forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqwik-save-artifacts.ts
71 lines (66 loc) · 2.56 KB
/
qwik-save-artifacts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { execa } from 'execa';
import { mkdir } from 'fs/promises';
import { fileURLToPath } from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const token = process.env.API_TOKEN_GITHUB;
const repo = `https://${token}:[email protected]/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 + '/packages/qwik/dist';
(async () => {
await $('rm', '-rf', qwik_build_artifacts);
const SHA = await $('git', 'rev-parse', 'HEAD');
await mkdir(`${root}/dist-dev`, {
recursive: true,
});
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;
}