Skip to content

Commit 861008f

Browse files
committed
feat: 修改构建产物,优化 Actions 脚本
1 parent 215d473 commit 861008f

6 files changed

Lines changed: 324 additions & 305 deletions

File tree

.github/workflows/main.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
name: build
2+
23
on:
4+
push:
5+
tags:
6+
- 'v*'
37
schedule:
48
- cron: "0 16 * * *"
59
workflow_dispatch:
610

711
jobs:
812
build:
913
runs-on: ubuntu-latest
14+
1015
steps:
1116
- name: Checkout
1217
uses: actions/checkout@v7
1318
with:
1419
ref: "main"
1520
submodules: recursive
1621

17-
- uses: pnpm/action-setup@v6
18-
name: Install pnpm
22+
- name: Install pnpm
23+
uses: pnpm/action-setup@v6
1924
with:
2025
version: 10
2126
cache: true
2227

23-
- name: Set up Node.js 16-nightly, latest, node
28+
- name: Set up Node.js
2429
uses: actions/setup-node@v6
2530
with:
2631
node-version: 'latest'
@@ -48,7 +53,7 @@ jobs:
4853
rm -f submodules_before.txt submodules_after.txt
4954
5055
- name: Update package version if submodules changed
51-
if: steps.check_submodules.outputs.has_updates == 'true'
56+
if: steps.check_submodules.outputs.has_updates == 'true' && github.event_name != 'push'
5257
run: |
5358
pnpm version patch --no-git-tag-version
5459
@@ -61,43 +66,52 @@ jobs:
6166
git push origin main
6267
6368
- name: Install dependencies
64-
if: steps.check_submodules.outputs.has_updates == 'true'
69+
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
6570
run: |
6671
pnpm i --no-frozen-lockfile
6772
cd src/sub/backend
6873
pnpm i --no-frozen-lockfile
6974
7075
- name: Bundle
71-
if: steps.check_submodules.outputs.has_updates == 'true'
76+
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
7277
run: |
7378
pnpm build
7479
75-
- id: tag
76-
name: Generate release tag
77-
if: steps.check_submodules.outputs.has_updates == 'true'
80+
- name: Generate release tag
81+
id: tag
82+
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
7883
run: |
79-
SUBSTORE_RELEASE=`node --eval="process.stdout.write(require('./package.json').version)"`
80-
echo "release_tag=$SUBSTORE_RELEASE" >> $GITHUB_OUTPUT
84+
if [ "${{ github.event_name }}" == "push" ]; then
85+
# 从推送的 tag 获取版本号
86+
TAG_NAME="${{ github.ref_name }}"
87+
# 移除 v 前缀(如果存在)
88+
VERSION="${TAG_NAME#v}"
89+
echo "release_tag=$VERSION" >> $GITHUB_OUTPUT
90+
else
91+
# 从 package.json 获取版本号
92+
SUBSTORE_RELEASE=`node --eval="process.stdout.write(require('./package.json').version)"`
93+
echo "release_tag=$SUBSTORE_RELEASE" >> $GITHUB_OUTPUT
94+
fi
8195
8296
- name: Prepare release
83-
if: steps.check_submodules.outputs.has_updates == 'true'
97+
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
8498
run: |
8599
pnpm i -D conventional-changelog-cli
86100
npx conventional-changelog -p cli -i CHANGELOG.md -s
87101
88102
- name: Release
89103
uses: softprops/action-gh-release@v1
90-
if: steps.check_submodules.outputs.has_updates == 'true'
104+
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
91105
env:
92106
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93107
with:
94108
body_path: ./CHANGELOG.md
95-
tag_name: ${{ steps.tag.outputs.release_tag }}
109+
tag_name: ${{ github.event_name == 'push' && github.ref_name || steps.tag.outputs.release_tag }}
96110
files: |
97111
./dist/_worker.js
98112
99113
- name: Git push assets to "release" branch
100-
if: steps.check_submodules.outputs.has_updates == 'true'
114+
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
101115
run: |
102116
cd dist || exit 1
103117
git init

esbuild.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
const fs = require('fs');
32
const path = require('path');
43
const { build } = require('esbuild');
54

65
const objectHasOwnPolyfill = require.resolve('core-js/actual/object/has-own');
6+
77
!(async () => {
88
const pkg = JSON.parse(
99
await fs.promises.readFile(
@@ -15,7 +15,7 @@ const objectHasOwnPolyfill = require.resolve('core-js/actual/object/has-own');
1515
const mainVersion = JSON.parse(
1616
fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'),
1717
).version.trim();
18-
const dist = 'dist/_workers.js'
18+
const dist = 'dist/_worker.js'
1919
const artifacts = [
2020
{ src: 'index.js', dest: dist },
2121
];
@@ -34,6 +34,7 @@ const objectHasOwnPolyfill = require.resolve('core-js/actual/object/has-own');
3434
__VERSION__: `"${version}"`
3535
}
3636
});
37+
3738
fs.writeFileSync(
3839
path.join(__dirname, dist),
3940
`// SUB_STORE_NODE_VERSION: ${mainVersion}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store-node",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"private": true,
55
"license": "GPL-3.0",
66
"scripts": {

0 commit comments

Comments
 (0)