fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndrecache the release archive in release actions (#1201)26e01c83

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