Skip to content

Commit 3bec7f8

Browse files
committed
branch validation
1 parent dc91c06 commit 3bec7f8

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

.github/workflows/release.yaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,30 @@ jobs:
1515
runs-on: ubuntu-20.04
1616
steps:
1717
- uses: actions/checkout@v2
18-
with:
19-
ref: main
18+
# TODO: Unfortunately it's not obvious how to restrict `workflow_dispatch` to a particular branch
19+
# so this step ensures releases are always done off of `main`.
20+
- name: Ensure branch is 'main'
21+
run: |
22+
git fetch origin &> /dev/null
23+
branch="$(git rev-parse --abbrev-ref HEAD)"
24+
if [[ "${branch}" != "main" ]]; then
25+
echo "The release branch must be main. Got '${branch}'' instead." >&2
26+
exit 1
27+
else
28+
echo "Branch is '${branch}'"
29+
fi
2030
- name: Ensure release does not already exist
2131
run: |
32+
git fetch origin &> /dev/null
2233
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
2334
if [[ -n "$(git tag -l ${version})" ]]; then
2435
echo "A release '${version}' already exists." >&2
36+
exit 1
37+
else
38+
echo "Tag '${version}' will be created"
2539
fi
2640
builds:
41+
needs: validation
2742
runs-on: ${{ matrix.os }}
2843
strategy:
2944
matrix:
@@ -52,8 +67,6 @@ jobs:
5267
TARGET: "x86_64-unknown-linux-musl"
5368
steps:
5469
- uses: actions/checkout@v2
55-
with:
56-
ref: "${{ github.base_ref }}"
5770
- name: Install rust toolchains for host
5871
run: |
5972
# Detect the current version of rust
@@ -92,8 +105,6 @@ jobs:
92105
runs-on: ubuntu-20.04
93106
steps:
94107
- uses: actions/checkout@v2
95-
with:
96-
ref: main
97108
- uses: actions/download-artifact@v2
98109
with:
99110
path: ${{ github.workspace }}/crate_universe/target/artifacts

0 commit comments

Comments
 (0)