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