Skip to content

Commit 5ae76cb

Browse files
committed
Addressed PR feedback
1 parent efbb66d commit 5ae76cb

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

.github/workflows/release.yaml

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
name: Release
33
on:
44
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: "The new version to release. E.g. `1.2.3`"
8-
required: true
95

106
defaults:
117
run:
@@ -16,17 +12,30 @@ env:
1612

1713
jobs:
1814
validation:
19-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-20.04
2016
steps:
2117
- uses: actions/checkout@v2
22-
with:
23-
ref: main
24-
- name: Detect the current version
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
30+
- name: Ensure release does not already exist
2531
run: |
32+
git fetch origin &> /dev/null
2633
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
27-
if [[ "${version}" != "${{ github.event.inputs.version }}" ]]; then
28-
echo "Release versions don't match: ${version} != ${{ github.event.inputs.version }}" >&2
34+
if [[ -n "$(git tag -l ${version})" ]]; then
35+
echo "A release '${version}' already exists." >&2
2936
exit 1
37+
else
38+
echo "Tag '${version}' will be created"
3039
fi
3140
builds:
3241
needs: validation
@@ -58,12 +67,10 @@ jobs:
5867
TARGET: "x86_64-unknown-linux-musl"
5968
steps:
6069
- uses: actions/checkout@v2
61-
with:
62-
ref: "${{ github.base_ref }}"
6370
- name: Install rust toolchains for host
6471
run: |
6572
# Detect the current version of rust
66-
version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | sed 's/DEFAULT_RUST_VERSION = "//' | sed 's/"//')"
73+
version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | grep -o '[[:digit:].]\+')"
6774
rustup override set "${version}"
6875
rustup update stable && rustup default stable
6976
- name: Setup macos build tooling
@@ -95,21 +102,16 @@ jobs:
95102
if-no-files-found: error
96103
release:
97104
needs: builds
98-
runs-on: ubuntu-latest
105+
runs-on: ubuntu-20.04
99106
steps:
100107
- uses: actions/checkout@v2
101-
with:
102-
ref: main
103108
- uses: actions/download-artifact@v2
104109
with:
105110
path: ${{ github.workspace }}/crate_universe/target/artifacts
106111
- name: Detect the current version
107112
run: |
108-
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
109-
if [[ "${version}" != "${{ github.event.inputs.version }}" ]]; then
110-
echo "Release versions don't match: ${version} != ${{ github.event.inputs.version }}" >&2
111-
exit 1
112-
fi
113+
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | grep -o '[[:digit:].]\+')"
114+
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
113115
- name: Create the rules archive
114116
run: |
115117
# Update urls and sha256 values
@@ -122,12 +124,12 @@ jobs:
122124
env:
123125
CARGO_BAZEL_GENERATOR_URL: file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
124126
ARTIFACTS_DIR: ${{ github.workspace }}/crate_universe/target/artifacts
125-
URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{github.event.inputs.version}}
127+
URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }}
126128
- name: Generate release notes
127129
run: |
128130
# Generate the release notes
129-
sed 's/{version}/${{ github.event.inputs.version }}/g' ${{ github.workspace }}/.github/release_notes.template \
130-
| sed 's/{sha256}/${{env.ARCHIVE_SHA256}}/g' \
131+
sed 's/{version}/${{ env.RELEASE_VERSION }}/g' ${{ github.workspace }}/.github/release_notes.template \
132+
| sed 's/{sha256}/${{ env.ARCHIVE_SHA256 }}/g' \
131133
> ${{ github.workspace }}/.github/release_notes.txt
132134
- name: Create release
133135
uses: softprops/action-gh-release@v1
@@ -136,7 +138,7 @@ jobs:
136138
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137139
with:
138140
generate_release_notes: true
139-
tag_name: ${{github.event.inputs.version}}
141+
tag_name: ${{ env.RELEASE_VERSION }}
140142
body_path: ${{ github.workspace }}/.github/release_notes.txt
141143
target_commitish: ${{ github.base_ref }}
142144

@@ -146,7 +148,7 @@ jobs:
146148
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147149
with:
148150
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
149-
asset_name: rules_rust-v${{ github.event.inputs.version }}.tar.gz
151+
asset_name: rules_rust-v${{ env.RELEASE_VERSION }}.tar.gz
150152
asset_path: ${{ github.workspace }}/.github/rules_rust.tar.gz
151153
asset_content_type: application/gzip
152154

0 commit comments

Comments
 (0)