fork/rules_rust

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

UebelAndreFix release notes generation for extensions (#3062)5eed46d8

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