Skip to content

Commit 8fbe4dc

Browse files
committed
ci: 使用 job outputs 串联 release 和 build,无需 PAT
1 parent dd4a5d9 commit 8fbe4dc

1 file changed

Lines changed: 76 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ jobs:
2020
permissions:
2121
contents: write
2222
pull-requests: write
23+
outputs:
24+
tag: ${{ steps.push-tag.outputs.tag }}
2325
steps:
2426
- uses: actions/checkout@v4
2527
with:
2628
fetch-depth: 0
27-
token: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
2829

2930
- uses: pnpm/action-setup@v4
3031

@@ -42,21 +43,90 @@ jobs:
4243
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4344

4445
- name: Push tag if version changed
46+
id: push-tag
4547
if: steps.changesets.outputs.hasChangesets == 'false'
4648
shell: bash
4749
run: |
4850
VERSION=$(node -p "require('./package.json').version")
49-
if ! git ls-remote --tags origin | grep -q "refs/tags/v$VERSION$"; then
51+
TAG="v$VERSION"
52+
if ! git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then
5053
git config user.name "github-actions[bot]"
5154
git config user.email "github-actions[bot]@users.noreply.github.com"
52-
git tag "v$VERSION"
53-
git push origin "v$VERSION"
54-
echo "Pushed tag v$VERSION"
55+
git tag "$TAG"
56+
git push origin "$TAG"
57+
echo "tag=$TAG" >> $GITHUB_OUTPUT
58+
echo "Pushed tag $TAG"
5559
else
56-
echo "Tag v$VERSION already exists"
60+
echo "Tag $TAG already exists"
5761
fi
5862
5963
build:
64+
needs: [release]
65+
if: needs.release.outputs.tag != ''
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
include:
70+
- os: ubuntu-24.04
71+
target: x86_64-unknown-linux-gnu
72+
- os: macos-latest
73+
target: x86_64-apple-darwin
74+
- os: macos-latest
75+
target: aarch64-apple-darwin
76+
- os: windows-latest
77+
target: x86_64-pc-windows-msvc
78+
runs-on: ${{ matrix.os }}
79+
permissions:
80+
contents: write
81+
steps:
82+
- uses: actions/checkout@v4
83+
with:
84+
ref: ${{ needs.release.outputs.tag }}
85+
86+
- name: Install Linux dependencies
87+
if: runner.os == 'Linux'
88+
run: |
89+
sudo apt-get update
90+
sudo apt-get install -y \
91+
libwebkit2gtk-4.1-dev \
92+
libappindicator3-dev \
93+
librsvg2-dev \
94+
patchelf \
95+
libpipewire-0.3-dev \
96+
libgbm-dev \
97+
libxcb1-dev \
98+
libegl-dev
99+
100+
- uses: pnpm/action-setup@v4
101+
102+
- uses: actions/setup-node@v4
103+
with:
104+
node-version: 20
105+
cache: pnpm
106+
107+
- uses: dtolnay/rust-toolchain@stable
108+
with:
109+
targets: ${{ matrix.target }}
110+
111+
- uses: Swatinem/rust-cache@v2
112+
with:
113+
workspaces: src-tauri
114+
115+
- run: pnpm install
116+
117+
- uses: tauri-apps/tauri-action@v0
118+
env:
119+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120+
with:
121+
tagName: ${{ needs.release.outputs.tag }}
122+
releaseName: ${{ needs.release.outputs.tag }}
123+
releaseBody: "See [CHANGELOG](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details."
124+
releaseDraft: false
125+
prerelease: false
126+
args: --target ${{ matrix.target }}
127+
128+
# 直接由 tag push 或 workflow_dispatch 触发的构建
129+
build-tag:
60130
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
61131
strategy:
62132
fail-fast: false

0 commit comments

Comments
 (0)