mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
CI: run in tmpfs
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
import { isCI } from 'ci-info';
|
||||
|
||||
export const ROOT_DIR = path.resolve(__dirname, '../..');
|
||||
|
||||
@@ -6,7 +9,10 @@ export const CACHE_DIR = path.resolve(ROOT_DIR, '.cache');
|
||||
|
||||
export const SOURCE_DIR = path.join(ROOT_DIR, 'Source');
|
||||
|
||||
export const PUBLIC_DIR = path.resolve(ROOT_DIR, 'public');
|
||||
export const PUBLIC_DIR = isCI
|
||||
? fs.mkdtempSync(path.join(os.tmpdir(), 'sukkaw-surge-public-'))
|
||||
: 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');
|
||||
export const OUTPUT_SINGBOX_DIR = path.resolve(PUBLIC_DIR, 'sing-box');
|
||||
|
||||
@@ -9,12 +9,13 @@ import undici from 'undici';
|
||||
import picocolors from 'picocolors';
|
||||
import { PUBLIC_DIR } from './constants/dir';
|
||||
import { requestWithLog } from './lib/fetch-retry';
|
||||
import { isDirectoryEmptySync } from './lib/misc';
|
||||
|
||||
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) => {
|
||||
if (fs.existsSync(PUBLIC_DIR)) {
|
||||
if (fs.existsSync(PUBLIC_DIR) && !isDirectoryEmptySync(PUBLIC_DIR)) {
|
||||
console.log(picocolors.blue('Public directory exists, skip downloading previous build'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ import { buildCloudMounterRules } from './build-cloudmounter-rules';
|
||||
import { createSpan, printTraceResult, whyIsNodeRunning } from './trace';
|
||||
import { buildDeprecateFiles } from './build-deprecate-files';
|
||||
import path from 'node:path';
|
||||
import { ROOT_DIR } from './constants/dir';
|
||||
import { PUBLIC_DIR, ROOT_DIR } from './constants/dir';
|
||||
|
||||
import { setOutput } from '@actions/core';
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('Uncaught exception:', error);
|
||||
@@ -106,6 +108,10 @@ 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);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { dirname } from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import type { PathLike } from 'node:fs';
|
||||
import fsp from 'node:fs/promises';
|
||||
|
||||
export function fastStringCompare(a: string, b: string) {
|
||||
@@ -79,3 +80,13 @@ export function withBannerArray(title: string, description: string[] | readonly
|
||||
'################## EOF ##################'
|
||||
];
|
||||
};
|
||||
|
||||
export function isDirectoryEmptySync(path: PathLike) {
|
||||
const directoryHandle = fs.opendirSync(path);
|
||||
|
||||
try {
|
||||
return directoryHandle.readSync() === null;
|
||||
} finally {
|
||||
directoryHandle.closeSync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user