forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqwik-save-artifacts.ts
More file actions
93 lines (86 loc) · 3.07 KB
/
qwik-save-artifacts.ts
File metadata and controls
93 lines (86 loc) · 3.07 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { execa } from 'execa';
import { existsSync } from 'node:fs';
import { mkdir } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const token = process.env.API_TOKEN_GITHUB;
const root = __dirname + '/..';
const srcRepoRef = 'https://github.com/BuilderIO/qwik/commit/';
(async () => {
const finishQwik = await prepare({
buildRepo: 'qwik-build',
artifactsDir: root + '/packages/qwik/dist',
});
const finishQwikCity = await prepare({
buildRepo: 'qwik-city-build',
artifactsDir: root + '/packages/qwik-city/lib',
});
await finishQwik();
await finishQwikCity();
})();
async function prepare({ buildRepo, artifactsDir }: { buildRepo: string; artifactsDir: string }) {
if (!existsSync(artifactsDir)) {
// if no artifacts, then nothing to do.
return () => null;
}
const buildRepoDir = root + '/dist-dev/' + buildRepo;
const repo = token
? `https://${token}:x-oauth-basic@github.com/BuilderIO/${buildRepo}.git`
: `git@github.com:BuilderIO/${buildRepo}.git`;
await $('rm', '-rf', buildRepoDir);
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(`${buildRepoDir}`);
try {
await $('git', 'checkout', branch);
} catch (e) {
await $('git', 'checkout', '-b', branch);
}
await $('rm', '-rf', ...(await expand(buildRepoDir)));
await $('cp', '-r', ...(await expand(artifactsDir)), buildRepoDir);
process.chdir(`${buildRepoDir}`);
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(`### ${srcRepoRef}/${dstSHA}`);
console.log('##############################################################');
console.log('##############################################################');
return async () => {
await $('git', 'push', repo, `HEAD:${branch}`);
await $('rm', '-rf', buildRepoDir);
};
}
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;
}