|
|
@@ -13,6 +13,9 @@ import { Readable } from 'node:stream';
|
|
|
const IS_READING_BUILD_OUTPUT = 1 << 2;
|
|
|
const ALL_FILES_EXISTS = 1 << 3;
|
|
|
|
|
|
+const GITHUB_CODELOAD_URL = 'https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master';
|
|
|
+const GITLAB_CODELOAD_URL = 'https://gitlab.com/SukkaW/ruleset.skk.moe/-/archive/master/ruleset.skk.moe-master.tar.gz';
|
|
|
+
|
|
|
export const downloadPreviousBuild = task(require.main === module, __filename)(async (span) => {
|
|
|
const buildOutputList: string[] = [];
|
|
|
|
|
|
@@ -49,54 +52,71 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
|
|
|
|
|
const filesList = buildOutputList.map(f => path.join('ruleset.skk.moe-master', f));
|
|
|
|
|
|
- return span
|
|
|
- .traceChild('download & extract previoud build')
|
|
|
- .traceAsyncFn(async () => {
|
|
|
- const resp = await fetchWithRetry('https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master', {
|
|
|
- ...defaultRequestInit,
|
|
|
- retry: {
|
|
|
- retryOnNon2xx: false
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if (resp.status !== 200) {
|
|
|
- console.warn('Download previous build failed! Status:', resp.status);
|
|
|
- if (resp.status === 404) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ const tarGzUrl = await span.traceChildAsync('get tar.gz url', async () => {
|
|
|
+ const resp = await fetchWithRetry(GITHUB_CODELOAD_URL, {
|
|
|
+ ...defaultRequestInit,
|
|
|
+ method: 'HEAD',
|
|
|
+ retry: {
|
|
|
+ retryOnNon2xx: false
|
|
|
}
|
|
|
+ });
|
|
|
+ if (resp.status !== 200) {
|
|
|
+ console.warn('Download previous build from GitHub failed! Status:', resp.status);
|
|
|
+ console.warn('Switch to GitLab');
|
|
|
+ return GITLAB_CODELOAD_URL;
|
|
|
+ }
|
|
|
+ return GITHUB_CODELOAD_URL;
|
|
|
+ });
|
|
|
+
|
|
|
+ return span.traceChildAsync('download & extract previoud build', async () => {
|
|
|
+ const resp = await fetchWithRetry(tarGzUrl, {
|
|
|
+ headers: {
|
|
|
+ 'User-Agent': 'curl/8.9.1',
|
|
|
+ Accept: 'application/octet-stream'
|
|
|
+ },
|
|
|
+ retry: {
|
|
|
+ retryOnNon2xx: false
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- if (!resp.body) {
|
|
|
- throw new Error('Download previous build failed! No body found');
|
|
|
+ if (resp.status !== 200) {
|
|
|
+ console.warn('Download previous build failed! Status:', resp.status);
|
|
|
+ if (resp.status === 404) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- const gunzip = zlib.createGunzip();
|
|
|
- const extract = tarStream.extract();
|
|
|
+ if (!resp.body) {
|
|
|
+ throw new Error('Download previous build failed! No body found');
|
|
|
+ }
|
|
|
|
|
|
- pipeline(
|
|
|
- Readable.fromWeb(resp.body),
|
|
|
- gunzip,
|
|
|
- extract
|
|
|
- );
|
|
|
+ const gunzip = zlib.createGunzip();
|
|
|
+ const extract = tarStream.extract();
|
|
|
|
|
|
- const pathPrefix = `ruleset.skk.moe-master${path.sep}`;
|
|
|
+ pipeline(
|
|
|
+ Readable.fromWeb(resp.body),
|
|
|
+ gunzip,
|
|
|
+ extract
|
|
|
+ );
|
|
|
|
|
|
- for await (const entry of extract) {
|
|
|
- if (entry.header.type !== 'file') {
|
|
|
- entry.resume(); // Drain the entry
|
|
|
- continue;
|
|
|
- }
|
|
|
- // filter entry
|
|
|
- if (!filesList.some(f => entry.header.name.startsWith(f))) {
|
|
|
- entry.resume(); // Drain the entry
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- const relativeEntryPath = entry.header.name.replace(pathPrefix, '');
|
|
|
- const targetPath = path.join(__dirname, '..', relativeEntryPath);
|
|
|
+ const pathPrefix = 'ruleset.skk.moe-master/';
|
|
|
|
|
|
- await mkdir(path.dirname(targetPath), { recursive: true });
|
|
|
- await pipeline(entry, createWriteStream(targetPath));
|
|
|
+ for await (const entry of extract) {
|
|
|
+ if (entry.header.type !== 'file') {
|
|
|
+ entry.resume(); // Drain the entry
|
|
|
+ continue;
|
|
|
}
|
|
|
- });
|
|
|
+ // filter entry
|
|
|
+ if (!filesList.some(f => entry.header.name.startsWith(f))) {
|
|
|
+ entry.resume(); // Drain the entry
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ const relativeEntryPath = entry.header.name.replace(pathPrefix, '');
|
|
|
+ const targetPath = path.join(__dirname, '..', relativeEntryPath);
|
|
|
+
|
|
|
+ await mkdir(path.dirname(targetPath), { recursive: true });
|
|
|
+ await pipeline(entry, createWriteStream(targetPath));
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|