Skip to content

Commit 2ed1884

Browse files
committed
ci: add release workflow and update build workflow
- add new GitHub Actions workflow for automated crate publishing to crates.io on version tags - include steps for version verification, testing, packaging, and GitHub release creation - update rust workflow copyright to fix typo and bump checkout action version for compatibility - ensure release process supports dry-run mode for testing without actual publishing - align workflow configurations with current best practices for CI/CD automation Signed-off-by: mingcheng <[email protected]>
1 parent 8f9769a commit 2ed1884

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

.github/workflows/release.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release Crates
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
workflow_dispatch:
8+
inputs:
9+
dry-run:
10+
description: "Perform a dry run without actually publishing"
11+
required: false
12+
type: boolean
13+
default: false
14+
15+
jobs:
16+
publish-crates:
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 30
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v5
22+
23+
- name: Install Rust
24+
uses: dtolnay/rust-toolchain@stable
25+
with:
26+
toolchain: stable
27+
28+
- name: Cache Cargo dependencies
29+
uses: actions/cache@v4
30+
with:
31+
path: |
32+
~/.cargo/registry
33+
~/.cargo/git
34+
target
35+
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-cargo-release-
38+
${{ runner.os }}-cargo-
39+
40+
- name: Verify version matches tag
41+
if: github.event_name == 'push'
42+
run: |
43+
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
44+
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
45+
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
46+
echo "❌ Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
47+
exit 1
48+
fi
49+
echo "✅ Version check passed: $TAG_VERSION"
50+
51+
- name: Run tests
52+
run: cargo test --all --locked
53+
54+
- name: Verify package can be built
55+
run: cargo package --locked --allow-dirty
56+
57+
- name: Publish to crates.io (dry-run)
58+
if: github.event_name == 'workflow_dispatch' && inputs.dry-run
59+
run: cargo publish --dry-run --locked
60+
61+
- name: Publish to crates.io
62+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !inputs.dry-run)
63+
uses: katyo/publish-crates@v2
64+
with:
65+
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
66+
ignore-unpublished-changes: true
67+
68+
- name: Create GitHub Release
69+
if: github.event_name == 'push'
70+
uses: softprops/action-gh-release@v2
71+
with:
72+
generate_release_notes: true
73+
draft: false
74+
prerelease: false
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/rust.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!#
2-
# Copyright (c) 2025 Hangzhou Guanwaii Technology Co,.Ltd.
2+
# Copyright (c) 2025 Hangzhou Guanwaii Technology Co., Ltd.
33
#
44
# This source code is licensed under the MIT License,
55
# which is located in the LICENSE file in the source tree's root directory.
@@ -9,7 +9,7 @@
99
# File Created: 2025-03-05 11:10:40
1010
#
1111
# Modified By: mingcheng <[email protected]>
12-
# Last Modified: 2025-10-16 16:37:42
12+
# Last Modified: 2025-10-22 00:10:03
1313
##
1414

1515
name: Cargo Build & Test
@@ -104,7 +104,7 @@ jobs:
104104
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
105105
steps:
106106
- name: Checkout code
107-
uses: actions/checkout@v4
107+
uses: actions/checkout@v5
108108

109109
- name: Setup Rust toolchain (${{ matrix.toolchain }})
110110
uses: dtolnay/rust-toolchain@master

0 commit comments

Comments
 (0)