fork/rules_rust

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

UebelAndreImplement rules archive release artifact in github action. (#1501)76360dd3

0.11.0
9.9 KiB225 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          bazel clean
120          # Build an archive of the repo contents
121          tar -czf ${{ github.workspace }}/.github/rules_rust.tar.gz --exclude=".git" --exclude=".github" --exclude="examples" -C ${{ github.workspace }} .
122          # Save the sha256 checksum of the distro archive to the environment
123          sha256="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }')"
124          echo "ARCHIVE_SHA256=${sha256}" >> $GITHUB_ENV
125        env:
126          CARGO_BAZEL_GENERATOR_URL: file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
127          ARTIFACTS_DIR: ${{ github.workspace }}/crate_universe/target/artifacts
128          URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }}
129      # Upload the artifact in case creating a release fails so all artifacts can then be manually recovered.
130      - uses: actions/upload-artifact@v2
131        with:
132          name: "rules_rust.tar.gz"
133          path: ${{ github.workspace }}/.github/rules_rust.tar.gz
134          if-no-files-found: error
135      - name: Generate release notes
136        run: |
137          # Generate the release notes
138          sed 's/{version}/${{ env.RELEASE_VERSION }}/g' ${{ github.workspace }}/.github/release_notes.template \
139          | sed 's/{sha256}/${{ env.ARCHIVE_SHA256 }}/g' \
140          > ${{ github.workspace }}/.github/release_notes.txt
141      - name: Create release
142        uses: softprops/action-gh-release@v1
143        id: rules_rust_release
144        env:
145          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146        with:
147          generate_release_notes: true
148          tag_name: ${{ env.RELEASE_VERSION }}
149          body_path: ${{ github.workspace }}/.github/release_notes.txt
150          target_commitish: ${{ github.base_ref }}
151
152      - name: "Upload the rules archive"
153        uses: actions/upload-release-asset@v1
154        env:
155          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156        with:
157          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
158          asset_name: rules_rust-v${{ env.RELEASE_VERSION }}.tar.gz
159          asset_path: ${{ github.workspace }}/.github/rules_rust.tar.gz
160          asset_content_type: application/gzip
161
162      # There must be a upload action for each platform triple we create
163      - name: "Upload aarch64-apple-darwin"
164        uses: actions/upload-release-asset@v1
165        env:
166          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
167        with:
168          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
169          asset_name: cargo-bazel-aarch64-apple-darwin
170          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel
171          asset_content_type: application/octet-stream
172      - name: "Upload aarch64-unknown-linux-gnu"
173        uses: actions/upload-release-asset@v1
174        env:
175          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176        with:
177          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
178          asset_name: cargo-bazel-aarch64-unknown-linux-gnu
179          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel
180          asset_content_type: application/octet-stream
181      - name: "Upload x86_64-apple-darwin"
182        uses: actions/upload-release-asset@v1
183        env:
184          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185        with:
186          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
187          asset_name: cargo-bazel-x86_64-apple-darwin
188          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel
189          asset_content_type: application/octet-stream
190      - name: "Upload x86_64-pc-windows-gnu"
191        uses: actions/upload-release-asset@v1
192        env:
193          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
194        with:
195          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
196          asset_name: cargo-bazel-x86_64-pc-windows-gnu.exe
197          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe
198          asset_content_type: application/octet-stream
199      - name: "Upload x86_64-pc-windows-msvc"
200        uses: actions/upload-release-asset@v1
201        env:
202          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
203        with:
204          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
205          asset_name: cargo-bazel-x86_64-pc-windows-msvc.exe
206          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe
207          asset_content_type: application/octet-stream
208      - name: "Upload x86_64-unknown-linux-gnu"
209        uses: actions/upload-release-asset@v1
210        env:
211          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
212        with:
213          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
214          asset_name: cargo-bazel-x86_64-unknown-linux-gnu
215          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
216          asset_content_type: application/octet-stream
217      - name: "Upload x86_64-unknown-linux-musl"
218        uses: actions/upload-release-asset@v1
219        env:
220          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
221        with:
222          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
223          asset_name: cargo-bazel-x86_64-unknown-linux-musl
224          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel
225          asset_content_type: application/octet-stream