11name : Release
22
33on :
4- push :
5- tags :
6- - ' v*'
4+ pull_request :
5+ branches :
6+ - main
7+ types :
8+ - closed
9+ paths :
10+ - Cargo.toml
711
812permissions :
913 contents : write
1216 CARGO_TERM_COLOR : always
1317
1418jobs :
19+ create-tag :
20+ name : Create Release Tag
21+ if : github.event.pull_request.merged == true
22+ runs-on : ubuntu-latest
23+ outputs :
24+ tag : ${{ steps.version.outputs.tag }}
25+ version : ${{ steps.version.outputs.version }}
26+ created : ${{ steps.create.outputs.created }}
27+ steps :
28+ - uses : actions/checkout@v4
29+ with :
30+ fetch-depth : 0
31+
32+ - name : Get version from Cargo.toml
33+ id : version
34+ run : |
35+ VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' | tr -d '\r')
36+ TAG="v${VERSION}"
37+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
38+ echo "tag=${TAG}" >> $GITHUB_OUTPUT
39+
40+ - name : Check if tag already exists
41+ id : check_tag
42+ run : |
43+ TAG=${{ steps.version.outputs.tag }}
44+ if git rev-parse "$TAG" >/dev/null 2>&1; then
45+ echo "exists=true" >> $GITHUB_OUTPUT
46+ echo "Tag $TAG already exists, skipping"
47+ else
48+ echo "exists=false" >> $GITHUB_OUTPUT
49+ fi
50+
51+ - name : Create and push tag
52+ id : create
53+ run : |
54+ if [ "${{ steps.check_tag.outputs.exists }}" = "true" ]; then
55+ echo "created=false" >> $GITHUB_OUTPUT
56+ echo "Tag already exists — skipping release"
57+ exit 0
58+ fi
59+ TAG=${{ steps.version.outputs.tag }}
60+ git config user.name "github-actions[bot]"
61+ git config user.email "github-actions[bot]@users.noreply.github.com"
62+ git tag -a "$TAG" -m "Release $TAG"
63+ git push origin "$TAG"
64+ echo "created=true" >> $GITHUB_OUTPUT
65+ echo "Tag $TAG created and pushed"
66+
1567 build :
1668 name : Build ${{ matrix.target }}
69+ needs : create-tag
70+ if : needs.create-tag.outputs.created == 'true'
1771 runs-on : ${{ matrix.os }}
1872 strategy :
1973 fail-fast : false
@@ -22,68 +76,57 @@ jobs:
2276 - target : x86_64-unknown-linux-musl
2377 os : ubuntu-latest
2478 archive : tar.gz
25- use_cross : true
26- - target : aarch64-unknown-linux-musl
27- os : ubuntu-latest
28- archive : tar.gz
29- use_cross : true
30- - target : x86_64-apple-darwin
79+ - target : aarch64-apple-darwin
3180 os : macos-latest
3281 archive : tar.gz
33- use_cross : false
34- - target : aarch64-apple-darwin
82+ - target : x86_64-apple-darwin
3583 os : macos-latest
3684 archive : tar.gz
37- use_cross : false
3885 - target : x86_64-pc-windows-msvc
3986 os : windows-latest
4087 archive : zip
41- use_cross : false
4288
4389 steps :
4490 - uses : actions/checkout@v4
91+ with :
92+ ref : ${{ needs.create-tag.outputs.tag }}
4593
4694 - name : Install Rust toolchain
4795 uses : dtolnay/rust-toolchain@stable
4896 with :
4997 targets : ${{ matrix.target }}
5098
51- - name : Install cross
52- if : matrix.use_cross == true
53- run : cargo install cross --locked
54-
55- - name : Build release binary (cross)
56- if : matrix.use_cross == true
57- run : cross build --release --target ${{ matrix.target }}
99+ - name : Install musl tools (Linux)
100+ if : matrix.target == 'x86_64-unknown-linux-musl'
101+ run : sudo apt-get update && sudo apt-get install -y musl-tools
58102
59103 - name : Build release binary
60- if : matrix.use_cross == false
61104 run : cargo build --release --target ${{ matrix.target }}
62105
63106 - name : Package (unix)
64107 if : matrix.archive == 'tar.gz'
65108 run : |
66109 cd target/${{ matrix.target }}/release
67- tar czf ../../../gitkit-${{ github.ref_name }}-${{ matrix.target }}.tar.gz gitkit
110+ tar czf ../../../gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.tar.gz gitkit
68111 cd ../../..
69112
70113 - name : Package (windows)
71114 if : matrix.archive == 'zip'
72115 shell : pwsh
73116 run : |
74117 cd target/${{ matrix.target }}/release
75- Compress-Archive -Path gitkit.exe -DestinationPath ../../../gitkit-${{ github.ref_name }}-${{ matrix.target }}.zip
118+ Compress-Archive -Path gitkit.exe -DestinationPath ../../../gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.zip
76119 cd ../../..
77120
78121 - name : Upload artifact
79122 uses : actions/upload-artifact@v4
80123 with :
81124 name : gitkit-${{ matrix.target }}
82- path : gitkit-${{ github.ref_name }}-${{ matrix.target }}.*
125+ path : gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.*
83126
84127 github-release :
85128 name : Create GitHub Release
86- needs : build
129+ needs : [create-tag, build]
87130 runs-on : ubuntu-latest
88131 steps :
89132 - uses : actions/checkout@v4
@@ -97,6 +140,31 @@ jobs:
97140 - name : Create release
98141 uses : softprops/action-gh-release@v2
99142 with :
100- tag_name : ${{ github.ref_name }}
143+ tag_name : ${{ needs.create-tag.outputs.tag }}
101144 generate_release_notes : true
102145 files : artifacts/*
146+
147+ approve :
148+ name : Awaiting Manual Approval
149+ needs : github-release
150+ runs-on : ubuntu-latest
151+ environment :
152+ name : production
153+ steps :
154+ - name : Approval granted
155+ run : echo "Release approved for publishing to crates.io"
156+
157+ publish :
158+ name : Publish to crates.io
159+ needs : [create-tag, approve]
160+ runs-on : ubuntu-latest
161+ steps :
162+ - uses : actions/checkout@v4
163+ with :
164+ ref : ${{ needs.create-tag.outputs.tag }}
165+
166+ - name : Install Rust toolchain
167+ uses : dtolnay/rust-toolchain@stable
168+
169+ - name : Cargo publish
170+ run : cargo publish --token ${{ secrets.CARGO_TOKEN }}
0 commit comments