|
@@ -1,4 +1,5 @@
|
|
|
import path from 'node:path';
|
|
import path from 'node:path';
|
|
|
|
|
+import fs from 'node:fs';
|
|
|
import { pipeline } from 'node:stream/promises';
|
|
import { pipeline } from 'node:stream/promises';
|
|
|
import { task } from './trace';
|
|
import { task } from './trace';
|
|
|
import { defaultRequestInit, fetchWithRetry } from './lib/fetch-retry';
|
|
import { defaultRequestInit, fetchWithRetry } from './lib/fetch-retry';
|
|
@@ -6,11 +7,19 @@ import { extract as tarExtract } from 'tar-fs';
|
|
|
import type { Headers as TarEntryHeaders } from 'tar-fs';
|
|
import type { Headers as TarEntryHeaders } from 'tar-fs';
|
|
|
import zlib from 'node:zlib';
|
|
import zlib from 'node:zlib';
|
|
|
import { Readable } from 'node:stream';
|
|
import { Readable } from 'node:stream';
|
|
|
|
|
+import picocolors from 'picocolors';
|
|
|
|
|
|
|
|
const GITHUB_CODELOAD_URL = 'https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master';
|
|
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';
|
|
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) => {
|
|
export const downloadPreviousBuild = task(require.main === module, __filename)(async (span) => {
|
|
|
|
|
+ const publicDir = path.resolve(__dirname, '..', 'public');
|
|
|
|
|
+
|
|
|
|
|
+ if (fs.existsSync(publicDir)) {
|
|
|
|
|
+ console.log(picocolors.blue('Public directory exists, skip downloading previous build'));
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const tarGzUrl = await span.traceChildAsync('get tar.gz url', async () => {
|
|
const tarGzUrl = await span.traceChildAsync('get tar.gz url', async () => {
|
|
|
const resp = await fetchWithRetry(GITHUB_CODELOAD_URL, {
|
|
const resp = await fetchWithRetry(GITHUB_CODELOAD_URL, {
|
|
|
...defaultRequestInit,
|
|
...defaultRequestInit,
|
|
@@ -27,8 +36,6 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
|
|
return GITHUB_CODELOAD_URL;
|
|
return GITHUB_CODELOAD_URL;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const publicDir = path.resolve(__dirname, '..', 'public');
|
|
|
|
|
-
|
|
|
|
|
return span.traceChildAsync('download & extract previoud build', async () => {
|
|
return span.traceChildAsync('download & extract previoud build', async () => {
|
|
|
const resp = await fetchWithRetry(tarGzUrl, {
|
|
const resp = await fetchWithRetry(tarGzUrl, {
|
|
|
headers: {
|
|
headers: {
|