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