mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-16 11:10:33 +08:00
Chore: download dist from GitLab if GitHub dist repo is down
This commit is contained in:
parent
affaa13890
commit
554afd0fd9
3
.github/workflows/main.yml
vendored
3
.github/workflows/main.yml
vendored
@ -74,8 +74,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir ./deploy-git
|
mkdir ./deploy-git
|
||||||
cd ./deploy-git
|
cd ./deploy-git
|
||||||
git init
|
|
||||||
git config --global init.defaultBranch master
|
git config --global init.defaultBranch master
|
||||||
|
git init
|
||||||
git config --global push.default matching
|
git config --global push.default matching
|
||||||
git config --global user.email "${GITLAB_EMAIL}"
|
git config --global user.email "${GITLAB_EMAIL}"
|
||||||
git config --global user.name "${GITLAB_USER}"
|
git config --global user.name "${GITLAB_USER}"
|
||||||
@ -95,6 +95,7 @@ jobs:
|
|||||||
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
|
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
|
||||||
- name: Upload Dist to GitHub
|
- name: Upload Dist to GitHub
|
||||||
uses: peaceiris/actions-gh-pages@v4
|
uses: peaceiris/actions-gh-pages@v4
|
||||||
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
personal_token: ${{ secrets.GIT_TOKEN }}
|
personal_token: ${{ secrets.GIT_TOKEN }}
|
||||||
user_name: ${{ secrets.GIT_USER }}
|
user_name: ${{ secrets.GIT_USER }}
|
||||||
|
|||||||
@ -13,6 +13,9 @@ import { Readable } from 'node:stream';
|
|||||||
const IS_READING_BUILD_OUTPUT = 1 << 2;
|
const IS_READING_BUILD_OUTPUT = 1 << 2;
|
||||||
const ALL_FILES_EXISTS = 1 << 3;
|
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) => {
|
export const downloadPreviousBuild = task(require.main === module, __filename)(async (span) => {
|
||||||
const buildOutputList: string[] = [];
|
const buildOutputList: string[] = [];
|
||||||
|
|
||||||
@ -49,11 +52,28 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
|||||||
|
|
||||||
const filesList = buildOutputList.map(f => path.join('ruleset.skk.moe-master', f));
|
const filesList = buildOutputList.map(f => path.join('ruleset.skk.moe-master', f));
|
||||||
|
|
||||||
return span
|
const tarGzUrl = await span.traceChildAsync('get tar.gz url', async () => {
|
||||||
.traceChild('download & extract previoud build')
|
const resp = await fetchWithRetry(GITHUB_CODELOAD_URL, {
|
||||||
.traceAsyncFn(async () => {
|
|
||||||
const resp = await fetchWithRetry('https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master', {
|
|
||||||
...defaultRequestInit,
|
...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: {
|
retry: {
|
||||||
retryOnNon2xx: false
|
retryOnNon2xx: false
|
||||||
}
|
}
|
||||||
@ -79,7 +99,7 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
|||||||
extract
|
extract
|
||||||
);
|
);
|
||||||
|
|
||||||
const pathPrefix = `ruleset.skk.moe-master${path.sep}`;
|
const pathPrefix = 'ruleset.skk.moe-master/';
|
||||||
|
|
||||||
for await (const entry of extract) {
|
for await (const entry of extract) {
|
||||||
if (entry.header.type !== 'file') {
|
if (entry.header.type !== 'file') {
|
||||||
|
|||||||
@ -124,7 +124,7 @@ function createFetchRetry($fetch: typeof fetch): FetchWithRetry {
|
|||||||
|
|
||||||
export const defaultRequestInit: RequestInit = {
|
export const defaultRequestInit: RequestInit = {
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'curl/8.9.0 (https://github.com/SukkaW/Surge)'
|
'User-Agent': 'curl/8.9.1 (https://github.com/SukkaW/Surge)'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user