fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
5eed46d8
main
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-13 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-13 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_15.2.0.app/Contents/Developer/ 92# Set SDK environment variables 93echo "SDKROOT=$(xcrun -sdk macosx13.0 --show-sdk-path)" >> $GITHUB_ENV 94echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx13.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" \ 141--exclude=".github" \ 142--exclude="crate_universe/target" \ 143--exclude="extensions" \ 144examples/bzlmod \ 145--exclude="examples" \ 146. 147 148# Save the sha256 checksum of the distro archive to the environment 149sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 150echo "ARCHIVE_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 151env : 152CARGO_BAZEL_GENERATOR_URL : file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 153ARTIFACTS_DIR : ${{ github.workspace }}/crate_universe/target/artifacts 154URL_PREFIX : https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }} 155- name : Create the rules extensions archive for Bindgen 156run : | 157# Build an archive of the repo contents. 158tar -czf ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz \ 159-C ${{ github.workspace }}/extensions/bindgen \ 160--exclude="examples" \ 161. 162 163# Save the sha256 checksum of the distro archive to the environment 164sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 165echo "ARCHIVE_EXT_BINDGEN_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 166- name : Create the rules extensions archive for Prost 167run : | 168# Build an archive of the repo contents. 169tar -czf ${{ github.workspace }}/.github/rules_rust_prost.tar.gz \ 170-C ${{ github.workspace }}/extensions/prost \ 171--exclude="examples" \ 172. 173 174# Save the sha256 checksum of the distro archive to the environment 175sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_prost.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 176echo "ARCHIVE_EXT_PROST_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 177- name : Create the rules extensions archive for Protobuf 178run : | 179# Build an archive of the repo contents. 180tar -czf ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz \ 181-C ${{ github.workspace }}/extensions/protobuf \ 182--exclude="examples" \ 183. 184 185# Save the sha256 checksum of the distro archive to the environment 186sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 187echo "ARCHIVE_EXT_PROTOBUF_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 188- name : Create the rules extensions archive for wasm-bindgen 189run : | 190# Build an archive of the repo contents. 191tar -czf ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz \ 192-C ${{ github.workspace }}/extensions/wasm_bindgen \ 193--exclude="examples" \ 194. 195 196# Save the sha256 checksum of the distro archive to the environment 197sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 198echo "ARCHIVE_EXT_WASM_BINDGEN_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 199# Upload the artifact in case creating a release fails so all artifacts can then be manually recovered. 200- uses : actions/upload-artifact@v3 201with : 202name : "rules_rust.tar.gz" 203path : ${{ github.workspace }}/.github/rules_rust.tar.gz 204if-no-files-found : error 205- uses : actions/upload-artifact@v3 206with : 207name : "rules_rust_bindgen.tar.gz" 208path : ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz 209if-no-files-found : error 210- uses : actions/upload-artifact@v3 211with : 212name : "rules_rust_prost.tar.gz" 213path : ${{ github.workspace }}/.github/rules_rust_prost.tar.gz 214if-no-files-found : error 215- uses : actions/upload-artifact@v3 216with : 217name : "rules_rust_protobuf.tar.gz" 218path : ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz 219if-no-files-found : error 220- uses : actions/upload-artifact@v3 221with : 222name : "rules_rust_wasm_bindgen.tar.gz" 223path : ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz 224if-no-files-found : error 225- name : Generate release notes 226run : | 227# Generate the release notes 228sed 's#{version}#${{ env.RELEASE_VERSION }}#g' ${{ github.workspace }}/.github/release_notes.template \ 229| sed 's#{sha256_base64}#${{ env.ARCHIVE_SHA256_BASE64 }}#g' \ 230| sed 's#{ext_bindgen_sha256_base64}#${{ env.ARCHIVE_EXT_BINDGEN_SHA256_BASE64 }}#g' \ 231| sed 's#{ext_prost_sha256_base64}#${{ env.ARCHIVE_EXT_PROST_SHA256_BASE64 }}#g' \ 232| sed 's#{ext_protobuf_sha256_base64}#${{ env.ARCHIVE_EXT_PROTOBUF_SHA256_BASE64 }}#g' \ 233| sed 's#{ext_wasm_bindgen_sha256_base64}#${{ env.ARCHIVE_EXT_WASM_BINDGEN_SHA256_BASE64 }}#g' \ 234> ${{ github.workspace }}/.github/release_notes.txt 235- name : Create release 236uses : softprops/action-gh-release@v1 237id : rules_rust_release 238env : 239GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 240with : 241generate_release_notes : true 242tag_name : ${{ env.RELEASE_VERSION }} 243body_path : ${{ github.workspace }}/.github/release_notes.txt 244target_commitish : ${{ github.base_ref }} 245 246- name : "Upload the rules archive" 247uses : actions/upload-release-asset@v1 248env : 249GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 250with : 251upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 252asset_name : rules_rust-${{ env.RELEASE_VERSION }}.tar.gz 253asset_path : ${{ github.workspace }}/.github/rules_rust.tar.gz 254asset_content_type : application/gzip 255 256- name : "Upload the bindgen extension archive" 257uses : actions/upload-release-asset@v1 258env : 259GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 260with : 261upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 262asset_name : rules_rust_bindgen-${{ env.RELEASE_VERSION }}.tar.gz 263asset_path : ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz 264asset_content_type : application/gzip 265- name : "Upload the prost extension archive" 266uses : actions/upload-release-asset@v1 267env : 268GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 269with : 270upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 271asset_name : rules_rust_prost-${{ env.RELEASE_VERSION }}.tar.gz 272asset_path : ${{ github.workspace }}/.github/rules_rust_prost.tar.gz 273asset_content_type : application/gzip 274- name : "Upload the protobuf extension archive" 275uses : actions/upload-release-asset@v1 276env : 277GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 278with : 279upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 280asset_name : rules_rust_protobuf-${{ env.RELEASE_VERSION }}.tar.gz 281asset_path : ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz 282asset_content_type : application/gzip 283- name : "Upload the wasm_bindgen extension archive" 284uses : actions/upload-release-asset@v1 285env : 286GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 287with : 288upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 289asset_name : rules_rust_wasm_bindgen-${{ env.RELEASE_VERSION }}.tar.gz 290asset_path : ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz 291asset_content_type : application/gzip 292 293# There must be a upload action for each platform triple we create 294- name : "Upload aarch64-apple-darwin" 295uses : actions/upload-release-asset@v1 296env : 297GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 298with : 299upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 300asset_name : cargo-bazel-aarch64-apple-darwin 301asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel 302asset_content_type : application/octet-stream 303- name : "Upload aarch64-pc-windows-msvc" 304uses : actions/upload-release-asset@v1 305env : 306GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 307with : 308upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 309asset_name : cargo-bazel-aarch64-pc-windows-msvc.exe 310asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-pc-windows-msvc/cargo-bazel.exe 311asset_content_type : application/octet-stream 312- name : "Upload aarch64-unknown-linux-gnu" 313uses : actions/upload-release-asset@v1 314env : 315GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 316with : 317upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 318asset_name : cargo-bazel-aarch64-unknown-linux-gnu 319asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel 320asset_content_type : application/octet-stream 321- name : "Upload x86_64-apple-darwin" 322uses : actions/upload-release-asset@v1 323env : 324GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 325with : 326upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 327asset_name : cargo-bazel-x86_64-apple-darwin 328asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel 329asset_content_type : application/octet-stream 330- name : "Upload x86_64-pc-windows-gnu" 331uses : actions/upload-release-asset@v1 332env : 333GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 334with : 335upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 336asset_name : cargo-bazel-x86_64-pc-windows-gnu.exe 337asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe 338asset_content_type : application/octet-stream 339- name : "Upload x86_64-pc-windows-msvc" 340uses : actions/upload-release-asset@v1 341env : 342GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 343with : 344upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 345asset_name : cargo-bazel-x86_64-pc-windows-msvc.exe 346asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe 347asset_content_type : application/octet-stream 348- name : "Upload x86_64-unknown-linux-gnu" 349uses : actions/upload-release-asset@v1 350env : 351GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 352with : 353upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 354asset_name : cargo-bazel-x86_64-unknown-linux-gnu 355asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 356asset_content_type : application/octet-stream 357- name : "Upload x86_64-unknown-linux-musl" 358uses : actions/upload-release-asset@v1 359env : 360GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 361with : 362upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 363asset_name : cargo-bazel-x86_64-unknown-linux-musl 364asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel 365asset_content_type : application/octet-stream