66 pull_request :
77 branches : ["dev"]
88 release :
9- types :
10- - published # 当发布版本时触发
9+ types : [published]
1110
1211env :
1312 CARGO_TERM_COLOR : always
1716
1817jobs :
1918 test :
20- name : Test
19+ name : Run Tests
2120 runs-on : ubuntu-latest
2221 steps :
2322 - uses : actions/checkout@v4
@@ -29,43 +28,38 @@ jobs:
2928 toolchain : stable
3029 override : true
3130
32- - name : Cache Rust dependencies
31+ - name : Cache Dependencies
3332 uses : actions/cache@v3
3433 with :
3534 path : |
3635 ~/.cargo/registry
3736 ~/.cargo/git
3837 backend/target
3938 key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
40- restore-keys : ${{ runner.os }}-cargo-
4139
42- - name : Cache SQLx metadata
40+ - name : Cache SQLx Data
4341 uses : actions/cache@v3
4442 with :
4543 path : backend/.sqlx
4644 key : ${{ runner.os }}-sqlx-${{ hashFiles('**/*.rs', '**/migrations/**') }}
47- restore-keys : ${{ runner.os }}-sqlx-
4845
4946 - name : Install SQLx CLI
5047 run : cargo install sqlx-cli --no-default-features --features postgres
5148
52- - name : Prepare SQLx metadata
53- run : |
54- cd backend
55- cargo sqlx prepare -- --tests
49+ - name : Prepare SQLx
50+ run : cd backend && cargo sqlx prepare -- --tests
5651 env :
5752 DATABASE_URL : ${{ secrets.DATABASE_URL }}
5853 SQLX_OFFLINE : true
5954
60- - name : Run tests
55+ - name : Execute Tests
6156 run : cd backend && cargo test --verbose
6257
6358 build :
64- name : Build ${{ matrix.target.name }}
59+ name : Build ( ${{ matrix.target.name }})
6560 needs : test
6661 runs-on : ${{ matrix.target.os }}
6762 strategy :
68- fail-fast : false
6963 matrix :
7064 target :
7165 - name : Linux x86_64
@@ -87,117 +81,88 @@ jobs:
8781 steps :
8882 - uses : actions/checkout@v4
8983
90- - name : Install cross-compilation toolchain for ARM64
84+ - name : Setup ARM Toolchain
9185 if : matrix.target.target == 'aarch64-unknown-linux-gnu'
9286 run : |
9387 sudo apt-get update
9488 sudo apt-get install -y gcc-aarch64-linux-gnu
9589
96- - name : Setup Rust
90+ - name : Configure Rust
9791 uses : actions-rs/toolchain@v1
9892 with :
9993 profile : minimal
10094 toolchain : stable
10195 target : ${{ matrix.target.target }}
10296 override : true
10397
104- - name : Cache Rust dependencies
98+ - name : Cache Build
10599 uses : actions/cache@v3
106100 with :
107101 path : |
108102 ~/.cargo/registry
109103 ~/.cargo/git
110104 backend/target
111105 key : ${{ runner.os }}-${{ matrix.target.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
112- restore-keys : ${{ runner.os }}-${{ matrix.target.target }}-cargo-
113-
114- - name : Cache SQLx metadata
115- uses : actions/cache@v3
116- with :
117- path : backend/.sqlx
118- key : ${{ runner.os }}-sqlx-${{ hashFiles('**/*.rs', '**/migrations/**') }}
119- restore-keys : ${{ runner.os }}-sqlx-
120-
121- - name : Install SQLx CLI
122- run : cargo install sqlx-cli --no-default-features --features postgres
123-
124- - name : Prepare SQLx metadata
125- run : |
126- cd backend
127- cargo sqlx prepare -- --tests
128- env :
129- DATABASE_URL : ${{ secrets.DATABASE_URL }}
130- SQLX_OFFLINE : true
131106
132- - name : Build release binary
133- run : |
134- cd backend
135- cargo build --release --target ${{ matrix.target.target }}
107+ - name : Compile Release
108+ run : cd backend && cargo build --release --target ${{ matrix.target.target }}
136109
137- - name : Prepare binary
138- shell : bash
110+ - name : Package Artifact
139111 run : |
140- cd backend
141112 mkdir -p release
142- cp target/${{ matrix.target.target }}/release/${{ matrix.target.bin }} release/${{ matrix.target.asset_name }}
113+ cp backend/ target/${{ matrix.target.target }}/release/${{ matrix.target.bin }} release/${{ matrix.target.asset_name }}
143114
144- - name : Upload binary as artifact
115+ - name : Upload Artifact
145116 uses : actions/upload-artifact@v4
146117 with :
147118 name : ${{ matrix.target.asset_name }}
148- path : backend/release/${{ matrix.target.asset_name }}
149- if-no-files-found : error
119+ path : release/${{ matrix.target.asset_name }}
150120
151- update-release-notes :
152- permissions :
153- contents : write
154- runs-on : ubuntu-latest
155- steps :
156- - uses : actions/checkout@v4
157-
158- - name : Extract release notes
159- id : extract-release-notes
160- uses : ffurrer2/extract-release-notes@v2
161-
162- - uses : softprops/action-gh-release@v2
163- with :
164- body : |-
165- ${{ steps.extract-release-notes.outputs.release_notes }}
166- | File | SHA256 |
167- | ---- | ------ |
168-
169- upload-to-release :
170- needs :
171- - build
172- - update-release-notes
121+ release :
122+ name : Publish Release
123+ needs : build
173124 permissions :
174125 contents : write
175126 runs-on : ubuntu-latest
176- strategy :
177- matrix :
178- mode :
179- - debug
180- - release
181127 steps :
182128 - uses : actions/checkout@v4
183129
184- - uses : actions/download-artifact@v4
130+ - name : Download Artifacts
131+ uses : actions/download-artifact@v4
185132 with :
186- name : ${{ matrix.target.asset_name }}
187- path : artifact
133+ path : artifacts
188134
189- - run : |
190- zip -r ../${{ matrix.asset_name }} *
191- working-directory: artifact
192-
193- - id : calculate-sha256
135+ - name : Generate Version
136+ id : version
194137 run : |
195- echo sha256=$(sha256sum ${{ matrix.asset_name }} | awk '{print $1}') >> $GITHUB_OUTPUT
196-
197- - uses : softprops/action-gh-release@v2
138+ if [ "$GITHUB_EVENT_NAME" = "release" ]; then
139+ echo "version=$(jq -r .release.tag_name $GITHUB_EVENT_PATH)" >> $GITHUB_OUTPUT
140+ else
141+ echo "version=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
142+ fi
143+
144+ - name : Calculate Checksums
145+ id : checksums
146+ run : |
147+ echo "HASHES=| File | SHA256 |" >> $GITHUB_OUTPUT
148+ echo "HASHES+=| ---- | ------ |" >> $GITHUB_OUTPUT
149+ cd artifacts
150+ for file in *; do
151+ if [ -f "$file" ]; then
152+ sha=$(sha256sum "$file" | awk '{print $1}')
153+ echo "HASHES+=| $file | $sha |" >> $GITHUB_OUTPUT
154+ fi
155+ done
156+
157+ - name : Create Release
158+ uses : softprops/action-gh-release@v2
198159 with :
199- append_body : true
200- body : |-
201- | ${{ matrix.asset_name }} | ${{ steps.calculate-sha256.outputs.sha256 }} |
202- files : |
203- ${{ matrix.asset_name }}
160+ tag_name : ${{ steps.version.outputs.version }}
161+ name : ${{ steps.version.outputs.version }}
162+ body : |
163+ ${{ github.event.release.body }}
164+
165+ ## Checksums
166+ ${{ steps.checksums.outputs.HASHES }}
167+ files : artifacts/*
168+ if : ${{ github.event_name == 'release' }}
0 commit comments