|
| 1 | +# Copyright 2022-2023, axodotdev |
| 2 | +# SPDX-License-Identifier: MIT or Apache-2.0 |
| 3 | +# |
| 4 | +# CI that: |
| 5 | +# |
| 6 | +# * checks for a Git Tag that looks like a release |
| 7 | +# * creates a Github Release™ and fills in its text |
| 8 | +# * builds artifacts with cargo-dist (executable-zips, installers) |
| 9 | +# * uploads those artifacts to the Github Release™ |
| 10 | +# |
| 11 | +# Note that the Github Release™ will be created before the artifacts, |
| 12 | +# so there will be a few minutes where the release has no artifacts |
| 13 | +# and then they will slowly trickle in, possibly failing. To make |
| 14 | +# this more pleasant we mark the release as a "draft" until all |
| 15 | +# artifacts have been successfully uploaded. This allows you to |
| 16 | +# choose what to do with partial successes and avoids spamming |
| 17 | +# anyone with notifications before the release is actually ready. |
| 18 | +name: Release |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write |
| 22 | + |
| 23 | +# This task will run whenever you push a git tag that looks like a version |
| 24 | +# like "v1", "v1.2.0", "v0.1.0-prerelease01", "my-app-v1.0.0", etc. |
| 25 | +# The version will be roughly parsed as ({PACKAGE_NAME}-)?v{VERSION}, where |
| 26 | +# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION |
| 27 | +# must be a Cargo-style SemVer Version. |
| 28 | +# |
| 29 | +# If PACKAGE_NAME is specified, then we will create a Github Release™ for that |
| 30 | +# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). |
| 31 | +# |
| 32 | +# If PACKAGE_NAME isn't specified, then we will create a Github Release™ for all |
| 33 | +# (cargo-dist-able) packages in the workspace with that version (this is mode is |
| 34 | +# intended for workspaces with only one dist-able package, or with all dist-able |
| 35 | +# packages versioned/released in lockstep). |
| 36 | +# |
| 37 | +# If you push multiple tags at once, separate instances of this workflow will |
| 38 | +# spin up, creating an independent Github Release™ for each one. |
| 39 | +# |
| 40 | +# If there's a prerelease-style suffix to the version then the Github Release™ |
| 41 | +# will be marked as a prerelease. |
| 42 | +on: |
| 43 | + push: |
| 44 | + tags: |
| 45 | + - "*-?v[0-9]+*" |
| 46 | + |
| 47 | +jobs: |
| 48 | + # Create the Github Release™ so the packages have something to be uploaded to |
| 49 | + create-release: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + outputs: |
| 52 | + has-releases: ${{ steps.create-release.outputs.has-releases }} |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v3 |
| 57 | + with: |
| 58 | + submodules: recursive |
| 59 | + - name: Install cargo-dist |
| 60 | + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 61 | + - id: create-release |
| 62 | + run: | |
| 63 | + cargo dist plan --tag=${{ github.ref_name }} --output-format=json > dist-manifest.json |
| 64 | + echo "dist plan ran successfully" |
| 65 | + cat dist-manifest.json |
| 66 | +
|
| 67 | + # Create the Github Release™ based on what cargo-dist thinks it should be |
| 68 | + ANNOUNCEMENT_TITLE=$(jq --raw-output ".announcement_title" dist-manifest.json) |
| 69 | + IS_PRERELEASE=$(jq --raw-output ".announcement_is_prerelease" dist-manifest.json) |
| 70 | + jq --raw-output ".announcement_github_body" dist-manifest.json > new_dist_announcement.md |
| 71 | + gh release create ${{ github.ref_name }} --draft --prerelease="$IS_PRERELEASE" --title="$ANNOUNCEMENT_TITLE" --notes-file=new_dist_announcement.md |
| 72 | + echo "created announcement!" |
| 73 | +
|
| 74 | + # Upload the manifest to the Github Release™ |
| 75 | + gh release upload ${{ github.ref_name }} dist-manifest.json |
| 76 | + echo "uploaded manifest!" |
| 77 | +
|
| 78 | + # Disable all the upload-artifacts tasks if we have no actual releases |
| 79 | + HAS_RELEASES=$(jq --raw-output ".releases != null" dist-manifest.json) |
| 80 | + echo "has-releases=$HAS_RELEASES" >> "$GITHUB_OUTPUT" |
| 81 | +
|
| 82 | + # Build and packages all the things |
| 83 | + upload-artifacts: |
| 84 | + # Let the initial task tell us to not run (currently very blunt) |
| 85 | + needs: create-release |
| 86 | + if: ${{ needs.create-release.outputs.has-releases == 'true' }} |
| 87 | + strategy: |
| 88 | + fail-fast: false |
| 89 | + matrix: |
| 90 | + # For these target platforms |
| 91 | + include: |
| 92 | + - os: "ubuntu-latest" |
| 93 | + dist-args: "--artifacts=global" |
| 94 | + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 95 | + - os: "macos-latest" |
| 96 | + dist-args: "--artifacts=local --target=x86_64-apple-darwin" |
| 97 | + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 98 | + - os: "windows-latest" |
| 99 | + dist-args: "--artifacts=local --target=x86_64-pc-windows-msvc" |
| 100 | + install-dist: "irm https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.ps1 | iex" |
| 101 | + - os: "ubuntu-latest" |
| 102 | + dist-args: "--artifacts=local --target=x86_64-unknown-linux-gnu" |
| 103 | + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 104 | + - os: "ubuntu-latest" |
| 105 | + dist-args: "--artifacts=local --target=x86_64-unknown-linux-musl" |
| 106 | + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 107 | + # TODO! These targets are currently broken due to missing `cross` support, but we should fix them! |
| 108 | + # - os: "macos-latest" |
| 109 | + # dist-args: "--artifacts=local --target=aarch64-apple-darwin" |
| 110 | + # install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 111 | + # - os: "ubuntu-latest" |
| 112 | + # dist-args: "--artifacts=local --target=aarch64-unknown-linux-gnu" |
| 113 | + # install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 114 | + # - os: "ubuntu-latest" |
| 115 | + # dist-args: "--artifacts=local --target=armv7-unknown-linux-gnueabihf" |
| 116 | + # install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 117 | + # - os: "ubuntu-latest" |
| 118 | + # dist-args: "--artifacts=local --target=i686-unknown-linux-gnu" |
| 119 | + # install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 120 | + # - os: "ubuntu-latest" |
| 121 | + # dist-args: "--artifacts=local --target=x86_64-unknown-netbsd" |
| 122 | + # install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.1.0/cargo-dist-installer.sh | sh" |
| 123 | + |
| 124 | + runs-on: ${{ matrix.os }} |
| 125 | + env: |
| 126 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 127 | + steps: |
| 128 | + - uses: actions/checkout@v3 |
| 129 | + with: |
| 130 | + submodules: recursive |
| 131 | + - name: Install cargo-dist |
| 132 | + run: ${{ matrix.install-dist }} |
| 133 | + - name: Run cargo-dist |
| 134 | + # This logic is a bit janky because it's trying to be a polyglot between |
| 135 | + # powershell and bash since this will run on windows, macos, and linux! |
| 136 | + # The two platforms don't agree on how to talk about env vars but they |
| 137 | + # do agree on 'cat' and '$()' so we use that to marshal values between commands. |
| 138 | + run: | |
| 139 | + # Actually do builds and make zips and whatnot |
| 140 | + cargo dist build --tag=${{ github.ref_name }} --output-format=json ${{ matrix.dist-args }} > dist-manifest.json |
| 141 | + echo "dist ran successfully" |
| 142 | + cat dist-manifest.json |
| 143 | +
|
| 144 | + # Parse out what we just built and upload it to the Github Release™ |
| 145 | + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt |
| 146 | + echo "uploading..." |
| 147 | + cat uploads.txt |
| 148 | + gh release upload ${{ github.ref_name }} $(cat uploads.txt) |
| 149 | + echo "uploaded!" |
| 150 | +
|
| 151 | + # Mark the Github Release™ as a non-draft now that everything has succeeded! |
| 152 | + publish-release: |
| 153 | + # Only run after all the other tasks, but it's ok if upload-artifacts was skipped |
| 154 | + needs: [create-release, upload-artifacts] |
| 155 | + if: ${{ always() && needs.create-release.result == 'success' && (needs.upload-artifacts.result == 'skipped' || needs.upload-artifacts.result == 'success') }} |
| 156 | + runs-on: ubuntu-latest |
| 157 | + env: |
| 158 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 159 | + steps: |
| 160 | + - uses: actions/checkout@v3 |
| 161 | + with: |
| 162 | + submodules: recursive |
| 163 | + - name: mark release as non-draft |
| 164 | + run: | |
| 165 | + gh release edit ${{ github.ref_name }} --draft=false |
0 commit comments