fork/rules_rust

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

UebelAndreMoved rust extension rules into a separate `rules_rust_ext` workspace. (#3007)2bad96d9

cleanup
16.1 KiB361 linesraw
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 \
132            -- --artifacts-dir="${ARTIFACTS_DIR}" --url-prefix="${URL_PREFIX}"
133
134          bazel clean
135
136          # Build an archive of the repo contents.
137          # `examples/bzlmod` is included for the BCR presubmit; it must appear before --exclude="examples"
138          tar -czf ${{ github.workspace }}/.github/rules_rust.tar.gz \
139            -C ${{ github.workspace }} \
140            --exclude=".git" --exclude=".github" \
141            --exclude="crate_universe/target" \
142            examples/bzlmod \
143            --exclude="examples" \
144            --exclude="extensions" \
145            .
146
147          # Save the sha256 checksum of the distro archive to the environment
148          sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)"
149          echo "ARCHIVE_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV
150        env:
151          CARGO_BAZEL_GENERATOR_URL: file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
152          ARTIFACTS_DIR: ${{ github.workspace }}/crate_universe/target/artifacts
153          URL_PREFIX: https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }}
154      - name: Create the rules extensions archive for Bindgen
155        run: |
156          # Build an archive of the repo contents.
157          tar -czf ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz \
158            -C ${{ github.workspace }}/extensions/bindgen \
159            --exclude="examples" \
160            .
161
162          # Save the sha256 checksum of the distro archive to the environment
163          sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)"
164          echo "ARCHIVE_EXT_BINDGEN_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV
165      - name: Create the rules extensions archive for Prost
166        run: |
167          # Build an archive of the repo contents.
168          tar -czf ${{ github.workspace }}/.github/rules_rust_prost.tar.gz \
169            -C ${{ github.workspace }}/extensions/prost \
170            --exclude="examples" \
171            .
172
173          # Save the sha256 checksum of the distro archive to the environment
174          sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_prost.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)"
175          echo "ARCHIVE_EXT_PROST_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV
176      - name: Create the rules extensions archive for Protobuf
177        run: |
178          # Build an archive of the repo contents.
179          tar -czf ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz \
180            -C ${{ github.workspace }}/extensions/protobuf \
181            --exclude="examples" \
182            .
183
184          # Save the sha256 checksum of the distro archive to the environment
185          sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)"
186          echo "ARCHIVE_EXT_PROTOBUF_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV
187      - name: Create the rules extensions archive for wasm-bindgen
188        run: |
189          # Build an archive of the repo contents.
190          tar -czf ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz \
191            -C ${{ github.workspace }}/extensions/wasm_bindgen \
192            --exclude="examples" \
193            .
194
195          # Save the sha256 checksum of the distro archive to the environment
196          sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)"
197          echo "ARCHIVE_EXT_WASM_BINDGEN_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV
198      # Upload the artifact in case creating a release fails so all artifacts can then be manually recovered.
199      - uses: actions/upload-artifact@v3
200        with:
201          name: "rules_rust.tar.gz"
202          path: ${{ github.workspace }}/.github/rules_rust.tar.gz
203          if-no-files-found: error
204      - uses: actions/upload-artifact@v3
205        with:
206          name: "rules_rust_bindgen.tar.gz"
207          path: ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz
208          if-no-files-found: error
209      - uses: actions/upload-artifact@v3
210        with:
211          name: "rules_rust_prost.tar.gz"
212          path: ${{ github.workspace }}/.github/rules_rust_prost.tar.gz
213          if-no-files-found: error
214      - uses: actions/upload-artifact@v3
215        with:
216          name: "rules_rust_protobuf.tar.gz"
217          path: ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz
218          if-no-files-found: error
219      - uses: actions/upload-artifact@v3
220        with:
221          name: "rules_rust_wasm_bindgen.tar.gz"
222          path: ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz
223          if-no-files-found: error
224      - name: Generate release notes
225        run: |
226          # Generate the release notes
227          sed 's#{version}#${{ env.RELEASE_VERSION }}#g' ${{ github.workspace }}/.github/release_notes.template \
228          | sed 's#{sha256_base64}#${{ env.ARCHIVE_SHA256_BASE64 }}#g' \
229          | sed 's#{ext_sha256_base64}#${{ env.ARCHIVE_EXT_SHA256_BASE64 }}#g' \
230          > ${{ github.workspace }}/.github/release_notes.txt
231      - name: Create release
232        uses: softprops/action-gh-release@v1
233        id: rules_rust_release
234        env:
235          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
236        with:
237          generate_release_notes: true
238          tag_name: ${{ env.RELEASE_VERSION }}
239          body_path: ${{ github.workspace }}/.github/release_notes.txt
240          target_commitish: ${{ github.base_ref }}
241
242      - name: "Upload the rules archive"
243        uses: actions/upload-release-asset@v1
244        env:
245          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
246        with:
247          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
248          asset_name: rules_rust-${{ env.RELEASE_VERSION }}.tar.gz
249          asset_path: ${{ github.workspace }}/.github/rules_rust.tar.gz
250          asset_content_type: application/gzip
251
252      - name: "Upload the bindgen extension archive"
253        uses: actions/upload-release-asset@v1
254        env:
255          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
256        with:
257          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
258          asset_name: rules_rust_bindgen-${{ env.RELEASE_VERSION }}.tar.gz
259          asset_path: ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz
260          asset_content_type: application/gzip
261      - name: "Upload the prost extension archive"
262        uses: actions/upload-release-asset@v1
263        env:
264          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
265        with:
266          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
267          asset_name: rules_rust_prost-${{ env.RELEASE_VERSION }}.tar.gz
268          asset_path: ${{ github.workspace }}/.github/rules_rust_prost.tar.gz
269          asset_content_type: application/gzip
270      - name: "Upload the protobuf extension archive"
271        uses: actions/upload-release-asset@v1
272        env:
273          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
274        with:
275          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
276          asset_name: rules_rust_protobuf-${{ env.RELEASE_VERSION }}.tar.gz
277          asset_path: ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz
278          asset_content_type: application/gzip
279      - name: "Upload the wasm_bindgen extension archive"
280        uses: actions/upload-release-asset@v1
281        env:
282          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
283        with:
284          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
285          asset_name: rules_rust_wasm_bindgen-${{ env.RELEASE_VERSION }}.tar.gz
286          asset_path: ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz
287          asset_content_type: application/gzip
288
289      # There must be a upload action for each platform triple we create
290      - name: "Upload aarch64-apple-darwin"
291        uses: actions/upload-release-asset@v1
292        env:
293          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
294        with:
295          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
296          asset_name: cargo-bazel-aarch64-apple-darwin
297          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel
298          asset_content_type: application/octet-stream
299      - name: "Upload aarch64-pc-windows-msvc"
300        uses: actions/upload-release-asset@v1
301        env:
302          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
303        with:
304          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
305          asset_name: cargo-bazel-aarch64-pc-windows-msvc.exe
306          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-pc-windows-msvc/cargo-bazel.exe
307          asset_content_type: application/octet-stream
308      - name: "Upload aarch64-unknown-linux-gnu"
309        uses: actions/upload-release-asset@v1
310        env:
311          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
312        with:
313          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
314          asset_name: cargo-bazel-aarch64-unknown-linux-gnu
315          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel
316          asset_content_type: application/octet-stream
317      - name: "Upload x86_64-apple-darwin"
318        uses: actions/upload-release-asset@v1
319        env:
320          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
321        with:
322          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
323          asset_name: cargo-bazel-x86_64-apple-darwin
324          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel
325          asset_content_type: application/octet-stream
326      - name: "Upload x86_64-pc-windows-gnu"
327        uses: actions/upload-release-asset@v1
328        env:
329          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
330        with:
331          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
332          asset_name: cargo-bazel-x86_64-pc-windows-gnu.exe
333          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe
334          asset_content_type: application/octet-stream
335      - name: "Upload x86_64-pc-windows-msvc"
336        uses: actions/upload-release-asset@v1
337        env:
338          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
339        with:
340          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
341          asset_name: cargo-bazel-x86_64-pc-windows-msvc.exe
342          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe
343          asset_content_type: application/octet-stream
344      - name: "Upload x86_64-unknown-linux-gnu"
345        uses: actions/upload-release-asset@v1
346        env:
347          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
348        with:
349          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
350          asset_name: cargo-bazel-x86_64-unknown-linux-gnu
351          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel
352          asset_content_type: application/octet-stream
353      - name: "Upload x86_64-unknown-linux-musl"
354        uses: actions/upload-release-asset@v1
355        env:
356          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
357        with:
358          upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
359          asset_name: cargo-bazel-x86_64-unknown-linux-musl
360          asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel
361          asset_content_type: application/octet-stream