@@ -2,6 +2,8 @@ name: Release
22
33on :
44 push :
5+ branches :
6+ - main
57 tags :
68 - ' v*'
79 workflow_dispatch :
1012 CARGO_TERM_COLOR : always
1113
1214jobs :
15+ check-version :
16+ name : Check Version & Create Tag
17+ runs-on : ubuntu-latest
18+ outputs :
19+ should_release : ${{ steps.version_check.outputs.should_release }}
20+ new_tag : ${{ steps.version_check.outputs.new_tag }}
21+ version : ${{ steps.version_check.outputs.version }}
22+ permissions :
23+ contents : write
24+
25+ steps :
26+ - name : Checkout code
27+ uses : actions/checkout@v4
28+ with :
29+ fetch-depth : 0
30+
31+ - name : Get Cargo.toml version
32+ id : cargo_version
33+ run : |
34+ VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1')
35+ echo "version=$VERSION" >> $GITHUB_OUTPUT
36+ echo "Cargo.toml version: $VERSION"
37+
38+ - name : Get latest git tag
39+ id : git_tag
40+ run : |
41+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
42+ echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
43+ echo "Latest git tag: $LATEST_TAG"
44+
45+ - name : Compare versions
46+ id : version_check
47+ run : |
48+ CARGO_VERSION="${{ steps.cargo_version.outputs.version }}"
49+ LATEST_TAG="${{ steps.git_tag.outputs.latest_tag }}"
50+ LATEST_TAG_VERSION=${LATEST_TAG#v}
51+
52+ echo "Comparing: Cargo($CARGO_VERSION) vs Git($LATEST_TAG_VERSION)"
53+
54+ if [ "$CARGO_VERSION" != "$LATEST_TAG_VERSION" ]; then
55+ echo "should_release=true" >> $GITHUB_OUTPUT
56+ echo "new_tag=v$CARGO_VERSION" >> $GITHUB_OUTPUT
57+ echo "version=$CARGO_VERSION" >> $GITHUB_OUTPUT
58+ echo "New version detected, will create tag: v$CARGO_VERSION"
59+ else
60+ echo "should_release=false" >> $GITHUB_OUTPUT
61+ echo "Version is up to date, no release needed"
62+ fi
63+
64+ - name : Create and push tag
65+ if : steps.version_check.outputs.should_release == 'true'
66+ run : |
67+ git config user.name "github-actions[bot]"
68+ git config user.email "github-actions[bot]@users.noreply.github.com"
69+ git tag -a "${{ steps.version_check.outputs.new_tag }}" -m "Release ${{ steps.version_check.outputs.new_tag }}"
70+ git push origin "${{ steps.version_check.outputs.new_tag }}"
71+
1372 build :
1473 name : Build for ${{ matrix.target }}
74+ needs : check-version
75+ if : needs.check-version.outputs.should_release == 'true'
1576 runs-on : ${{ matrix.os }}
1677 strategy :
1778 matrix :
@@ -79,10 +140,11 @@ jobs:
79140
80141 release :
81142 name : Create Release
82- needs : build
143+ needs : [check-version, build]
83144 runs-on : ubuntu-latest
84- if : startsWith(github.ref, 'refs/tags/')
85-
145+ permissions :
146+ contents : write
147+
86148 steps :
87149 - name : Checkout code
88150 uses : actions/checkout@v4
@@ -98,12 +160,12 @@ jobs:
98160 - name : Create Release
99161 uses : softprops/action-gh-release@v1
100162 with :
101- tag_name : ${{ github.ref_name }}
102- name : Release ${{ github.ref_name }}
163+ tag_name : ${{ needs.check-version.outputs.new_tag }}
164+ name : Release ${{ needs.check-version.outputs.new_tag }}
103165 draft : false
104166 prerelease : false
105167 body : |
106- ## Changes in ${{ github.ref_name }}
168+ ## Changes in ${{ needs.check-version.outputs.new_tag }}
107169
108170 ### Downloads
109171 - **Linux (x86_64)**: rbdc-mcp-linux-x86_64
@@ -112,7 +174,7 @@ jobs:
112174 - **macOS (Apple Silicon)**: rbdc-mcp-macos-aarch64
113175
114176 ### Installation(Recommended use cargo)
115- 0. cargo install --git https://github.com/rbatis/rbdc-mcp.git
177+ 0. cargo install --git https://github.com/rbatis/rbdc-mcp.git --tag ${{ needs.check-version.outputs.new_tag }}
116178 ### Installation(use binary)
117179 1. Download the appropriate binary for your platform
118180 2. Make it executable (Unix systems): `chmod +x rbdc-mcp-*`
0 commit comments