CI: run in tmpfs

This commit is contained in:
SukkaW 2025-01-18 00:20:23 +08:00
parent 273b941723
commit 7683775dee
7 changed files with 84 additions and 6 deletions

View File

@ -56,15 +56,16 @@ jobs:
${{ runner.os }}-v3-
- run: pnpm install
- run: pnpm run build
id: build
- name: Pre-deploy check
# If the public directory doesn't exist, the build should fail.
# If the public directory is empty, the build should fail.
run: |
if [ ! -d public ]; then
if [ ! -d ${{ steps.build.outputs.public_dir }} ]; then
echo "public directory not found"
exit 1
fi
if [ ! "$(ls -A public)" ]; then
if [ ! "$(ls -A ${{ steps.build.outputs.public_dir }})" ]; then
echo "public directory is empty"
exit 1
fi
@ -72,10 +73,11 @@ jobs:
echo ".BUILD_FINISHED not found"
exit 1
fi
echo "public directory is ready: ${{ steps.build.outputs.public_dir }}"
- uses: actions/upload-artifact@v4
with:
name: build-artifact-${{ github. ref_name }}
path: public
path: ${{ steps.build.outputs.public_dir }}
if-no-files-found: error
retention-days: 1
compression-level: 4

View File

@ -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');

View File

@ -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;
}

View File

@ -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);

View File

@ -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();
}
}

View File

@ -20,6 +20,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.11.1",
"@ghostery/adblocker": "^2.3.1",
"@henrygd/queue": "^1.0.7",
"async-retry": "^1.3.3",

51
pnpm-lock.yaml generated
View File

@ -19,6 +19,9 @@ importers:
.:
dependencies:
'@actions/core':
specifier: ^1.11.1
version: 1.11.1
'@ghostery/adblocker':
specifier: ^2.3.1
version: 2.3.1
@ -161,6 +164,18 @@ importers:
packages:
'@actions/core@1.11.1':
resolution: {integrity: sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==}
'@actions/exec@1.1.1':
resolution: {integrity: sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==}
'@actions/http-client@2.2.3':
resolution: {integrity: sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==}
'@actions/io@1.1.3':
resolution: {integrity: sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==}
'@antfu/utils@0.7.10':
resolution: {integrity: sha512-+562v9k4aI80m1+VuMHehNJWLOFjBnXn3tdOitzD0il5b7smkSBal4+a3oKiQTbrwMmN/TBUMDvbdoWDehgOww==}
@ -234,6 +249,10 @@ packages:
resolution: {integrity: sha512-lB05FkqEdUg2AA0xEbUz0SnkXT1LcCTa438W4IWTUh4hdOnVbQyOJ81OrDXsJk/LSiJHubgGEFoR5EHq1NsH1A==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@fastify/busboy@2.1.1':
resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==}
engines: {node: '>=14'}
'@ghostery/adblocker-content@2.3.1':
resolution: {integrity: sha512-8ZTY1sEE218b0EMk3Q9fv/cWwUxunSCyBOaKuviEmJY5EyvPa1VbGPuTq/Qdvo1kduD8nLEzCwgWhcT3F3TT0Q==}
@ -1726,6 +1745,10 @@ packages:
tunnel-agent@0.6.0:
resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==}
tunnel@0.0.6:
resolution: {integrity: sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==}
engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'}
type-check@0.4.0:
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
engines: {node: '>= 0.8.0'}
@ -1750,6 +1773,10 @@ packages:
undici-types@6.20.0:
resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==}
undici@5.28.5:
resolution: {integrity: sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==}
engines: {node: '>=14.0'}
undici@7.2.1:
resolution: {integrity: sha512-U2k0XHLJfaciARRxDcqTk2AZQsGXerHzdvfCZcy1hNhSf5KCAF4jIQQxL+apQviOekhRFPqED6Of5/+LcUSLzQ==}
engines: {node: '>=20.18.1'}
@ -1843,6 +1870,22 @@ packages:
snapshots:
'@actions/core@1.11.1':
dependencies:
'@actions/exec': 1.1.1
'@actions/http-client': 2.2.3
'@actions/exec@1.1.1':
dependencies:
'@actions/io': 1.1.3
'@actions/http-client@2.2.3':
dependencies:
tunnel: 0.0.6
undici: 5.28.5(patch_hash=eyidnukwfhrd7exzoydz2h5cfq)
'@actions/io@1.1.3': {}
'@antfu/utils@0.7.10': {}
'@babel/code-frame@7.26.2':
@ -1942,6 +1985,8 @@ snapshots:
'@eslint/core': 0.10.0
levn: 0.4.1
'@fastify/busboy@2.1.1': {}
'@ghostery/adblocker-content@2.3.1':
dependencies:
'@ghostery/adblocker-extended-selectors': 2.3.1
@ -3536,6 +3581,8 @@ snapshots:
dependencies:
safe-buffer: 5.2.1
tunnel@0.0.6: {}
type-check@0.4.0:
dependencies:
prelude-ls: 1.2.1
@ -3559,6 +3606,10 @@ snapshots:
undici-types@6.20.0: {}
undici@5.28.5(patch_hash=eyidnukwfhrd7exzoydz2h5cfq):
dependencies:
'@fastify/busboy': 2.1.1
undici@7.2.1(patch_hash=eyidnukwfhrd7exzoydz2h5cfq): {}
unique-filename@4.0.0: