1+ name : Manual Release
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version_type :
7+ description : ' Version bump type'
8+ required : true
9+ default : ' patch'
10+ type : choice
11+ options :
12+ - major
13+ - minor
14+ - patch
15+
16+ env :
17+ CARGO_TERM_COLOR : always
18+
19+ jobs :
20+ release :
21+ name : Create Release
22+ runs-on : ubuntu-latest
23+ outputs :
24+ new_version : ${{ steps.version.outputs.new_version }}
25+ upload_url : ${{ steps.create_release.outputs.upload_url }}
26+ steps :
27+ - uses : actions/checkout@v4
28+ with :
29+ token : ${{ secrets.GITHUB_TOKEN }}
30+ fetch-depth : 0
31+
32+ - uses : dtolnay/rust-toolchain@stable
33+ - uses : Swatinem/rust-cache@v2
34+
35+ # Install cargo-edit for version bumping
36+ - name : Install cargo-edit
37+ run : cargo install cargo-edit
38+
39+ # Bump version in Cargo.toml
40+ - name : Bump version
41+ id : version
42+ run : |
43+ cargo set-version --bump ${{ github.event.inputs.version_type }}
44+ NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
45+ echo "new_version=v$NEW_VERSION" >> $GITHUB_OUTPUT
46+ echo "New version: v$NEW_VERSION"
47+
48+ # Run tests before release
49+ - name : Run tests
50+ run : cargo test
51+
52+ # Commit version bump
53+ - name : Commit version bump
54+ run : |
55+ git config --local user.email "action@github.com"
56+ git config --local user.name "GitHub Action"
57+ git add Cargo.toml Cargo.lock
58+ git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}"
59+ git tag ${{ steps.version.outputs.new_version }}
60+ git push origin main
61+ git push origin ${{ steps.version.outputs.new_version }}
62+
63+ # Create GitHub Release
64+ - name : Create Release
65+ id : create_release
66+ uses : actions/create-release@v1
67+ env :
68+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
69+ with :
70+ tag_name : ${{ steps.version.outputs.new_version }}
71+ release_name : Release ${{ steps.version.outputs.new_version }}
72+ draft : false
73+ prerelease : false
74+
75+ build-and-upload :
76+ name : Build and Upload
77+ needs : release
78+ strategy :
79+ matrix :
80+ include :
81+ - target : x86_64-unknown-linux-gnu
82+ os : ubuntu-latest
83+ - target : x86_64-pc-windows-msvc
84+ os : windows-latest
85+ - target : x86_64-apple-darwin
86+ os : macos-latest
87+ - target : aarch64-apple-darwin
88+ os : macos-latest
89+ runs-on : ${{ matrix.os }}
90+ steps :
91+ - uses : actions/checkout@v4
92+ with :
93+ ref : ${{ needs.release.outputs.new_version }}
94+ - uses : dtolnay/rust-toolchain@stable
95+ with :
96+ targets : ${{ matrix.target }}
97+ - uses : Swatinem/rust-cache@v2
98+ with :
99+ key : ${{ matrix.target }}
100+ - name : Build
101+ run : cargo build --release --target ${{ matrix.target }}
102+ - name : Create archive (Unix)
103+ if : matrix.os != 'windows-latest'
104+ run : |
105+ cd target/${{ matrix.target }}/release
106+ tar -czf ../../../gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.tar.gz gittype
107+ - name : Create archive (Windows)
108+ if : matrix.os == 'windows-latest'
109+ run : |
110+ cd target/${{ matrix.target }}/release
111+ Compress-Archive -Path gittype.exe -DestinationPath ../../../gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.zip
112+ - name : Upload Release Asset (Unix)
113+ if : matrix.os != 'windows-latest'
114+ uses : actions/upload-release-asset@v1
115+ env :
116+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
117+ with :
118+ upload_url : ${{ needs.release.outputs.upload_url }}
119+ asset_path : ./gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.tar.gz
120+ asset_name : gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.tar.gz
121+ asset_content_type : application/gzip
122+ - name : Upload Release Asset (Windows)
123+ if : matrix.os == 'windows-latest'
124+ uses : actions/upload-release-asset@v1
125+ env :
126+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
127+ with :
128+ upload_url : ${{ needs.release.outputs.upload_url }}
129+ asset_path : ./gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.zip
130+ asset_name : gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.zip
131+ asset_content_type : application/zip
132+
133+ publish-crates :
134+ name : Publish to crates.io
135+ runs-on : ubuntu-latest
136+ needs : [release, build-and-upload]
137+ steps :
138+ - uses : actions/checkout@v4
139+ with :
140+ ref : ${{ needs.release.outputs.new_version }}
141+ - uses : dtolnay/rust-toolchain@stable
142+ - uses : Swatinem/rust-cache@v2
143+ - name : Publish to crates.io
144+ run : cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
145+
146+ update-homebrew :
147+ name : Update Homebrew Formula
148+ runs-on : ubuntu-latest
149+ needs : [release, build-and-upload]
150+ steps :
151+ - name : Update Homebrew formula
152+ uses : dawidd6/action-homebrew-bump-formula@v3
153+ with :
154+ token : ${{ secrets.HOMEBREW_TAP_TOKEN }}
155+ tap : unhappychoice/homebrew-tap
156+ formula : gittype
157+ tag : ${{ needs.release.outputs.new_version }}
0 commit comments