Skip to content

Commit 80d1972

Browse files
authored
Added release workflow (#1195)
* Added release workflow * Addressed PR feedback
1 parent cd44b36 commit 80d1972

8 files changed

+258
-327
lines changed

.github/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
release_notes.txt
2+
rules_rust*.tar.gz

.github/github.bazelrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Bazel settings for use in Github CI
2+
3+
# Always display the flags being used
4+
common --announce_rc
5+
6+
# These settings make the windows workers behave similarly to unix workers
7+
startup --windows_enable_symlinks
8+
build --enable_runfiles
9+
10+
# Show errors in CI
11+
test --test_output=errors
12+
13+
# Show more information about failures
14+
build --verbose_failures
15+
16+
# UI for cleaner CI output
17+
common --color=no
18+
common --curses=no
19+
common --show_task_finish
20+
common --show_timestamps

.github/release_notes.template

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# {version}
2+
3+
```python
4+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
http_archive(
6+
name = "rules_rust",
7+
sha256 = "{sha256}",
8+
urls = [
9+
"https://mirror.bazel.build/github.com/bazelbuild/rules_rust/releases/download/{version}/rules_rust-v{version}.tar.gz",
10+
"https://github.com/bazelbuild/rules_rust/releases/download/{version}/rules_rust-v{version}.tar.gz",
11+
],
12+
)
13+
```
14+
15+
Additional documentation can be found at: https://bazelbuild.github.io/rules_rust/#setup

.github/version.bzl.template

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
---
2+
name: Release
3+
on:
4+
workflow_dispatch:
5+
6+
defaults:
7+
run:
8+
shell: bash
9+
10+
env:
11+
BAZEL_STARTUP_FLAGS: --bazelrc=${{ github.workspace }}/.github/github.bazelrc
12+
13+
jobs:
14+
validation:
15+
runs-on: ubuntu-20.04
16+
steps:
17+
- uses: actions/checkout@v2
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
31+
run: |
32+
git fetch origin &> /dev/null
33+
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
34+
if [[ -n "$(git tag -l ${version})" ]]; then
35+
echo "A release '${version}' already exists." >&2
36+
exit 1
37+
else
38+
echo "Tag '${version}' will be created"
39+
fi
40+
builds:
41+
needs: validation
42+
runs-on: ${{ matrix.os }}
43+
strategy:
44+
matrix:
45+
# Create a job for each target triple
46+
include:
47+
- os: macos-11
48+
env:
49+
TARGET: "aarch64-apple-darwin"
50+
- os: ubuntu-20.04
51+
env:
52+
TARGET: "aarch64-unknown-linux-gnu"
53+
- os: macos-11
54+
env:
55+
TARGET: "x86_64-apple-darwin"
56+
- os: ubuntu-20.04
57+
env:
58+
TARGET: "x86_64-pc-windows-gnu"
59+
- os: windows-2019
60+
env:
61+
TARGET: "x86_64-pc-windows-msvc"
62+
- os: ubuntu-20.04
63+
env:
64+
TARGET: "x86_64-unknown-linux-gnu"
65+
- os: ubuntu-20.04
66+
env:
67+
TARGET: "x86_64-unknown-linux-musl"
68+
steps:
69+
- uses: actions/checkout@v2
70+
- name: Install rust toolchains for host
71+
run: |
72+
# Detect the current version of rust
73+
version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | grep -o '[[:digit:].]\+')"
74+
rustup override set "${version}"
75+
rustup update stable && rustup default stable
76+
- name: Setup macos build tooling
77+
run: |
78+
sudo xcode-select -s /Applications/Xcode_12.4.app/Contents/Developer/
79+
# Set SDK environment variables
80+
echo "SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path)" >> $GITHUB_ENV
81+
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version)" >> $GITHUB_ENV
82+
if: startswith(matrix.os, 'macos')
83+
- name: Setup Windows Bazelrc
84+
run: |
85+
echo "startup --output_user_root=C:/tmp" > ./user.bazelrc
86+
if: startswith(matrix.os, 'Windows')
87+
- name: Build cargo-bazel binaries
88+
run: |
89+
# Build binaries
90+
if [[ "${RUNNER_OS}" == "Windows" ]]; then
91+
OUTPUT_PATH="$(cygpath "${{ github.workspace }}/crate_universe/target/artifacts" -m)"
92+
else
93+
OUTPUT_PATH="${{ github.workspace }}/crate_universe/target/artifacts"
94+
fi
95+
bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/cross_installer -- --target=${TARGET} --output="${OUTPUT_PATH}"
96+
env:
97+
TARGET: "${{ matrix.env.TARGET }}"
98+
- uses: actions/upload-artifact@v2
99+
with:
100+
name: "${{ matrix.env.TARGET }}"
101+
path: ${{ github.workspace }}/crate_universe/target/artifacts/${{ matrix.env.TARGET }}
102+
if-no-files-found: error
103+
release:
104+
needs: builds
105+
runs-on: ubuntu-20.04
106+
steps:
107+
- uses: actions/checkout@v2
108+
- uses: actions/download-artifact@v2
109+
with:
110+
path: ${{ github.workspace }}/crate_universe/target/artifacts
111+
- name: Detect the current version
112+
run: |
113+
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | grep -o '[[:digit:].]\+')"
114+
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
115+
- name: Create the rules archive
116+
run: |
117+
# Update urls and sha256 values
118+
bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/urls_generator -- --artifacts-dir="${ARTIFACTS_DIR}" --url-prefix="${URL_PREFIX}"
119+
# Publish to a known location
120+
bazel ${BAZEL_STARTUP_FLAGS[@]} run //distro:publish -- ${{ github.workspace }}/.github
121+
# Save the sha256 checksum of the distro archive to the environment
122+
sha256="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }')"
123+
echo "ARCHIVE_SHA256=${sha256}" >> $GITHUB_ENV
124+
env:
125+
CARGO_BAZEL_GENERATOR_URL: file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
126+
ARTIFACTS_DIR: ${{ github.workspace }}/crate_universe/target/artifacts
127+
URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }}
128+
- name: Generate release notes
129+
run: |
130+
# Generate the release notes
131+
sed 's/{version}/${{ env.RELEASE_VERSION }}/g' ${{ github.workspace }}/.github/release_notes.template \
132+
| sed 's/{sha256}/${{ env.ARCHIVE_SHA256 }}/g' \
133+
> ${{ github.workspace }}/.github/release_notes.txt
134+
- name: Create release
135+
uses: softprops/action-gh-release@v1
136+
id: rules_rust_release
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
with:
140+
generate_release_notes: true
141+
tag_name: ${{ env.RELEASE_VERSION }}
142+
body_path: ${{ github.workspace }}/.github/release_notes.txt
143+
target_commitish: ${{ github.base_ref }}
144+
145+
- name: "Upload the rules archive"
146+
uses: actions/upload-release-asset@v1
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
with:
150+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
151+
asset_name: rules_rust-v${{ env.RELEASE_VERSION }}.tar.gz
152+
asset_path: ${{ github.workspace }}/.github/rules_rust.tar.gz
153+
asset_content_type: application/gzip
154+
155+
# There must be a upload action for each platform triple we create
156+
- name: "Upload aarch64-apple-darwin"
157+
uses: actions/upload-release-asset@v1
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160+
with:
161+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
162+
asset_name: cargo-bazel-aarch64-apple-darwin
163+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel
164+
asset_content_type: application/octet-stream
165+
- name: "Upload aarch64-unknown-linux-gnu"
166+
uses: actions/upload-release-asset@v1
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169+
with:
170+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
171+
asset_name: cargo-bazel-aarch64-unknown-linux-gnu
172+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel
173+
asset_content_type: application/octet-stream
174+
- name: "Upload x86_64-apple-darwin"
175+
uses: actions/upload-release-asset@v1
176+
env:
177+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
178+
with:
179+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
180+
asset_name: cargo-bazel-x86_64-apple-darwin
181+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel
182+
asset_content_type: application/octet-stream
183+
- name: "Upload x86_64-pc-windows-gnu"
184+
uses: actions/upload-release-asset@v1
185+
env:
186+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
187+
with:
188+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
189+
asset_name: cargo-bazel-x86_64-pc-windows-gnu.exe
190+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe
191+
asset_content_type: application/octet-stream
192+
- name: "Upload x86_64-pc-windows-msvc"
193+
uses: actions/upload-release-asset@v1
194+
env:
195+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
196+
with:
197+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
198+
asset_name: cargo-bazel-x86_64-pc-windows-msvc.exe
199+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe
200+
asset_content_type: application/octet-stream
201+
- name: "Upload x86_64-unknown-linux-gnu"
202+
uses: actions/upload-release-asset@v1
203+
env:
204+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
205+
with:
206+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
207+
asset_name: cargo-bazel-x86_64-unknown-linux-gnu
208+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
209+
asset_content_type: application/octet-stream
210+
- name: "Upload x86_64-unknown-linux-musl"
211+
uses: actions/upload-release-asset@v1
212+
env:
213+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
214+
with:
215+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
216+
asset_name: cargo-bazel-x86_64-unknown-linux-musl
217+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel
218+
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)