22name : Release
33on :
44 workflow_dispatch :
5+ pull_request :
6+ branches :
7+ - main
8+ paths :
9+ - version.bzl
510 push :
611 branches :
712 - main
2025 runs-on : ubuntu-20.04
2126 steps :
2227 - uses : actions/checkout@v3
23- # TODO: Unfortunately it's not obvious how to restrict `workflow_dispatch` to a particular branch
24- # so this step ensures releases are always done off of `main`.
25- - name : Ensure branch is 'main'
26- run : |
27- git fetch origin &> /dev/null
28- branch="$(git rev-parse --abbrev-ref HEAD)"
29- if [[ "${branch}" != "main" ]]; then
30- echo "The release branch must be main. Got '${branch}'' instead." >&2
31- exit 1
32- else
33- echo "Branch is '${branch}'"
34- fi
3528 - name : Ensure release does not already exist
3629 run : |
3730 git fetch origin &> /dev/null
@@ -168,6 +161,7 @@ jobs:
168161 | sed 's#{sha256_base64}#${{ env.ARCHIVE_SHA256_BASE64 }}#g' \
169162 > ${{ github.workspace }}/.github/release_notes.txt
170163 - name : Create release
164+ if : startsWith(github.ref, 'refs/heads/main')
171165 uses : softprops/action-gh-release@v1
172166 id : rules_rust_release
173167 env :
@@ -179,6 +173,7 @@ jobs:
179173 target_commitish : ${{ github.base_ref }}
180174
181175 - name : " Upload the rules archive"
176+ if : startsWith(github.ref, 'refs/heads/main')
182177 uses : actions/upload-release-asset@v1
183178 env :
184179 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -190,6 +185,7 @@ jobs:
190185
191186 # There must be a upload action for each platform triple we create
192187 - name : " Upload aarch64-apple-darwin"
188+ if : startsWith(github.ref, 'refs/heads/main')
193189 uses : actions/upload-release-asset@v1
194190 env :
195191 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -199,6 +195,7 @@ jobs:
199195 asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel
200196 asset_content_type : application/octet-stream
201197 - name : " Upload aarch64-pc-windows-msvc"
198+ if : startsWith(github.ref, 'refs/heads/main')
202199 uses : actions/upload-release-asset@v1
203200 env :
204201 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -208,6 +205,7 @@ jobs:
208205 asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-pc-windows-msvc/cargo-bazel.exe
209206 asset_content_type : application/octet-stream
210207 - name : " Upload aarch64-unknown-linux-gnu"
208+ if : startsWith(github.ref, 'refs/heads/main')
211209 uses : actions/upload-release-asset@v1
212210 env :
213211 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -217,6 +215,7 @@ jobs:
217215 asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel
218216 asset_content_type : application/octet-stream
219217 - name : " Upload x86_64-apple-darwin"
218+ if : startsWith(github.ref, 'refs/heads/main')
220219 uses : actions/upload-release-asset@v1
221220 env :
222221 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -226,6 +225,7 @@ jobs:
226225 asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel
227226 asset_content_type : application/octet-stream
228227 - name : " Upload x86_64-pc-windows-gnu"
228+ if : startsWith(github.ref, 'refs/heads/main')
229229 uses : actions/upload-release-asset@v1
230230 env :
231231 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -235,6 +235,7 @@ jobs:
235235 asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe
236236 asset_content_type : application/octet-stream
237237 - name : " Upload x86_64-pc-windows-msvc"
238+ if : startsWith(github.ref, 'refs/heads/main')
238239 uses : actions/upload-release-asset@v1
239240 env :
240241 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -244,6 +245,7 @@ jobs:
244245 asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe
245246 asset_content_type : application/octet-stream
246247 - name : " Upload x86_64-unknown-linux-gnu"
248+ if : startsWith(github.ref, 'refs/heads/main')
247249 uses : actions/upload-release-asset@v1
248250 env :
249251 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -253,6 +255,7 @@ jobs:
253255 asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
254256 asset_content_type : application/octet-stream
255257 - name : " Upload x86_64-unknown-linux-musl"
258+ if : startsWith(github.ref, 'refs/heads/main')
256259 uses : actions/upload-release-asset@v1
257260 env :
258261 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments