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