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