mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
CI: download previous build using GitHub Actions
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import { isCI } from 'ci-info';
|
||||
import process from 'node:process';
|
||||
|
||||
export const ROOT_DIR = path.resolve(__dirname, '../..');
|
||||
|
||||
@@ -8,9 +7,7 @@ export const CACHE_DIR = path.resolve(ROOT_DIR, '.cache');
|
||||
|
||||
export const SOURCE_DIR = path.join(ROOT_DIR, 'Source');
|
||||
|
||||
export const PUBLIC_DIR = isCI
|
||||
? fs.mkdtempSync('/dev/shm/sukkaw-surge-public-')
|
||||
: path.resolve(ROOT_DIR, 'public');
|
||||
export const PUBLIC_DIR = process.env.PUBLIC_DIR || path.resolve(ROOT_DIR, 'public');
|
||||
|
||||
export const OUTPUT_SURGE_DIR = path.join(PUBLIC_DIR, 'List');
|
||||
export const OUTPUT_CLASH_DIR = path.resolve(PUBLIC_DIR, 'Clash');
|
||||
|
||||
@@ -10,6 +10,7 @@ import picocolors from 'picocolors';
|
||||
import { PUBLIC_DIR } from './constants/dir';
|
||||
import { requestWithLog } from './lib/fetch-retry';
|
||||
import { isDirectoryEmptySync } from './lib/misc';
|
||||
import { isCI } from 'ci-info';
|
||||
|
||||
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';
|
||||
@@ -20,6 +21,11 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
||||
return;
|
||||
}
|
||||
|
||||
// we uses actions/checkout to download the previous build now, so we should throw if the directory is empty
|
||||
if (isCI) {
|
||||
throw new Error('CI environment detected, but public directory is empty');
|
||||
}
|
||||
|
||||
const tarGzUrl = await span.traceChildAsync('get tar.gz url', async () => {
|
||||
const resp = await requestWithLog(GITHUB_CODELOAD_URL, { method: 'HEAD' });
|
||||
if (resp.statusCode !== 200) {
|
||||
|
||||
@@ -29,9 +29,7 @@ import { buildCloudMounterRules } from './build-cloudmounter-rules';
|
||||
import { createSpan, printTraceResult, whyIsNodeRunning } from './trace';
|
||||
import { buildDeprecateFiles } from './build-deprecate-files';
|
||||
import path from 'node:path';
|
||||
import { PUBLIC_DIR, ROOT_DIR } from './constants/dir';
|
||||
|
||||
import { setOutput } from '@actions/core';
|
||||
import { ROOT_DIR } from './constants/dir';
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('Uncaught exception:', error);
|
||||
@@ -108,10 +106,6 @@ const buildFinishedLock = path.join(ROOT_DIR, '.BUILD_FINISHED');
|
||||
// write a file to demonstrate that the build is finished
|
||||
fs.writeFileSync(buildFinishedLock, 'BUILD_FINISHED\n');
|
||||
|
||||
if (process.env.GITHUB_OUTPUT) {
|
||||
setOutput('public_dir', PUBLIC_DIR);
|
||||
}
|
||||
|
||||
// Finish the build to avoid leaking timer/fetch ref
|
||||
await whyIsNodeRunning();
|
||||
process.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user