fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
76360dd3
0.9.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}" 119bazel clean 120# Build an archive of the repo contents 121tar -czf ${{ github.workspace }}/.github/rules_rust.tar.gz --exclude=".git" --exclude=".github" --exclude="examples" -C ${{ github.workspace }} . 122# Save the sha256 checksum of the distro archive to the environment 123sha256="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }')" 124echo "ARCHIVE_SHA256=${sha256}" >> $GITHUB_ENV 125env : 126CARGO_BAZEL_GENERATOR_URL : file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 127ARTIFACTS_DIR : ${{ github.workspace }}/crate_universe/target/artifacts 128URL_PREFIX : https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }} 129# Upload the artifact in case creating a release fails so all artifacts can then be manually recovered. 130- uses : actions/upload-artifact@v2 131with : 132name : "rules_rust.tar.gz" 133path : ${{ github.workspace }}/.github/rules_rust.tar.gz 134if-no-files-found : error 135- name : Generate release notes 136run : | 137# Generate the release notes 138sed 's/{version}/${{ env.RELEASE_VERSION }}/g' ${{ github.workspace }}/.github/release_notes.template \ 139| sed 's/{sha256}/${{ env.ARCHIVE_SHA256 }}/g' \ 140> ${{ github.workspace }}/.github/release_notes.txt 141- name : Create release 142uses : softprops/action-gh-release@v1 143id : rules_rust_release 144env : 145GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 146with : 147generate_release_notes : true 148tag_name : ${{ env.RELEASE_VERSION }} 149body_path : ${{ github.workspace }}/.github/release_notes.txt 150target_commitish : ${{ github.base_ref }} 151 152- name : "Upload the rules archive" 153uses : actions/upload-release-asset@v1 154env : 155GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 156with : 157upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 158asset_name : rules_rust-v${{ env.RELEASE_VERSION }}.tar.gz 159asset_path : ${{ github.workspace }}/.github/rules_rust.tar.gz 160asset_content_type : application/gzip 161 162# There must be a upload action for each platform triple we create 163- name : "Upload aarch64-apple-darwin" 164uses : actions/upload-release-asset@v1 165env : 166GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 167with : 168upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 169asset_name : cargo-bazel-aarch64-apple-darwin 170asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel 171asset_content_type : application/octet-stream 172- name : "Upload aarch64-unknown-linux-gnu" 173uses : actions/upload-release-asset@v1 174env : 175GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 176with : 177upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 178asset_name : cargo-bazel-aarch64-unknown-linux-gnu 179asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel 180asset_content_type : application/octet-stream 181- name : "Upload x86_64-apple-darwin" 182uses : actions/upload-release-asset@v1 183env : 184GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 185with : 186upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 187asset_name : cargo-bazel-x86_64-apple-darwin 188asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel 189asset_content_type : application/octet-stream 190- name : "Upload x86_64-pc-windows-gnu" 191uses : actions/upload-release-asset@v1 192env : 193GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 194with : 195upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 196asset_name : cargo-bazel-x86_64-pc-windows-gnu.exe 197asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe 198asset_content_type : application/octet-stream 199- name : "Upload x86_64-pc-windows-msvc" 200uses : actions/upload-release-asset@v1 201env : 202GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 203with : 204upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 205asset_name : cargo-bazel-x86_64-pc-windows-msvc.exe 206asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe 207asset_content_type : application/octet-stream 208- name : "Upload x86_64-unknown-linux-gnu" 209uses : actions/upload-release-asset@v1 210env : 211GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 212with : 213upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 214asset_name : cargo-bazel-x86_64-unknown-linux-gnu 215asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 216asset_content_type : application/octet-stream 217- name : "Upload x86_64-unknown-linux-musl" 218uses : actions/upload-release-asset@v1 219env : 220GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 221with : 222upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 223asset_name : cargo-bazel-x86_64-unknown-linux-musl 224asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel 225asset_content_type : application/octet-stream