1+ name : Build and Upload Binaries
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ release_tag :
7+ description : ' Release tag to upload binaries to (e.g. jito-bell-v0.1.0)'
8+ required : true
9+ type : string
10+ package_path :
11+ description : ' Path to the package'
12+ required : true
13+ default : ' jito-bell'
14+ type : string
15+ publish_release :
16+ description : ' Publish the release after uploading binaries'
17+ required : true
18+ default : true
19+ type : boolean
20+
21+ jobs :
22+ build-binaries :
23+ name : Build ${{ matrix.target }}
24+ runs-on : ${{ matrix.os }}
25+ strategy :
26+ fail-fast : false
27+ matrix :
28+ include :
29+ - os : ubuntu-latest
30+ target : x86_64-unknown-linux-musl
31+ name : x86_64-unknown-linux-musl
32+ - os : macos-latest
33+ target : x86_64-apple-darwin
34+ name : x86_64-apple-darwin
35+ - os : windows-latest
36+ target : x86_64-pc-windows-msvc
37+ name : x86_64-pc-windows-msvc
38+ steps :
39+ - name : Git Checkout
40+ uses : actions/checkout@v4
41+ with :
42+ fetch-depth : 1
43+ ref : refs/tags/${{ github.event.inputs.release_tag }}
44+
45+ - name : Setup Rust
46+ uses : dtolnay/rust-toolchain@stable
47+ with :
48+ targets : ${{ matrix.target }}
49+
50+ - name : Install musl-tools (Linux only)
51+ if : matrix.os == 'ubuntu-latest'
52+ run : sudo apt-get update && sudo apt-get install -y musl-tools
53+
54+ - name : Rust Cache
55+ uses : Swatinem/rust-cache@v2
56+ with :
57+ key : " jito-bell-${{ matrix.target }}-${{ inputs.package_path }}"
58+
59+ - name : Extract crate name and version
60+ id : crate_info
61+ shell : bash
62+ run : |
63+ CRATE_NAME="${{ inputs.package_path }}"
64+ VERSION=$(grep -m1 'version =' ${{ inputs.package_path }}/Cargo.toml | cut -d '"' -f2)
65+ echo "crate_name=$CRATE_NAME" >> $GITHUB_OUTPUT
66+ echo "version=$VERSION" >> $GITHUB_OUTPUT
67+ echo "Building $CRATE_NAME version $VERSION for ${{ matrix.target }}"
68+
69+ - name : Build
70+ run : cargo build --release --target ${{ matrix.target }}
71+
72+ - name : Prepare binary (Unix)
73+ if : matrix.os != 'windows-latest'
74+ run : |
75+ CRATE_NAME="${{ steps.crate_info.outputs.crate_name }}"
76+ VERSION="${{ steps.crate_info.outputs.version }}"
77+ BINARY_NAME="${CRATE_NAME}-v${VERSION}-${{ matrix.target }}"
78+
79+ echo "Building binary with new version: $VERSION"
80+
81+ # Copy binary to root with appropriate name
82+ cp ./target/${{ matrix.target }}/release/${CRATE_NAME} ${BINARY_NAME}
83+
84+ # Create checksum
85+ shasum -a 256 ${BINARY_NAME} > ${BINARY_NAME}.sha256
86+
87+ - name : Prepare binary (Windows)
88+ if : matrix.os == 'windows-latest'
89+ shell : pwsh
90+ run : |
91+ $CRATE_NAME = "${{ steps.crate_info.outputs.crate_name }}"
92+ $VERSION = "${{ steps.crate_info.outputs.version }}"
93+ $BINARY_NAME = "${CRATE_NAME}-v${VERSION}-${{ matrix.target }}.exe"
94+
95+ Write-Host "Building binary with new version: $VERSION"
96+
97+ # Copy binary to root with appropriate name
98+ Copy-Item "./target/${{ matrix.target }}/release/${CRATE_NAME}.exe" -Destination $BINARY_NAME
99+
100+ # Create checksum
101+ $hash = Get-FileHash -Path $BINARY_NAME -Algorithm SHA256
102+ $hash.Hash | Out-File -FilePath "${BINARY_NAME}.sha256"
103+
104+ - name : Upload binary artifacts (Unix)
105+ if : matrix.os != 'windows-latest'
106+ uses : actions/upload-artifact@v4
107+ with :
108+ name : ${{ matrix.name }}
109+ path : |
110+ ${{ steps.crate_info.outputs.crate_name }}-v${{ steps.crate_info.outputs.version }}-${{ matrix.target }}
111+ ${{ steps.crate_info.outputs.crate_name }}-v${{ steps.crate_info.outputs.version }}-${{ matrix.target }}.sha256
112+ retention-days : 7
113+
114+ - name : Upload binary artifacts (Windows)
115+ if : matrix.os == 'windows-latest'
116+ uses : actions/upload-artifact@v4
117+ with :
118+ name : ${{ matrix.name }}
119+ path : |
120+ ${{ steps.crate_info.outputs.crate_name }}-v${{ steps.crate_info.outputs.version }}-${{ matrix.target }}.exe
121+ ${{ steps.crate_info.outputs.crate_name }}-v${{ steps.crate_info.outputs.version }}-${{ matrix.target }}.exe.sha256
122+ retention-days : 7
123+
124+ publish-release :
125+ name : Publish Release
126+ needs : build-binaries
127+ runs-on : ubuntu-latest
128+ permissions :
129+ contents : write
130+ steps :
131+ - name : Git Checkout
132+ uses : actions/checkout@v4
133+ with :
134+ ref : ${{ github.event.inputs.release_tag }}
135+
136+ - name : Extract release information
137+ id : release_info
138+ shell : bash
139+ run : |
140+ CRATE_NAME="${{ inputs.package_path }}"
141+ VERSION=$(grep -m1 'version =' ${{ inputs.package_path }}/Cargo.toml | cut -d '"' -f2)
142+ echo "crate_name=$CRATE_NAME" >> $GITHUB_OUTPUT
143+ echo "version=$VERSION" >> $GITHUB_OUTPUT
144+
145+ - name : Create release directory
146+ run : mkdir -p release-binaries
147+
148+ - name : Download Linux binary
149+ uses : actions/download-artifact@v4
150+ with :
151+ name : x86_64-unknown-linux-musl
152+ path : release-binaries
153+
154+ - name : Download macOS binary
155+ uses : actions/download-artifact@v4
156+ with :
157+ name : x86_64-apple-darwin
158+ path : release-binaries
159+
160+ - name : Download Windows binary
161+ uses : actions/download-artifact@v4
162+ with :
163+ name : x86_64-pc-windows-msvc
164+ path : release-binaries
165+
166+ - name : Generate release notes
167+ id : release_notes
168+ run : |
169+ echo "" >> RELEASE_NOTES.md
170+ echo "## Binaries" >> RELEASE_NOTES.md
171+ echo "- Linux (x86_64-unknown-linux-musl)" >> RELEASE_NOTES.md
172+ echo "- macOS (x86_64-apple-darwin)" >> RELEASE_NOTES.md
173+ echo "- Windows (x86_64-pc-windows-msvc)" >> RELEASE_NOTES.md
174+
175+ if [ -f "CHANGELOG.md" ]; then
176+ echo "" >> RELEASE_NOTES.md
177+ echo "## Changelog" >> RELEASE_NOTES.md
178+ # Extract the relevant section from CHANGELOG.md if it exists
179+ grep -A 50 "^## ${{ steps.release_info.outputs.version }}" CHANGELOG.md | grep -B 50 -m 2 "^## " | head -n -1 >> RELEASE_NOTES.md || true
180+ fi
181+
182+ - name : Update release with binaries
183+ uses : ncipollo/release-action@v1
184+ with :
185+ tag : ${{ github.event.inputs.release_tag }}
186+ name : " ${{ steps.release_info.outputs.crate_name }} v${{ steps.release_info.outputs.version }}"
187+ bodyFile : " RELEASE_NOTES.md"
188+ artifacts : " ./release-binaries/*"
189+ artifactErrorsFailBuild : false
190+ allowUpdates : true
191+ draft : ${{ github.event.inputs.publish_release != 'true' }}
192+
193+ - name : Publish Release
194+ if : github.event.inputs.publish_release == 'true'
195+ env :
196+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
197+ run : |
198+ gh release edit "${{ github.event.inputs.release_tag }}" --draft=false
0 commit comments