@@ -2,218 +2,18 @@ name: Release
22
33on :
44 pull_request :
5- branches :
6- - main
7- types :
8- - closed
9- paths :
10- - Cargo.toml
5+ branches : [main]
6+ types : [closed]
7+ paths : [Cargo.toml]
118 workflow_dispatch :
129
1310permissions :
1411 contents : write
1512
16- env :
17- CARGO_TERM_COLOR : always
18-
1913jobs :
20- create-tag :
21- name : Create Release Tag
14+ release :
2215 if : github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
23- runs-on : ubuntu-latest
24- outputs :
25- tag : ${{ steps.version.outputs.tag }}
26- version : ${{ steps.version.outputs.version }}
27- created : ${{ steps.create.outputs.created }}
28- steps :
29- - uses : actions/checkout@v4
30- with :
31- fetch-depth : 0
32-
33- - name : Get version from Cargo.toml
34- id : version
35- run : |
36- VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' | tr -d '\r' | xargs)
37- TAG="v${VERSION}"
38- echo "version=${VERSION}" >> $GITHUB_OUTPUT
39- echo "tag=${TAG}" >> $GITHUB_OUTPUT
40-
41- - name : Check if tag already exists
42- id : check_tag
43- run : |
44- TAG=${{ steps.version.outputs.tag }}
45- if git rev-parse "$TAG" >/dev/null 2>&1; then
46- echo "exists=true" >> $GITHUB_OUTPUT
47- echo "Tag $TAG already exists, skipping"
48- else
49- echo "exists=false" >> $GITHUB_OUTPUT
50- fi
51-
52- - name : Create and push tag
53- id : create
54- run : |
55- if [ "${{ steps.check_tag.outputs.exists }}" = "true" ]; then
56- echo "created=false" >> $GITHUB_OUTPUT
57- echo "Tag already exists — skipping release"
58- exit 0
59- fi
60- TAG=${{ steps.version.outputs.tag }}
61- git config user.name "github-actions[bot]"
62- git config user.email "github-actions[bot]@users.noreply.github.com"
63- git tag -a "$TAG" -m "Release $TAG"
64- git push origin "$TAG"
65- echo "created=true" >> $GITHUB_OUTPUT
66- echo "Tag $TAG created and pushed"
67-
68- build :
69- name : Build ${{ matrix.target }}
70- needs : create-tag
71- if : needs.create-tag.outputs.created == 'true'
72- runs-on : ${{ matrix.os }}
73- strategy :
74- fail-fast : false
75- matrix :
76- include :
77- - target : x86_64-unknown-linux-musl
78- os : ubuntu-latest
79- archive : tar.gz
80- - target : aarch64-apple-darwin
81- os : macos-latest
82- archive : tar.gz
83- - target : x86_64-apple-darwin
84- os : macos-latest
85- archive : tar.gz
86- - target : x86_64-pc-windows-msvc
87- os : windows-latest
88- archive : zip
89-
90- steps :
91- - uses : actions/checkout@v4
92- with :
93- ref : ${{ needs.create-tag.outputs.tag }}
94-
95- - name : Install Rust toolchain
96- uses : dtolnay/rust-toolchain@stable
97- with :
98- targets : ${{ matrix.target }}
99-
100- - name : Install musl tools (Linux)
101- if : matrix.target == 'x86_64-unknown-linux-musl'
102- run : sudo apt-get update && sudo apt-get install -y musl-tools
103-
104- - name : Build release binary
105- run : cargo build --release --target ${{ matrix.target }}
106-
107- - name : Package (unix)
108- if : matrix.archive == 'tar.gz'
109- run : |
110- cd target/${{ matrix.target }}/release
111- tar czf "../../../gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.tar.gz" gitkit
112- cd ../../..
113-
114- - name : Package (windows)
115- if : matrix.archive == 'zip'
116- shell : pwsh
117- run : |
118- cd target/${{ matrix.target }}/release
119- Compress-Archive -Path gitkit.exe -DestinationPath "../../../gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.zip"
120- cd ../../..
121-
122- - name : Upload artifact
123- uses : actions/upload-artifact@v4
124- with :
125- name : gitkit-${{ matrix.target }}
126- path : gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.*
127-
128- github-release :
129- name : Create GitHub Release
130- needs : [create-tag, build]
131- runs-on : ubuntu-latest
132- steps :
133- - uses : actions/checkout@v4
134-
135- - name : Download all artifacts
136- uses : actions/download-artifact@v4
137- with :
138- path : artifacts
139- merge-multiple : true
140-
141- - name : Create release
142- uses : softprops/action-gh-release@v2
143- with :
144- tag_name : ${{ needs.create-tag.outputs.tag }}
145- generate_release_notes : true
146- files : artifacts/*
147-
148- approve :
149- name : Awaiting Manual Approval
150- needs : github-release
151- runs-on : ubuntu-latest
152- environment :
153- name : production
154- steps :
155- - name : Approval granted
156- run : echo "Release approved for publishing to crates.io"
157-
158- ensure-owners :
159- name : Ensure crates.io owners
160- needs : create-tag
161- if : needs.create-tag.outputs.created == 'true'
162- runs-on : ubuntu-latest
163- steps :
164- - uses : actions/checkout@v4
165- with :
166- ref : ${{ needs.create-tag.outputs.tag }}
167- - name : Install Rust toolchain
168- uses : dtolnay/rust-toolchain@stable
169-
170- - name : Add crates.io owners (best-effort)
171- env :
172- TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
173- OWNERS : github:univerlab:owners
174- run : |
175- set -eu
176- if [ -z "$TOKEN" ]; then
177- echo "No cargo token found in CARGO_REGISTRY_TOKEN; skipping owners update"
178- exit 0
179- fi
180- CRATE_NAME=$(grep '^name = ' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/' | tr -d '\r')
181- echo "crate=$CRATE_NAME"
182- for owner in $(echo "$OWNERS" | tr ',' ' '); do
183- echo "Adding owner: $owner"
184- cargo owner --token "$TOKEN" --add "$owner" || echo "cargo owner failed for $owner (continuing)"
185- done
186-
187- publish :
188- name : Publish to crates.io
189- needs : [create-tag, approve, ensure-owners]
190- runs-on : ubuntu-latest
191- steps :
192- - uses : actions/checkout@v4
193- with :
194- ref : ${{ needs.create-tag.outputs.tag }}
195-
196- - name : Install Rust toolchain
197- uses : dtolnay/rust-toolchain@stable
198-
199- - name : Check if stable release
200- id : version_check
201- run : |
202- VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/' | xargs)
203- if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
204- echo "is_stable=true" >> $GITHUB_OUTPUT
205- echo "Version $VERSION is stable — will publish"
206- else
207- echo "is_stable=false" >> $GITHUB_OUTPUT
208- echo "Version $VERSION is prerelease/dev — skipping publish"
209- fi
210-
211- - name : Cargo publish
212- if : steps.version_check.outputs.is_stable == 'true'
213- env :
214- CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
215- run : cargo publish --allow-dirty
216-
217- - name : Skipped prerelease
218- if : steps.version_check.outputs.is_stable == 'false'
219- run : echo "⏭️ Skipped crates.io publish for prerelease version"
16+ uses : UniverLab/workflows/.github/workflows/rust-release.yml@main
17+ with :
18+ binary-name : gitkit
19+ secrets : inherit
0 commit comments