Skip to content

Commit

Permalink
chore(ci): save build artifacts to qwik-build repository
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Mar 11, 2022
1 parent 4651e77 commit 7af93c5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Save artifacts
if: ${{ needs.changes.outputs.fullbuild == 'true' && github.event_name == 'push' }}
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
run: yarn qwik-save-artifacts

############ E2E TEST ############
test-e2e:
name: E2E Tests
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"bazel:lint": "npm run bazel:format -- --mode=check --lint=warn",
"bazel:lint-fix": "npm run bazel:format -- --mode=fix --lint=fix",
"link.dist": "cd dist-dev/@builder.io-qwik && npm link",
"qwik-save-artifacts": "node -r esbuild-register ./scripts/qwik-save-artifacts.ts",
"preinstall": "node scripts/tools/preinstall-script.js"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions scripts/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export async function generatePackageJson(config: BuildConfig) {
require: './testing/index.cjs',
},
'./qwikloader.js': './qwikloader.js',
'./qwikloader.debug.js': './qwikloader.debug.js',
'./package.json': './package.json',
},
files: Array.from(new Set(rootPkg.files)).sort((a, b) => {
Expand Down
65 changes: 65 additions & 0 deletions scripts/qwik-save-artifacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { execa } from 'execa';

const token = process.env.API_TOKEN_GITHUB;
const repo = `https://${token}:x-oauth-basic@github.com/BuilderIO/qwik-build.git`;
const srcRepoRef = 'https://github.com/BuilderIO/qwik/commit/';
const root = __dirname + '/..';
const qwik_build_artifacts = root + '/dist-dev/qwik-build';
const qwik_package = root + '/dist-dev/@builder.io-qwik';

(async () => {
await $('rm', '-rf', qwik_build_artifacts);
const SHA = await $('git', 'rev-parse', 'HEAD');
process.chdir(`${root}/dist-dev`);
await $('git', 'clone', repo);
const branch = await $('git', 'branch', '--show-current');
const msg = await $('git', 'log', '--oneline', '-1', '--no-decorate');
const userName = await $('git', 'log', '-1', "--pretty=format:'%an'");
const userEmail = await $('git', 'log', '-1', "--pretty=format:'%ae'");

process.chdir(`${qwik_build_artifacts}`);
try {
await $('git', 'checkout', branch);
} catch (e) {
await $('git', 'checkout', '-b', branch);
}
await $('rm', '-rf', ...(await expand(qwik_build_artifacts)));
await $('cp', '-r', ...(await expand(qwik_package)), qwik_build_artifacts);
process.chdir(`${qwik_build_artifacts}`);
await $('git', 'add', '--all');
await $(
'git',
'-c',
`user.name=${userName}`,
'-c',
`user.email=${userEmail}`,
'commit',
'--allow-empty',
'-m',
msg + '\n\n' + srcRepoRef + SHA
);
const dstSHA = await $('git', 'rev-parse', 'HEAD');
console.log('##############################################################');
console.log('##############################################################');
console.log(`### https://github.com/BuilderIO/qwik-build/commit/${dstSHA}`);
console.log('##############################################################');
console.log('##############################################################');
await $('git', 'push', repo, `HEAD:${branch}`);
await $('rm', '-rf', qwik_build_artifacts);
})();

async function $(cmd: string, ...args: string[]): Promise<string> {
console.log('EXEC:', cmd, ...args);
const { stdout } = await execa(cmd, args);
const output = String(stdout).trim();
console.log(' ', output);
return output;
}

async function expand(path: string): Promise<string[]> {
const { stdout } = await execa('ls', [path]);
const paths = String(stdout)
.split('\n')
.map((file) => path + '/' + file.trim());
return paths;
}

0 comments on commit 7af93c5

Please sign in to comment.