fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
2bad96d9
cleanup
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 : 49fail-fast : false 50matrix : 51# Create a job for each target triple 52include : 53- os : macos-12 54env : 55TARGET : "aarch64-apple-darwin" 56- os : ubuntu-20.04 57env : 58TARGET : "aarch64-unknown-linux-gnu" 59- os : windows-2022 60env : 61TARGET : "aarch64-pc-windows-msvc" 62- os : macos-12 63env : 64TARGET : "x86_64-apple-darwin" 65- os : ubuntu-20.04 66env : 67TARGET : "x86_64-pc-windows-gnu" 68- os : windows-2022 69env : 70TARGET : "x86_64-pc-windows-msvc" 71- os : ubuntu-20.04 72env : 73TARGET : "x86_64-unknown-linux-gnu" 74- os : ubuntu-20.04 75env : 76TARGET : "x86_64-unknown-linux-musl" 77steps : 78- uses : actions/checkout@v3 79- name : Install rust toolchains for host 80run : | 81# Detect the current version of rust 82version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | grep -o '[[:digit:].]\+')" 83rustup override set "${version}" 84rustup target add ${TARGET} 85rustup update stable --no-self-update --force-non-host 86rustup default stable 87env : 88TARGET : "${{ matrix.env.TARGET }}" 89- name : Setup macos build tooling 90run : | 91sudo xcode-select -s /Applications/Xcode_13.1.app/Contents/Developer/ 92# Set SDK environment variables 93echo "SDKROOT=$(xcrun -sdk macosx12.0 --show-sdk-path)" >> $GITHUB_ENV 94echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx12.0 --show-sdk-platform-version)" >> $GITHUB_ENV 95if : startswith(matrix.os, 'macos') 96- name : Setup Windows Bazelrc 97run : | 98echo "startup --output_user_root=C:/tmp" > ./user.bazelrc 99if : startswith(matrix.os, 'Windows') 100- name : Build cargo-bazel binaries 101run : | 102# Build binaries 103if [[ "${RUNNER_OS}" == "Windows" ]]; then 104OUTPUT_PATH="$(cygpath "${{ github.workspace }}/crate_universe/target/artifacts" -m)" 105else 106OUTPUT_PATH="${{ github.workspace }}/crate_universe/target/artifacts" 107fi 108bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/cross_installer -- --target=${TARGET} --output="${OUTPUT_PATH}" 109env : 110TARGET : "${{ matrix.env.TARGET }}" 111- uses : actions/upload-artifact@v3 112with : 113name : "${{ matrix.env.TARGET }}" 114path : ${{ github.workspace }}/crate_universe/target/artifacts/${{ matrix.env.TARGET }} 115if-no-files-found : error 116release : 117needs : builds 118runs-on : ubuntu-20.04 119steps : 120- uses : actions/checkout@v3 121- uses : actions/download-artifact@v3 122with : 123path : ${{ github.workspace }}/crate_universe/target/artifacts 124- name : Detect the current version 125run : | 126version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | grep -o '[[:digit:].]\+')" 127echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV 128- name : Create the rules archive 129run : | 130# Update urls and sha256 values 131bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/urls_generator \ 132-- --artifacts-dir="${ARTIFACTS_DIR}" --url-prefix="${URL_PREFIX}" 133 134bazel clean 135 136# Build an archive of the repo contents. 137# `examples/bzlmod` is included for the BCR presubmit; it must appear before --exclude="examples" 138tar -czf ${{ github.workspace }}/.github/rules_rust.tar.gz \ 139-C ${{ github.workspace }} \ 140--exclude=".git" --exclude=".github" \ 141--exclude="crate_universe/target" \ 142examples/bzlmod \ 143--exclude="examples" \ 144--exclude="extensions" \ 145. 146 147# Save the sha256 checksum of the distro archive to the environment 148sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 149echo "ARCHIVE_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 150env : 151CARGO_BAZEL_GENERATOR_URL : file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 152ARTIFACTS_DIR : ${{ github.workspace }}/crate_universe/target/artifacts 153URL_PREFIX : https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }} 154- name : Create the rules extensions archive for Bindgen 155run : | 156# Build an archive of the repo contents. 157tar -czf ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz \ 158-C ${{ github.workspace }}/extensions/bindgen \ 159--exclude="examples" \ 160. 161 162# Save the sha256 checksum of the distro archive to the environment 163sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 164echo "ARCHIVE_EXT_BINDGEN_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 165- name : Create the rules extensions archive for Prost 166run : | 167# Build an archive of the repo contents. 168tar -czf ${{ github.workspace }}/.github/rules_rust_prost.tar.gz \ 169-C ${{ github.workspace }}/extensions/prost \ 170--exclude="examples" \ 171. 172 173# Save the sha256 checksum of the distro archive to the environment 174sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_prost.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 175echo "ARCHIVE_EXT_PROST_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 176- name : Create the rules extensions archive for Protobuf 177run : | 178# Build an archive of the repo contents. 179tar -czf ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz \ 180-C ${{ github.workspace }}/extensions/protobuf \ 181--exclude="examples" \ 182. 183 184# Save the sha256 checksum of the distro archive to the environment 185sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 186echo "ARCHIVE_EXT_PROTOBUF_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 187- name : Create the rules extensions archive for wasm-bindgen 188run : | 189# Build an archive of the repo contents. 190tar -czf ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz \ 191-C ${{ github.workspace }}/extensions/wasm_bindgen \ 192--exclude="examples" \ 193. 194 195# Save the sha256 checksum of the distro archive to the environment 196sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 197echo "ARCHIVE_EXT_WASM_BINDGEN_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 198# Upload the artifact in case creating a release fails so all artifacts can then be manually recovered. 199- uses : actions/upload-artifact@v3 200with : 201name : "rules_rust.tar.gz" 202path : ${{ github.workspace }}/.github/rules_rust.tar.gz 203if-no-files-found : error 204- uses : actions/upload-artifact@v3 205with : 206name : "rules_rust_bindgen.tar.gz" 207path : ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz 208if-no-files-found : error 209- uses : actions/upload-artifact@v3 210with : 211name : "rules_rust_prost.tar.gz" 212path : ${{ github.workspace }}/.github/rules_rust_prost.tar.gz 213if-no-files-found : error 214- uses : actions/upload-artifact@v3 215with : 216name : "rules_rust_protobuf.tar.gz" 217path : ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz 218if-no-files-found : error 219- uses : actions/upload-artifact@v3 220with : 221name : "rules_rust_wasm_bindgen.tar.gz" 222path : ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz 223if-no-files-found : error 224- name : Generate release notes 225run : | 226# Generate the release notes 227sed 's#{version}#${{ env.RELEASE_VERSION }}#g' ${{ github.workspace }}/.github/release_notes.template \ 228| sed 's#{sha256_base64}#${{ env.ARCHIVE_SHA256_BASE64 }}#g' \ 229| sed 's#{ext_sha256_base64}#${{ env.ARCHIVE_EXT_SHA256_BASE64 }}#g' \ 230> ${{ github.workspace }}/.github/release_notes.txt 231- name : Create release 232uses : softprops/action-gh-release@v1 233id : rules_rust_release 234env : 235GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 236with : 237generate_release_notes : true 238tag_name : ${{ env.RELEASE_VERSION }} 239body_path : ${{ github.workspace }}/.github/release_notes.txt 240target_commitish : ${{ github.base_ref }} 241 242- name : "Upload the rules archive" 243uses : actions/upload-release-asset@v1 244env : 245GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 246with : 247upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 248asset_name : rules_rust-${{ env.RELEASE_VERSION }}.tar.gz 249asset_path : ${{ github.workspace }}/.github/rules_rust.tar.gz 250asset_content_type : application/gzip 251 252- name : "Upload the bindgen extension archive" 253uses : actions/upload-release-asset@v1 254env : 255GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 256with : 257upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 258asset_name : rules_rust_bindgen-${{ env.RELEASE_VERSION }}.tar.gz 259asset_path : ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz 260asset_content_type : application/gzip 261- name : "Upload the prost extension archive" 262uses : actions/upload-release-asset@v1 263env : 264GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 265with : 266upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 267asset_name : rules_rust_prost-${{ env.RELEASE_VERSION }}.tar.gz 268asset_path : ${{ github.workspace }}/.github/rules_rust_prost.tar.gz 269asset_content_type : application/gzip 270- name : "Upload the protobuf extension archive" 271uses : actions/upload-release-asset@v1 272env : 273GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 274with : 275upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 276asset_name : rules_rust_protobuf-${{ env.RELEASE_VERSION }}.tar.gz 277asset_path : ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz 278asset_content_type : application/gzip 279- name : "Upload the wasm_bindgen extension archive" 280uses : actions/upload-release-asset@v1 281env : 282GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 283with : 284upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 285asset_name : rules_rust_wasm_bindgen-${{ env.RELEASE_VERSION }}.tar.gz 286asset_path : ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz 287asset_content_type : application/gzip 288 289# There must be a upload action for each platform triple we create 290- name : "Upload aarch64-apple-darwin" 291uses : actions/upload-release-asset@v1 292env : 293GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 294with : 295upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 296asset_name : cargo-bazel-aarch64-apple-darwin 297asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel 298asset_content_type : application/octet-stream 299- name : "Upload aarch64-pc-windows-msvc" 300uses : actions/upload-release-asset@v1 301env : 302GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 303with : 304upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 305asset_name : cargo-bazel-aarch64-pc-windows-msvc.exe 306asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-pc-windows-msvc/cargo-bazel.exe 307asset_content_type : application/octet-stream 308- name : "Upload aarch64-unknown-linux-gnu" 309uses : actions/upload-release-asset@v1 310env : 311GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 312with : 313upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 314asset_name : cargo-bazel-aarch64-unknown-linux-gnu 315asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel 316asset_content_type : application/octet-stream 317- name : "Upload x86_64-apple-darwin" 318uses : actions/upload-release-asset@v1 319env : 320GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 321with : 322upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 323asset_name : cargo-bazel-x86_64-apple-darwin 324asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel 325asset_content_type : application/octet-stream 326- name : "Upload x86_64-pc-windows-gnu" 327uses : actions/upload-release-asset@v1 328env : 329GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 330with : 331upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 332asset_name : cargo-bazel-x86_64-pc-windows-gnu.exe 333asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe 334asset_content_type : application/octet-stream 335- name : "Upload x86_64-pc-windows-msvc" 336uses : actions/upload-release-asset@v1 337env : 338GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 339with : 340upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 341asset_name : cargo-bazel-x86_64-pc-windows-msvc.exe 342asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe 343asset_content_type : application/octet-stream 344- name : "Upload x86_64-unknown-linux-gnu" 345uses : actions/upload-release-asset@v1 346env : 347GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 348with : 349upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 350asset_name : cargo-bazel-x86_64-unknown-linux-gnu 351asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 352asset_content_type : application/octet-stream 353- name : "Upload x86_64-unknown-linux-musl" 354uses : actions/upload-release-asset@v1 355env : 356GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 357with : 358upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 359asset_name : cargo-bazel-x86_64-unknown-linux-musl 360asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel 361asset_content_type : application/octet-stream