-
Notifications
You must be signed in to change notification settings - Fork 1.3k
136 lines (127 loc) · 4.8 KB
/
Copy pathmain.yml
File metadata and controls
136 lines (127 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: build
on:
workflow_dispatch:
push:
branches:
- master
paths:
- "backend/package.json"
pull_request:
branches:
- master
paths:
- "backend/package.json"
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: ".node-version"
- name: Install dependencies
run: |
corepack enable
cd backend && pnpm i --no-frozen-lockfile
- name: Sync latest mihomo version
run: |
MIHOMO_VERSION="$(curl -fsSL https://github.com/MetaCubeX/mihomo/releases/latest/download/version.txt | tr -d '\r\n')"
test -n "$MIHOMO_VERSION"
echo "Using mihomo version: $MIHOMO_VERSION"
cd backend
MIHOMO_VERSION="$MIHOMO_VERSION" node <<'NODE'
const fs = require('fs');
const files = ['src/utils/download.js', 'src/utils/flow.js'];
const version = process.env.MIHOMO_VERSION;
let replacements = 0;
for (const file of files) {
const source = fs.readFileSync(file, 'utf8');
const next = source.replace(/clash\.meta\/[^"']+/g, () => {
replacements += 1;
return `clash.meta/${version}`;
});
if (next !== source) {
fs.writeFileSync(file, next);
}
}
if (replacements === 0) {
throw new Error('No clash.meta version strings were updated.');
}
console.log(`Updated ${replacements} clash.meta version string(s).`);
NODE
- name: Test
run: |
cd backend
pnpm test
# - name: Build
# run: |
# cd backend
# pnpm run build
- name: Bundle
run: |
cd backend
pnpm bundle:esbuild
- id: tag
name: Generate release tag
run: |
cd backend
SUBSTORE_RELEASE="$(node --eval="process.stdout.write(require('./package.json').version)")"
echo "release_tag=${SUBSTORE_RELEASE}" >> "${GITHUB_OUTPUT}"
- name: Prepare release
run: |
cd backend
pnpm i -D conventional-changelog-cli
pnpm run changelog
- name: Release
uses: softprops/action-gh-release@v3
if: ${{ success() && github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: ./backend/CHANGELOG.md
tag_name: ${{ steps.tag.outputs.release_tag }}
# generate_release_notes: true
files: |
./backend/sub-store.min.js
./backend/dist/sub-store-0.min.js
./backend/dist/sub-store-1.min.js
./backend/dist/sub-store-parser.loon.min.js
./backend/dist/cron-sync-artifacts.min.js
./backend/dist/proxy-utils.esm.mjs
./backend/dist/sub-store.bundle.js
- name: Git push assets to "release" branch
if: ${{ success() && github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
auth_header="AUTHORIZATION: bearer ${GITHUB_TOKEN}"
repo_url="https://github.com/${GITHUB_REPOSITORY}.git"
release_dir="${RUNNER_TEMP}/release-dist"
rm -rf "${release_dir}"
if git -c http.https://github.com/.extraheader="${auth_header}" ls-remote --exit-code --heads "${repo_url}" release > /dev/null; then
git -c http.https://github.com/.extraheader="${auth_header}" clone --depth 1 --branch release "${repo_url}" "${release_dir}"
else
git init -b release "${release_dir}"
git -C "${release_dir}" remote add origin "${repo_url}"
fi
rsync -a --delete --exclude='.git' backend/dist/ "${release_dir}/"
cd "${release_dir}"
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No release asset changes to push."
exit 0
fi
git commit -m "release: ${{ steps.tag.outputs.release_tag }}"
git -c http.https://github.com/.extraheader="${auth_header}" push origin release
# - name: Sync to GitLab
# env:
# GITLAB_PIPELINE_TOKEN: ${{ secrets.GITLAB_PIPELINE_TOKEN }}
# run: |
# curl -X POST --fail -F token=$GITLAB_PIPELINE_TOKEN -F ref=master https://gitlab.com/api/v4/projects/48891296/trigger/pipeline