Skip to content

Commit f52b5f9

Browse files
committed
ci: DRY - 合并 build 和 build-tag job
1 parent 6ccafdf commit f52b5f9

1 file changed

Lines changed: 13 additions & 80 deletions

File tree

.github/workflows/release.yml

Lines changed: 13 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Release
33
on:
44
push:
55
branches: [main]
6-
tags: ['v*']
76
workflow_dispatch:
87
inputs:
98
tag:
@@ -15,7 +14,7 @@ env:
1514

1615
jobs:
1716
release:
18-
if: github.ref == 'refs/heads/main'
17+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
1918
runs-on: ubuntu-latest
2019
permissions:
2120
contents: write
@@ -62,7 +61,7 @@ jobs:
6261
6362
build:
6463
needs: [release]
65-
if: needs.release.outputs.tag != ''
64+
if: always() && (needs.release.outputs.tag != '' || github.event_name == 'workflow_dispatch')
6665
strategy:
6766
fail-fast: false
6867
matrix:
@@ -79,75 +78,19 @@ jobs:
7978
permissions:
8079
contents: write
8180
steps:
82-
- uses: actions/checkout@v4
83-
with:
84-
ref: ${{ needs.release.outputs.tag }}
85-
submodules: recursive
86-
87-
- name: Install Linux dependencies
88-
if: runner.os == 'Linux'
81+
- name: Determine tag
82+
id: get-tag
83+
shell: bash
8984
run: |
90-
sudo apt-get update
91-
sudo apt-get install -y \
92-
libwebkit2gtk-4.1-dev \
93-
libappindicator3-dev \
94-
librsvg2-dev \
95-
patchelf \
96-
libpipewire-0.3-dev \
97-
libgbm-dev \
98-
libxcb1-dev \
99-
libegl-dev
100-
101-
- uses: pnpm/action-setup@v4
102-
103-
- uses: actions/setup-node@v4
104-
with:
105-
node-version: 20
106-
cache: pnpm
107-
108-
- uses: dtolnay/rust-toolchain@stable
109-
with:
110-
targets: ${{ matrix.target }}
111-
112-
- uses: Swatinem/rust-cache@v2
113-
with:
114-
workspaces: src-tauri
115-
116-
- run: pnpm install
117-
118-
- uses: tauri-apps/tauri-action@v0
119-
env:
120-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121-
with:
122-
tagName: ${{ needs.release.outputs.tag }}
123-
releaseName: ${{ needs.release.outputs.tag }}
124-
releaseBody: "See [CHANGELOG](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details."
125-
releaseDraft: false
126-
prerelease: false
127-
args: --target ${{ matrix.target }}
85+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
86+
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
87+
else
88+
echo "tag=${{ needs.release.outputs.tag }}" >> $GITHUB_OUTPUT
89+
fi
12890
129-
# 直接由 tag push 或 workflow_dispatch 触发的构建
130-
build-tag:
131-
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
132-
strategy:
133-
fail-fast: false
134-
matrix:
135-
include:
136-
- os: ubuntu-24.04
137-
target: x86_64-unknown-linux-gnu
138-
- os: macos-latest
139-
target: x86_64-apple-darwin
140-
- os: macos-latest
141-
target: aarch64-apple-darwin
142-
- os: windows-latest
143-
target: x86_64-pc-windows-msvc
144-
runs-on: ${{ matrix.os }}
145-
permissions:
146-
contents: write
147-
steps:
14891
- uses: actions/checkout@v4
14992
with:
150-
ref: ${{ github.event.inputs.tag || github.ref }}
93+
ref: ${{ steps.get-tag.outputs.tag }}
15194
submodules: recursive
15295

15396
- name: Install Linux dependencies
@@ -181,22 +124,12 @@ jobs:
181124

182125
- run: pnpm install
183126

184-
- name: Get tag name
185-
id: tag
186-
shell: bash
187-
run: |
188-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
189-
echo "name=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
190-
else
191-
echo "name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
192-
fi
193-
194127
- uses: tauri-apps/tauri-action@v0
195128
env:
196129
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
197130
with:
198-
tagName: ${{ steps.tag.outputs.name }}
199-
releaseName: ${{ steps.tag.outputs.name }}
131+
tagName: ${{ steps.get-tag.outputs.tag }}
132+
releaseName: ${{ steps.get-tag.outputs.tag }}
200133
releaseBody: "See [CHANGELOG](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details."
201134
releaseDraft: false
202135
prerelease: false

0 commit comments

Comments
 (0)