|
1 | | -name: Release |
| 1 | +# This file was autogenerated by cargo-dist: https://opensource.axo.dev/cargo-dist/ |
| 2 | +# |
| 3 | +# Copyright 2022-2024, axodotdev |
| 4 | +# SPDX-License-Identifier: MIT or Apache-2.0 |
| 5 | +# |
| 6 | +# CI that: |
| 7 | +# |
| 8 | +# * checks for a Git Tag that looks like a release |
| 9 | +# * builds artifacts with cargo-dist (archives, installers, hashes) |
| 10 | +# * uploads those artifacts to temporary workflow zip |
| 11 | +# * on success, uploads the artifacts to a GitHub Release |
| 12 | +# |
| 13 | +# Note that the GitHub Release will be created with a generated |
| 14 | +# title/body based on your changelogs. |
2 | 15 |
|
| 16 | +name: Release |
3 | 17 | permissions: |
4 | | - contents: write |
| 18 | + "contents": "write" |
5 | 19 |
|
| 20 | +# This task will run whenever you push a git tag that looks like a version |
| 21 | +# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. |
| 22 | +# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where |
| 23 | +# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION |
| 24 | +# must be a Cargo-style SemVer Version (must have at least major.minor.patch). |
| 25 | +# |
| 26 | +# If PACKAGE_NAME is specified, then the announcement will be for that |
| 27 | +# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). |
| 28 | +# |
| 29 | +# If PACKAGE_NAME isn't specified, then the announcement will be for all |
| 30 | +# (cargo-dist-able) packages in the workspace with that version (this mode is |
| 31 | +# intended for workspaces with only one dist-able package, or with all dist-able |
| 32 | +# packages versioned/released in lockstep). |
| 33 | +# |
| 34 | +# If you push multiple tags at once, separate instances of this workflow will |
| 35 | +# spin up, creating an independent announcement for each one. However, GitHub |
| 36 | +# will hard limit this to 3 tags per commit, as it will assume more tags is a |
| 37 | +# mistake. |
| 38 | +# |
| 39 | +# If there's a prerelease-style suffix to the version, then the release(s) |
| 40 | +# will be marked as a prerelease. |
6 | 41 | on: |
| 42 | + pull_request: |
7 | 43 | push: |
8 | 44 | tags: |
9 | | - - 'v*' |
10 | | - |
11 | | -env: |
12 | | - CARGO_TERM_COLOR: always |
| 45 | + - '**[0-9]+.[0-9]+.[0-9]+*' |
13 | 46 |
|
14 | 47 | jobs: |
15 | | - # Plan the release |
| 48 | + # Run 'cargo dist plan' (or host) to determine what tasks we need to do |
16 | 49 | plan: |
17 | | - runs-on: ubuntu-latest |
| 50 | + runs-on: "ubuntu-24.04" |
18 | 51 | outputs: |
19 | | - plan: ${{ steps.plan.outputs.plan }} |
| 52 | + val: ${{ steps.plan.outputs.manifest }} |
| 53 | + tag: ${{ !github.event.pull_request && github.ref_name || '' }} |
| 54 | + tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} |
| 55 | + publishing: ${{ !github.event.pull_request }} |
| 56 | + env: |
| 57 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
20 | 58 | steps: |
21 | 59 | - uses: actions/checkout@v4 |
22 | | - - name: Install Rust |
23 | | - uses: dtolnay/rust-toolchain@stable |
| 60 | + with: |
| 61 | + submodules: recursive |
24 | 62 | - name: Install cargo-dist |
25 | | - run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh |
26 | | - - name: Plan Release |
27 | | - id: plan |
28 | | - run: cargo dist plan --output-format=json > plan.json && echo "plan=$(cat plan.json | jq -c .)" >> $GITHUB_OUTPUT |
| 63 | + # we specify bash to get pipefail; it guards against the `curl` command |
| 64 | + # failing. otherwise `sh` won't catch that `curl` returned non-0 |
| 65 | + shell: bash |
| 66 | + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh" |
| 67 | + - name: Cache cargo-dist |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: cargo-dist-cache |
| 71 | + path: ~/.cargo/bin/cargo-dist |
| 72 | + # sure would be cool if github gave us proper conditionals... |
| 73 | + # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible |
| 74 | + # functionality based on whether this is a pull_request, and whether it's from a fork. |
| 75 | + # (PRs run on the *source* but secrets are usually on the *target* -- that's *good* |
| 76 | + # but also really annoying to build CI around when it needs secrets to work right.) |
| 77 | + - id: plan |
| 78 | + run: | |
| 79 | + cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json |
| 80 | + echo "cargo dist ran successfully" |
| 81 | + cat plan-dist-manifest.json |
| 82 | + echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" |
| 83 | + - name: "Upload dist-manifest.json" |
| 84 | + uses: actions/upload-artifact@v4 |
| 85 | + with: |
| 86 | + name: artifacts-plan-dist-manifest |
| 87 | + path: plan-dist-manifest.json |
29 | 88 |
|
30 | | - # Build artifacts |
31 | | - build: |
32 | | - needs: plan |
| 89 | + # Build and packages all the platform-specific things |
| 90 | + build-local-artifacts: |
| 91 | + name: build-local-artifacts (${{ join(matrix.targets, ', ') }}) |
| 92 | + # Let the initial task tell us to not run (currently very blunt) |
| 93 | + needs: |
| 94 | + - plan |
| 95 | + if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} |
33 | 96 | strategy: |
34 | | - matrix: |
35 | | - include: |
36 | | - - os: ubuntu-latest |
37 | | - target: x86_64-unknown-linux-gnu |
38 | | - - os: ubuntu-latest |
39 | | - target: x86_64-unknown-linux-musl |
40 | | - - os: ubuntu-latest |
41 | | - target: aarch64-unknown-linux-gnu |
42 | | - - os: macos-latest |
43 | | - target: x86_64-apple-darwin |
44 | | - - os: macos-latest |
45 | | - target: aarch64-apple-darwin |
46 | | - - os: windows-latest |
47 | | - target: x86_64-pc-windows-msvc |
48 | | - runs-on: ${{ matrix.os }} |
| 97 | + fail-fast: false |
| 98 | + # Target platforms/runners are computed by cargo-dist in create-release. |
| 99 | + # Each member of the matrix has the following arguments: |
| 100 | + # |
| 101 | + # - runner: the github runner |
| 102 | + # - dist-args: cli flags to pass to cargo dist |
| 103 | + # - install-dist: expression to run to install cargo-dist on the runner |
| 104 | + # |
| 105 | + # Typically there will be: |
| 106 | + # - 1 "global" task that builds universal installers |
| 107 | + # - N "local" tasks that build each platform's binaries and platform-specific installers |
| 108 | + matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }} |
| 109 | + runs-on: ${{ matrix.runner }} |
| 110 | + env: |
| 111 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json |
49 | 113 | steps: |
50 | | - - uses: actions/checkout@v4 |
51 | | - - name: Install musl-tools and dependencies |
52 | | - if: matrix.target == 'x86_64-unknown-linux-musl' |
| 114 | + - name: enable windows longpaths |
53 | 115 | run: | |
54 | | - sudo apt-get update |
55 | | - sudo apt-get install -y musl-tools liblzma-dev libz-dev |
56 | | - - name: Install Rust |
57 | | - uses: dtolnay/rust-toolchain@stable |
| 116 | + git config --global core.longpaths true |
| 117 | + - uses: actions/checkout@v4 |
58 | 118 | with: |
59 | | - targets: ${{ matrix.target }} |
| 119 | + submodules: recursive |
60 | 120 | - name: Install cargo-dist |
61 | | - run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh |
62 | | - - name: Build Artifacts |
63 | | - run: cargo dist build --tag=${{ github.ref_name }} --target=${{ matrix.target }} --output-format=json > artifacts.json |
64 | | - - name: Upload Artifacts |
| 121 | + run: ${{ matrix.install_dist }} |
| 122 | + # Get the dist-manifest |
| 123 | + - name: Fetch local artifacts |
| 124 | + uses: actions/download-artifact@v4 |
| 125 | + with: |
| 126 | + pattern: artifacts-* |
| 127 | + path: target/distrib/ |
| 128 | + merge-multiple: true |
| 129 | + - name: Install dependencies |
| 130 | + run: | |
| 131 | + ${{ matrix.packages_install }} |
| 132 | + - name: Build artifacts |
| 133 | + run: | |
| 134 | + # Actually do builds and make zips and whatnot |
| 135 | + cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json |
| 136 | + echo "cargo dist ran successfully" |
| 137 | + - id: cargo-dist |
| 138 | + name: Post-build |
| 139 | + # We force bash here just because github makes it really hard to get values up |
| 140 | + # to "real" actions without writing to env-vars, and writing to env-vars has |
| 141 | + # inconsistent syntax between shell and powershell. |
| 142 | + shell: bash |
| 143 | + run: | |
| 144 | + # Parse out what we just built and upload it to scratch storage |
| 145 | + echo "paths<<EOF" >> "$GITHUB_OUTPUT" |
| 146 | + jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" |
| 147 | + echo "EOF" >> "$GITHUB_OUTPUT" |
| 148 | +
|
| 149 | + cp dist-manifest.json "$BUILD_MANIFEST_NAME" |
| 150 | + - name: "Upload artifacts" |
65 | 151 | uses: actions/upload-artifact@v4 |
66 | 152 | with: |
67 | | - name: artifacts-${{ matrix.target }} |
68 | | - path: target/dist/* |
| 153 | + name: artifacts-build-local-${{ join(matrix.targets, '_') }} |
| 154 | + path: | |
| 155 | + ${{ steps.cargo-dist.outputs.paths }} |
| 156 | + ${{ env.BUILD_MANIFEST_NAME }} |
| 157 | +
|
| 158 | + # Build and package all the platform-agnostic(ish) things |
| 159 | + build-global-artifacts: |
| 160 | + needs: |
| 161 | + - plan |
| 162 | + - build-local-artifacts |
| 163 | + runs-on: "ubuntu-24.04" |
| 164 | + env: |
| 165 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 166 | + BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json |
| 167 | + steps: |
| 168 | + - uses: actions/checkout@v4 |
| 169 | + with: |
| 170 | + submodules: recursive |
| 171 | + - name: Install cached cargo-dist |
| 172 | + uses: actions/download-artifact@v4 |
| 173 | + with: |
| 174 | + name: cargo-dist-cache |
| 175 | + path: ~/.cargo/bin/ |
| 176 | + - run: chmod +x ~/.cargo/bin/cargo-dist |
| 177 | + # Get all the local artifacts for the global tasks to use (for e.g. checksums) |
| 178 | + - name: Fetch local artifacts |
| 179 | + uses: actions/download-artifact@v4 |
| 180 | + with: |
| 181 | + pattern: artifacts-* |
| 182 | + path: target/distrib/ |
| 183 | + merge-multiple: true |
| 184 | + - id: cargo-dist |
| 185 | + shell: bash |
| 186 | + run: | |
| 187 | + cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json |
| 188 | + echo "cargo dist ran successfully" |
| 189 | +
|
| 190 | + # Parse out what we just built and upload it to scratch storage |
| 191 | + echo "paths<<EOF" >> "$GITHUB_OUTPUT" |
| 192 | + jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" |
| 193 | + echo "EOF" >> "$GITHUB_OUTPUT" |
69 | 194 |
|
70 | | - # Create the GitHub Release |
71 | | - release: |
72 | | - needs: [plan, build] |
73 | | - runs-on: ubuntu-latest |
| 195 | + cp dist-manifest.json "$BUILD_MANIFEST_NAME" |
| 196 | + - name: "Upload artifacts" |
| 197 | + uses: actions/upload-artifact@v4 |
| 198 | + with: |
| 199 | + name: artifacts-build-global |
| 200 | + path: | |
| 201 | + ${{ steps.cargo-dist.outputs.paths }} |
| 202 | + ${{ env.BUILD_MANIFEST_NAME }} |
| 203 | + # Determines if we should publish/announce |
| 204 | + host: |
| 205 | + needs: |
| 206 | + - plan |
| 207 | + - build-local-artifacts |
| 208 | + - build-global-artifacts |
| 209 | + # Only run if we're "publishing", and only if local and global didn't fail (skipped is fine) |
| 210 | + if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }} |
| 211 | + env: |
| 212 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 213 | + runs-on: "ubuntu-24.04" |
| 214 | + outputs: |
| 215 | + val: ${{ steps.host.outputs.manifest }} |
74 | 216 | steps: |
75 | 217 | - uses: actions/checkout@v4 |
76 | | - - name: Download Artifacts |
| 218 | + with: |
| 219 | + submodules: recursive |
| 220 | + - name: Install cached cargo-dist |
| 221 | + uses: actions/download-artifact@v4 |
| 222 | + with: |
| 223 | + name: cargo-dist-cache |
| 224 | + path: ~/.cargo/bin/ |
| 225 | + - run: chmod +x ~/.cargo/bin/cargo-dist |
| 226 | + # Fetch artifacts from scratch-storage |
| 227 | + - name: Fetch artifacts |
| 228 | + uses: actions/download-artifact@v4 |
| 229 | + with: |
| 230 | + pattern: artifacts-* |
| 231 | + path: target/distrib/ |
| 232 | + merge-multiple: true |
| 233 | + - id: host |
| 234 | + shell: bash |
| 235 | + run: | |
| 236 | + cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json |
| 237 | + echo "artifacts uploaded and released successfully" |
| 238 | + cat dist-manifest.json |
| 239 | + echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" |
| 240 | + - name: "Upload dist-manifest.json" |
| 241 | + uses: actions/upload-artifact@v4 |
| 242 | + with: |
| 243 | + # Overwrite the previous copy |
| 244 | + name: artifacts-dist-manifest |
| 245 | + path: dist-manifest.json |
| 246 | + # Create a GitHub Release while uploading all files to it |
| 247 | + - name: "Download GitHub Artifacts" |
77 | 248 | uses: actions/download-artifact@v4 |
78 | 249 | with: |
| 250 | + pattern: artifacts-* |
79 | 251 | path: artifacts |
80 | 252 | merge-multiple: true |
81 | | - - name: Install cargo-dist |
82 | | - run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh |
83 | | - - name: Create Release |
| 253 | + - name: Cleanup |
84 | 254 | run: | |
85 | | - ls -R artifacts |
86 | | - cargo dist host github --tag=${{ github.ref_name }} --artifacts-dir=artifacts |
| 255 | + # Remove the granular manifests |
| 256 | + rm -f artifacts/*-dist-manifest.json |
| 257 | + - name: Create GitHub Release |
| 258 | + env: |
| 259 | + PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}" |
| 260 | + ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}" |
| 261 | + ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}" |
| 262 | + RELEASE_COMMIT: "${{ github.sha }}" |
| 263 | + run: | |
| 264 | + # Write and read notes from a file to avoid quoting breaking things |
| 265 | + echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt |
| 266 | +
|
| 267 | + gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/* |
| 268 | +
|
| 269 | + announce: |
| 270 | + needs: |
| 271 | + - plan |
| 272 | + - host |
| 273 | + # use "always() && ..." to allow us to wait for all publish jobs while |
| 274 | + # still allowing individual publish jobs to skip themselves (for prereleases). |
| 275 | + # "host" however must run to completion, no skipping allowed! |
| 276 | + if: ${{ always() && needs.host.result == 'success' }} |
| 277 | + runs-on: "ubuntu-24.04" |
| 278 | + env: |
| 279 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 280 | + steps: |
| 281 | + - uses: actions/checkout@v4 |
| 282 | + with: |
| 283 | + submodules: recursive |
0 commit comments