fork/rules_rust

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

UebelAndreUpdate Release github pipeline to trigger automatically (#1757)927a364c

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