From efbb66d056d3356194e9f94e412dbe11fef3a70c Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Fri, 11 Mar 2022 07:01:39 -0800 Subject: [PATCH 1/2] Added release workflow --- .github/.gitignore | 2 + .github/github.bazelrc | 20 +++ .github/release_notes.template | 15 ++ .github/version.bzl.template | 8 - .github/workflows/release.yaml | 216 ++++++++++++++++++++++++++ .github/workflows/release_begin.yaml | 197 ----------------------- .github/workflows/release_finish.yaml | 122 --------------- version.bzl | 3 + 8 files changed, 256 insertions(+), 327 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/github.bazelrc create mode 100644 .github/release_notes.template delete mode 100644 .github/version.bzl.template create mode 100644 .github/workflows/release.yaml delete mode 100644 .github/workflows/release_begin.yaml delete mode 100644 .github/workflows/release_finish.yaml create mode 100644 version.bzl diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000000..cf7de92acb --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1,2 @@ +release_notes.txt +rules_rust*.tar.gz diff --git a/.github/github.bazelrc b/.github/github.bazelrc new file mode 100644 index 0000000000..74fb55425b --- /dev/null +++ b/.github/github.bazelrc @@ -0,0 +1,20 @@ +# Bazel settings for use in Github CI + +# Always display the flags being used +common --announce_rc + +# These settings make the windows workers behave similarly to unix workers +startup --windows_enable_symlinks +build --enable_runfiles + +# Show errors in CI +test --test_output=errors + +# Show more information about failures +build --verbose_failures + +# UI for cleaner CI output +common --color=no +common --curses=no +common --show_task_finish +common --show_timestamps diff --git a/.github/release_notes.template b/.github/release_notes.template new file mode 100644 index 0000000000..26c3b67343 --- /dev/null +++ b/.github/release_notes.template @@ -0,0 +1,15 @@ +# {version} + +```python +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "rules_rust", + sha256 = "{sha256}", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_rust/releases/download/{version}/rules_rust-v{version}.tar.gz", + "https://github.com/bazelbuild/rules_rust/releases/download/{version}/rules_rust-v{version}.tar.gz", + ], +) +``` + +Additional documentation can be found at: https://bazelbuild.github.io/rules_rust/#setup diff --git a/.github/version.bzl.template b/.github/version.bzl.template deleted file mode 100644 index b3591a8b9c..0000000000 --- a/.github/version.bzl.template +++ /dev/null @@ -1,8 +0,0 @@ -"""The version of rules_rust. - -Note: Any change to this file will trigger a new release. To make changes here, -edit `./.github/version.bzl.template` instead and run the `Release` action to -create a new release with an updated `./version.bzl` file. -""" - -VERSION = "{VERSION}" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..e36eb0504e --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,216 @@ +--- +name: Release +on: + workflow_dispatch: + inputs: + version: + description: "The new version to release. E.g. `1.2.3`" + required: true + +defaults: + run: + shell: bash + +env: + BAZEL_STARTUP_FLAGS: --bazelrc=${{ github.workspace }}/.github/github.bazelrc + +jobs: + validation: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: main + - name: Detect the current version + run: | + version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')" + if [[ "${version}" != "${{ github.event.inputs.version }}" ]]; then + echo "Release versions don't match: ${version} != ${{ github.event.inputs.version }}" >&2 + exit 1 + fi + builds: + needs: validation + runs-on: ${{ matrix.os }} + strategy: + matrix: + # Create a job for each target triple + include: + - os: macos-11 + env: + TARGET: "aarch64-apple-darwin" + - os: ubuntu-20.04 + env: + TARGET: "aarch64-unknown-linux-gnu" + - os: macos-11 + env: + TARGET: "x86_64-apple-darwin" + - os: ubuntu-20.04 + env: + TARGET: "x86_64-pc-windows-gnu" + - os: windows-2019 + env: + TARGET: "x86_64-pc-windows-msvc" + - os: ubuntu-20.04 + env: + TARGET: "x86_64-unknown-linux-gnu" + - os: ubuntu-20.04 + env: + TARGET: "x86_64-unknown-linux-musl" + steps: + - uses: actions/checkout@v2 + with: + ref: "${{ github.base_ref }}" + - name: Install rust toolchains for host + run: | + # Detect the current version of rust + version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | sed 's/DEFAULT_RUST_VERSION = "//' | sed 's/"//')" + rustup override set "${version}" + rustup update stable && rustup default stable + - name: Setup macos build tooling + run: | + sudo xcode-select -s /Applications/Xcode_12.4.app/Contents/Developer/ + # Set SDK environment variables + echo "SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path)" >> $GITHUB_ENV + echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version)" >> $GITHUB_ENV + if: startswith(matrix.os, 'macos') + - name: Setup Windows Bazelrc + run: | + echo "startup --output_user_root=C:/tmp" > ./user.bazelrc + if: startswith(matrix.os, 'Windows') + - name: Build cargo-bazel binaries + run: | + # Build binaries + if [[ "${RUNNER_OS}" == "Windows" ]]; then + OUTPUT_PATH="$(cygpath "${{ github.workspace }}/crate_universe/target/artifacts" -m)" + else + OUTPUT_PATH="${{ github.workspace }}/crate_universe/target/artifacts" + fi + bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/cross_installer -- --target=${TARGET} --output="${OUTPUT_PATH}" + env: + TARGET: "${{ matrix.env.TARGET }}" + - uses: actions/upload-artifact@v2 + with: + name: "${{ matrix.env.TARGET }}" + path: ${{ github.workspace }}/crate_universe/target/artifacts/${{ matrix.env.TARGET }} + if-no-files-found: error + release: + needs: builds + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: main + - uses: actions/download-artifact@v2 + with: + path: ${{ github.workspace }}/crate_universe/target/artifacts + - name: Detect the current version + run: | + version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')" + if [[ "${version}" != "${{ github.event.inputs.version }}" ]]; then + echo "Release versions don't match: ${version} != ${{ github.event.inputs.version }}" >&2 + exit 1 + fi + - name: Create the rules archive + run: | + # Update urls and sha256 values + bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/urls_generator -- --artifacts-dir="${ARTIFACTS_DIR}" --url-prefix="${URL_PREFIX}" + # Publish to a known location + bazel ${BAZEL_STARTUP_FLAGS[@]} run //distro:publish -- ${{ github.workspace }}/.github + # Save the sha256 checksum of the distro archive to the environment + sha256="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }')" + echo "ARCHIVE_SHA256=${sha256}" >> $GITHUB_ENV + env: + CARGO_BAZEL_GENERATOR_URL: file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel + ARTIFACTS_DIR: ${{ github.workspace }}/crate_universe/target/artifacts + URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{github.event.inputs.version}} + - name: Generate release notes + run: | + # Generate the release notes + sed 's/{version}/${{ github.event.inputs.version }}/g' ${{ github.workspace }}/.github/release_notes.template \ + | sed 's/{sha256}/${{env.ARCHIVE_SHA256}}/g' \ + > ${{ github.workspace }}/.github/release_notes.txt + - name: Create release + uses: softprops/action-gh-release@v1 + id: rules_rust_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + generate_release_notes: true + tag_name: ${{github.event.inputs.version}} + body_path: ${{ github.workspace }}/.github/release_notes.txt + target_commitish: ${{ github.base_ref }} + + - name: "Upload the rules archive" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: rules_rust-v${{ github.event.inputs.version }}.tar.gz + asset_path: ${{ github.workspace }}/.github/rules_rust.tar.gz + asset_content_type: application/gzip + + # There must be a upload action for each platform triple we create + - name: "Upload aarch64-apple-darwin" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: cargo-bazel-aarch64-apple-darwin + asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel + asset_content_type: application/octet-stream + - name: "Upload aarch64-unknown-linux-gnu" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: cargo-bazel-aarch64-unknown-linux-gnu + asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel + asset_content_type: application/octet-stream + - name: "Upload x86_64-apple-darwin" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: cargo-bazel-x86_64-apple-darwin + asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel + asset_content_type: application/octet-stream + - name: "Upload x86_64-pc-windows-gnu" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: cargo-bazel-x86_64-pc-windows-gnu.exe + asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe + asset_content_type: application/octet-stream + - name: "Upload x86_64-pc-windows-msvc" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: cargo-bazel-x86_64-pc-windows-msvc.exe + asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe + asset_content_type: application/octet-stream + - name: "Upload x86_64-unknown-linux-gnu" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: cargo-bazel-x86_64-unknown-linux-gnu + asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel + asset_content_type: application/octet-stream + - name: "Upload x86_64-unknown-linux-musl" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} + asset_name: cargo-bazel-x86_64-unknown-linux-musl + asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel + asset_content_type: application/octet-stream diff --git a/.github/workflows/release_begin.yaml b/.github/workflows/release_begin.yaml deleted file mode 100644 index 6313efa4ce..0000000000 --- a/.github/workflows/release_begin.yaml +++ /dev/null @@ -1,197 +0,0 @@ ---- -name: Release -on: - workflow_dispatch: - inputs: - version: - description: "The new version to release" - required: true - -defaults: - run: - shell: bash - -jobs: - crate_universe_builds: - if: ${{ github.repository_owner == 'bazelbuild' }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - # Create a job for each target triple - include: - - os: macos-10.15 - env: - TARGET: "aarch64-apple-darwin" - EXTENSION: "" - - os: ubuntu-20.04 - env: - TARGET: "aarch64-unknown-linux-gnu" - EXTENSION: "" - - os: macos-10.15 - env: - TARGET: "x86_64-apple-darwin" - EXTENSION: "" - - os: ubuntu-20.04 - env: - TARGET: "x86_64-pc-windows-gnu" - EXTENSION: ".exe" - - os: ubuntu-20.04 - env: - TARGET: "x86_64-unknown-linux-gnu" - EXTENSION: "" - steps: - - uses: actions/checkout@v2 - with: - ref: "${{ github.base_ref }}" - - run: | - # Install cross - if [[ "${RUNNER_OS}" == "macOS" ]]; then - curl --fail -Lo ~/cross.tar.gz https://github.com/rust-embedded/cross/releases/download/v0.2.1/cross-v0.2.1-x86_64-apple-darwin.tar.gz - else - curl --fail -Lo ~/cross.tar.gz https://github.com/rust-embedded/cross/releases/download/v0.2.1/cross-v0.2.1-x86_64-unknown-linux-gnu.tar.gz - fi - sudo tar -xf ~/cross.tar.gz -C /usr/local/bin/ - sudo chmod +x /usr/local/bin/cross - if: matrix.os != 'windows-2019' - - run: | - # Install rust toolchains for host - - # Detect the current version of rust - version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | sed 's/DEFAULT_RUST_VERSION = "//' | sed 's/"//')" - - rustup override set "${version}" - rustup update stable && rustup default stable - - run: | - # Setup macos build tooling - sudo xcode-select -s /Applications/Xcode_12.4.app/Contents/Developer/ - - # Set SDK environment variables - echo "SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path)" >> $GITHUB_ENV - echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version)" >> $GITHUB_ENV - if: matrix.os == 'macOS-10.15' - - run: | - # Build binaries - ./crate_universe/private/bootstrap/build.sh - env: - TARGET: "${{ matrix.env.TARGET }}" - - uses: actions/upload-artifact@v2 - with: - name: "${{ matrix.env.TARGET }}" - path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/${{ matrix.env.TARGET }} - if-no-files-found: error - release: - if: ${{ github.repository_owner == 'bazelbuild' }} - needs: crate_universe_builds - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: main - - run: | - # Write new releases file - cat ${{ github.workspace }}/.github/version.bzl.template \ - | sed 's/{VERSION}/${{ github.event.inputs.version }}/' \ - > ${{ github.workspace }}/version.bzl - - run: | - # Get release candidate number - git fetch origin &> /dev/null - num_tags="$(git tag -l | grep "${{ github.event.inputs.version }}" | wc -l | xargs || true)" - echo "RELEASE_CANDIDATE_NUMBER=$( echo "${num_tags}" | python3 -c 'import sys; print(int(sys.stdin.read().strip()) + 1)')" >> $GITHUB_ENV - - uses: actions/download-artifact@v2 - with: - path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin - - run: | - # Write new crate_universe defaults.bzl file - # Copy the new template - cp ${{ github.workspace }}/crate_universe/private/defaults.bzl.template ${{ github.workspace }}/crate_universe/private/defaults.bzl - - # Generate the release URL - url="${URL_PREFIX}/crate_universe_resolver-{host_triple}{extension}" - sed -i "s|{DEFAULT_URL_TEMPLATE}|${url}|" ${{ github.workspace }}/crate_universe/private/defaults.bzl - sed -i "s|{rc}|${RELEASE_CANDIDATE_NUMBER}|" ${{ github.workspace }}/crate_universe/private/defaults.bzl - - # Populate all sha256 values - TARGETS=( - aarch64-apple-darwin - aarch64-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-gnu - x86_64-unknown-linux-gnu - ) - for triple in ${TARGETS[@]}; do - if [[ "${triple}" == *"windows"* ]]; then - bin_name=crate_universe_resolver.exe - else - bin_name=crate_universe_resolver - fi - sha256="$(shasum --algorithm 256 ${{ github.workspace }}/crate_universe/private/bootstrap/bin/${triple}/release/${bin_name} | awk '{ print $1 }')" - sed -i "s|{${triple}--sha256}|${sha256}|" ${{ github.workspace }}/crate_universe/private/defaults.bzl - done - env: - URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ github.event.inputs.version }} - - run: | - # Update docs for release - SKIP_COMMIT=1 ${{ github.workspace }}/docs/update_docs.sh - - uses: actions/create-release@v1 - id: rules_rust_release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - prerelease: true - tag_name: ${{ github.event.inputs.version }}rc-${{ env.RELEASE_CANDIDATE_NUMBER }} - release_name: ${{ github.event.inputs.version }}rc-${{ env.RELEASE_CANDIDATE_NUMBER }} - body: ${{ github.event.inputs.version }}rc-${{ env.RELEASE_CANDIDATE_NUMBER }} - commitish: main - # There must be a upload action for each platform triple we create - - name: "Upload aarch64-apple-darwin" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-aarch64-apple-darwin - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/aarch64-apple-darwin/release/crate_universe_resolver - asset_content_type: application/octet-stream - - name: "Upload aarch64-unknown-linux-gnu" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-aarch64-unknown-linux-gnu - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/aarch64-unknown-linux-gnu/release/crate_universe_resolver - asset_content_type: application/octet-stream - - name: "Upload x86_64-apple-darwin" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-x86_64-apple-darwin - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/x86_64-apple-darwin/release/crate_universe_resolver - asset_content_type: application/octet-stream - - name: "Upload x86_64-pc-windows-gnu" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-x86_64-pc-windows-gnu.exe - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/x86_64-pc-windows-gnu/release/crate_universe_resolver.exe - asset_content_type: application/octet-stream - - name: "Upload x86_64-unknown-linux-gnu" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-x86_64-unknown-linux-gnu - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/x86_64-unknown-linux-gnu/release/crate_universe_resolver - asset_content_type: application/octet-stream - - uses: peter-evans/create-pull-request@v3 - with: - title: Release ${{ github.event.inputs.version }} - commit-message: release ${{ github.event.inputs.version }} - branch: release/${{ github.event.inputs.version }} - delete-branch: true - body: Release ${{ github.event.inputs.version }} diff --git a/.github/workflows/release_finish.yaml b/.github/workflows/release_finish.yaml deleted file mode 100644 index 116422ed34..0000000000 --- a/.github/workflows/release_finish.yaml +++ /dev/null @@ -1,122 +0,0 @@ ---- -name: Release Finalize -on: - push: - branches: - - main - paths: - # Only trigger for new releases - - "version.bzl" - -defaults: - run: - shell: bash - -jobs: - release: - if: ${{ github.repository_owner == 'bazelbuild' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: | - # Get current release version - git fetch origin &> /dev/null - RELEASE_VERSION=$(cat version.bzl | grep VERSION | sed 's/VERSION = "//' | sed 's/"//') - echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV - - # Get release candidate number - echo "RELEASE_CANDIDATE_NUMBER=$(git tag -l | grep "${RELEASE_VERSION}" | wc -l | xargs || true)" >> $GITHUB_ENV - - run: | - # Ensure there is at least 1 release candidate in the environment - if [[ -z "${RELEASE_CANDIDATE_NUMBER}" ]]; then - exit 1 - elif [[ "${RELEASE_CANDIDATE_NUMBER}" -eq "0" ]]; then - exit 1 - fi - - run: | - # Download all artifacts from the release candidate - TARGETS=( - aarch64-apple-darwin - aarch64-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-gnu - x86_64-unknown-linux-gnu - ) - - for triple in ${TARGETS[@]}; do - if [[ "${triple}" == *"windows"* ]]; then - ext=".exe" - else - ext="" - fi - resolver="${ARTIFACT_DIR}/${triple}/release/crate_universe_resolver${ext}" - mkdir -p "$(dirname "${resolver}")" - url="${ARTIFACT_URL}/crate_universe_resolver-${triple}${ext}" - echo "Downloading '${url}' to '${resolver}'" - curl --fail -Lo "${resolver}" "${url}" - sha256="$(shasum --algorithm 256 "${resolver}" | awk '{ print $1 }')" - - if [[ -z "$(grep "\"${triple}\": \"${sha256}\"" ${{ github.workspace }}/crate_universe/private/defaults.bzl)" ]]; then - echo "Unexpected sha256 value from `${url}`: got ${sha256}, expected value in `defaults.bzl`" - exit 1 - fi - done - env: - ARTIFACT_URL: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{env.RELEASE_VERSION}}rc-${{ env.RELEASE_CANDIDATE_NUMBER }} - ARTIFACT_DIR: ${{ github.workspace }}/crate_universe/private/bootstrap/bin - - uses: actions/create-release@v1 - id: rules_rust_release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - prerelease: true - tag_name: ${{env.RELEASE_VERSION}} - release_name: ${{env.RELEASE_VERSION}} - body: ${{env.RELEASE_VERSION}} - commitish: ${{ github.base_ref }} - # There must be a upload action for each platform triple we create - - name: "Upload aarch64-apple-darwin" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-aarch64-apple-darwin - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/aarch64-apple-darwin/release/crate_universe_resolver - asset_content_type: application/octet-stream - - name: "Upload aarch64-unknown-linux-gnu" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-aarch64-unknown-linux-gnu - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/aarch64-unknown-linux-gnu/release/crate_universe_resolver - asset_content_type: application/octet-stream - - name: "Upload x86_64-apple-darwin" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-x86_64-apple-darwin - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/x86_64-apple-darwin/release/crate_universe_resolver - asset_content_type: application/octet-stream - - name: "Upload x86_64-pc-windows-gnu" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-x86_64-pc-windows-gnu.exe - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/x86_64-pc-windows-gnu/release/crate_universe_resolver.exe - asset_content_type: application/octet-stream - - name: "Upload x86_64-unknown-linux-gnu" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: crate_universe_resolver-x86_64-unknown-linux-gnu - asset_path: ${{ github.workspace }}/crate_universe/private/bootstrap/bin/x86_64-unknown-linux-gnu/release/crate_universe_resolver - asset_content_type: application/octet-stream diff --git a/version.bzl b/version.bzl new file mode 100644 index 0000000000..0b27154a96 --- /dev/null +++ b/version.bzl @@ -0,0 +1,3 @@ +"""The version of rules_rust.""" + +VERSION = "0.0.7" From 5ae76cb6225a722fd55b318fe9119ef42d7b0c03 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 15 Mar 2022 07:51:09 -0700 Subject: [PATCH 2/2] Addressed PR feedback --- .github/workflows/release.yaml | 54 ++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e36eb0504e..1c9493517e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,10 +2,6 @@ name: Release on: workflow_dispatch: - inputs: - version: - description: "The new version to release. E.g. `1.2.3`" - required: true defaults: run: @@ -16,17 +12,30 @@ env: jobs: validation: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - with: - ref: main - - name: Detect the current version + # TODO: Unfortunately it's not obvious how to restrict `workflow_dispatch` to a particular branch + # so this step ensures releases are always done off of `main`. + - name: Ensure branch is 'main' + run: | + git fetch origin &> /dev/null + branch="$(git rev-parse --abbrev-ref HEAD)" + if [[ "${branch}" != "main" ]]; then + echo "The release branch must be main. Got '${branch}'' instead." >&2 + exit 1 + else + echo "Branch is '${branch}'" + fi + - name: Ensure release does not already exist run: | + git fetch origin &> /dev/null version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')" - if [[ "${version}" != "${{ github.event.inputs.version }}" ]]; then - echo "Release versions don't match: ${version} != ${{ github.event.inputs.version }}" >&2 + if [[ -n "$(git tag -l ${version})" ]]; then + echo "A release '${version}' already exists." >&2 exit 1 + else + echo "Tag '${version}' will be created" fi builds: needs: validation @@ -58,12 +67,10 @@ jobs: TARGET: "x86_64-unknown-linux-musl" steps: - uses: actions/checkout@v2 - with: - ref: "${{ github.base_ref }}" - name: Install rust toolchains for host run: | # Detect the current version of rust - version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | sed 's/DEFAULT_RUST_VERSION = "//' | sed 's/"//')" + version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | grep -o '[[:digit:].]\+')" rustup override set "${version}" rustup update stable && rustup default stable - name: Setup macos build tooling @@ -95,21 +102,16 @@ jobs: if-no-files-found: error release: needs: builds - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - with: - ref: main - uses: actions/download-artifact@v2 with: path: ${{ github.workspace }}/crate_universe/target/artifacts - name: Detect the current version run: | - version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')" - if [[ "${version}" != "${{ github.event.inputs.version }}" ]]; then - echo "Release versions don't match: ${version} != ${{ github.event.inputs.version }}" >&2 - exit 1 - fi + version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | grep -o '[[:digit:].]\+')" + echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV - name: Create the rules archive run: | # Update urls and sha256 values @@ -122,12 +124,12 @@ jobs: env: CARGO_BAZEL_GENERATOR_URL: file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel ARTIFACTS_DIR: ${{ github.workspace }}/crate_universe/target/artifacts - URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{github.event.inputs.version}} + URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }} - name: Generate release notes run: | # Generate the release notes - sed 's/{version}/${{ github.event.inputs.version }}/g' ${{ github.workspace }}/.github/release_notes.template \ - | sed 's/{sha256}/${{env.ARCHIVE_SHA256}}/g' \ + sed 's/{version}/${{ env.RELEASE_VERSION }}/g' ${{ github.workspace }}/.github/release_notes.template \ + | sed 's/{sha256}/${{ env.ARCHIVE_SHA256 }}/g' \ > ${{ github.workspace }}/.github/release_notes.txt - name: Create release uses: softprops/action-gh-release@v1 @@ -136,7 +138,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: generate_release_notes: true - tag_name: ${{github.event.inputs.version}} + tag_name: ${{ env.RELEASE_VERSION }} body_path: ${{ github.workspace }}/.github/release_notes.txt target_commitish: ${{ github.base_ref }} @@ -146,7 +148,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.rules_rust_release.outputs.upload_url }} - asset_name: rules_rust-v${{ github.event.inputs.version }}.tar.gz + asset_name: rules_rust-v${{ env.RELEASE_VERSION }}.tar.gz asset_path: ${{ github.workspace }}/.github/rules_rust.tar.gz asset_content_type: application/gzip