Skip to content

Commit 0159063

Browse files
committed
chore: 增加自动发布 release 的 workflows
- 在 github action 手动触发时执行 - 输入并校验版本号 - 执行 pnpm version 更新版本号 - 执行 pnpm build:single 构建单文件 - 将构建产物重命名 - 提交版本号变更,创建release
1 parent 33c2baf commit 0159063

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Release single-file build
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Release version, for example 1.2.3 or v1.2.3'
8+
required: true
9+
type: string
10+
prerelease:
11+
description: 'Mark this GitHub Release as a prerelease'
12+
required: false
13+
default: false
14+
type: boolean
15+
16+
permissions:
17+
contents: write
18+
19+
concurrency:
20+
group: release-${{ github.ref }}
21+
cancel-in-progress: false
22+
23+
jobs:
24+
release:
25+
if: github.ref_type == 'branch'
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Install pnpm
35+
uses: pnpm/action-setup@v4
36+
37+
- name: Set up Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
cache: 'pnpm'
41+
42+
- name: Normalize and validate version
43+
id: version
44+
env:
45+
RAW_VERSION: ${{ inputs.version }}
46+
shell: bash
47+
run: |
48+
raw="$RAW_VERSION"
49+
version="${raw#v}"
50+
51+
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
52+
echo "::error::Version must be valid semver, for example 1.2.3 or v1.2.3"
53+
exit 1
54+
fi
55+
56+
current_version="$(node -p "JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version")"
57+
if [[ "$version" == "$current_version" ]]; then
58+
echo "::error::package.json is already at version $version"
59+
exit 1
60+
fi
61+
62+
echo "version=$version" >> "$GITHUB_OUTPUT"
63+
echo "tag=v$version" >> "$GITHUB_OUTPUT"
64+
echo "asset=freecell-log-studio-v$version.html" >> "$GITHUB_OUTPUT"
65+
66+
- name: Stop if tag already exists
67+
shell: bash
68+
run: |
69+
if git rev-parse -q --verify "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null; then
70+
echo "::error::Tag ${{ steps.version.outputs.tag }} already exists"
71+
exit 1
72+
fi
73+
74+
- name: Install dependencies
75+
run: pnpm install --frozen-lockfile
76+
77+
- name: Update package version
78+
run: pnpm version "${{ steps.version.outputs.version }}" --no-git-tag-version
79+
80+
- name: Build single-file artifact
81+
run: pnpm build:single
82+
83+
- name: Rename artifact
84+
shell: bash
85+
run: |
86+
test -f dist/index.html
87+
mkdir -p release
88+
cp dist/index.html "release/${{ steps.version.outputs.asset }}"
89+
90+
- name: Commit version bump and create tag
91+
shell: bash
92+
run: |
93+
git config user.name "github-actions[bot]"
94+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
95+
96+
git add package.json pnpm-lock.yaml
97+
git commit -m "chore: release ${{ steps.version.outputs.tag }}"
98+
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
99+
git push origin "HEAD:${{ github.ref_name }}"
100+
git push origin "${{ steps.version.outputs.tag }}"
101+
102+
- name: Create GitHub Release
103+
env:
104+
GH_TOKEN: ${{ github.token }}
105+
IS_PRERELEASE: ${{ inputs.prerelease }}
106+
shell: bash
107+
run: |
108+
prerelease_flag=""
109+
if [[ "$IS_PRERELEASE" == "true" ]]; then
110+
prerelease_flag="--prerelease"
111+
fi
112+
113+
gh release create "${{ steps.version.outputs.tag }}" \
114+
"release/${{ steps.version.outputs.asset }}" \
115+
--title "Freecell Log Studio ${{ steps.version.outputs.tag }}" \
116+
--notes "Single-file HTML build for ${{ steps.version.outputs.tag }}." \
117+
$prerelease_flag

0 commit comments

Comments
 (0)