2
2
name : Release
3
3
on :
4
4
workflow_dispatch :
5
- inputs :
6
- version :
7
- description : " The new version to release. E.g. `1.2.3`"
8
- required : true
9
5
10
6
defaults :
11
7
run :
16
12
17
13
jobs :
18
14
validation :
19
- runs-on : ubuntu-latest
15
+ runs-on : ubuntu-20.04
20
16
steps :
21
17
- 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
25
31
run : |
32
+ git fetch origin &> /dev/null
26
33
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
29
36
exit 1
37
+ else
38
+ echo "Tag '${version}' will be created"
30
39
fi
31
40
builds :
32
41
needs : validation
@@ -58,12 +67,10 @@ jobs:
58
67
TARGET : " x86_64-unknown-linux-musl"
59
68
steps :
60
69
- uses : actions/checkout@v2
61
- with :
62
- ref : " ${{ github.base_ref }}"
63
70
- name : Install rust toolchains for host
64
71
run : |
65
72
# 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:].]\+ ')"
67
74
rustup override set "${version}"
68
75
rustup update stable && rustup default stable
69
76
- name : Setup macos build tooling
@@ -95,21 +102,16 @@ jobs:
95
102
if-no-files-found : error
96
103
release :
97
104
needs : builds
98
- runs-on : ubuntu-latest
105
+ runs-on : ubuntu-20.04
99
106
steps :
100
107
- uses : actions/checkout@v2
101
- with :
102
- ref : main
103
108
- uses : actions/download-artifact@v2
104
109
with :
105
110
path : ${{ github.workspace }}/crate_universe/target/artifacts
106
111
- name : Detect the current version
107
112
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
113
115
- name : Create the rules archive
114
116
run : |
115
117
# Update urls and sha256 values
@@ -122,12 +124,12 @@ jobs:
122
124
env :
123
125
CARGO_BAZEL_GENERATOR_URL : file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
124
126
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 }}
126
128
- name : Generate release notes
127
129
run : |
128
130
# 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' \
131
133
> ${{ github.workspace }}/.github/release_notes.txt
132
134
- name : Create release
133
135
uses : softprops/action-gh-release@v1
@@ -136,7 +138,7 @@ jobs:
136
138
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
137
139
with :
138
140
generate_release_notes : true
139
- tag_name : ${{github.event.inputs.version }}
141
+ tag_name : ${{ env.RELEASE_VERSION }}
140
142
body_path : ${{ github.workspace }}/.github/release_notes.txt
141
143
target_commitish : ${{ github.base_ref }}
142
144
@@ -146,7 +148,7 @@ jobs:
146
148
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
147
149
with :
148
150
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
150
152
asset_path : ${{ github.workspace }}/.github/rules_rust.tar.gz
151
153
asset_content_type : application/gzip
152
154
0 commit comments