|
| 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 | +# * builds artifacts with cargo-dist (executable-zips, installers, hashes) |
| 8 | +# * uploads those artifacts to the Github Release™ |
| 9 | +# * undrafts the Github Release™ on success |
| 10 | +# |
| 11 | +# Note that a Github Release™ with this tag is assumed to exist as a draft |
| 12 | +# with the appropriate title/body, and will be undrafted for you. |
| 13 | +name: Release |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +# This task will run whenever you push a git tag that looks like a version |
| 19 | +# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. |
| 20 | +# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where |
| 21 | +# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION |
| 22 | +# must be a Cargo-style SemVer Version (must have at least major.minor.patch). |
| 23 | +# |
| 24 | +# If PACKAGE_NAME is specified, then the release will be for that |
| 25 | +# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). |
| 26 | +# |
| 27 | +# If PACKAGE_NAME isn't specified, then the release will be for all |
| 28 | +# (cargo-dist-able) packages in the workspace with that version (this mode is |
| 29 | +# intended for workspaces with only one dist-able package, or with all dist-able |
| 30 | +# packages versioned/released in lockstep). |
| 31 | +# |
| 32 | +# If you push multiple tags at once, separate instances of this workflow will |
| 33 | +# spin up, creating an independent Github Release™ for each one. However Github |
| 34 | +# will hard limit this to 3 tags per commit, as it will assume more tags is a |
| 35 | +# mistake. |
| 36 | +# |
| 37 | +# If there's a prerelease-style suffix to the version, then the Github Release™ |
| 38 | +# will be marked as a prerelease. |
| 39 | +on: |
| 40 | + push: |
| 41 | + tags: |
| 42 | + - '**[0-9]+.[0-9]+.[0-9]+*' |
| 43 | + |
| 44 | +jobs: |
| 45 | + # Run 'cargo dist plan' to determine what tasks we need to do |
| 46 | + plan: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + outputs: |
| 49 | + has-releases: ${{ steps.plan.outputs.has-releases }} |
| 50 | + releases: ${{ steps.plan.outputs.releases }} |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v3 |
| 55 | + with: |
| 56 | + submodules: recursive |
| 57 | + - name: Install cargo-dist |
| 58 | + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0-prerelease.6/cargo-dist-installer.sh | sh" |
| 59 | + - id: plan |
| 60 | + run: | |
| 61 | + cargo dist plan --tag=${{ github.ref_name }} --output-format=json > dist-manifest.json |
| 62 | + echo "dist plan ran successfully" |
| 63 | + cat dist-manifest.json |
| 64 | +
|
| 65 | + # We're assuming a draft Github Release™ with the desired title/tag/body already exists |
| 66 | +
|
| 67 | + # Upload the manifest to the Github Release™ |
| 68 | + gh release upload ${{ github.ref_name }} dist-manifest.json |
| 69 | + echo "uploaded manifest!" |
| 70 | +
|
| 71 | + # Disable all the upload-artifacts tasks if we have no actual releases |
| 72 | + HAS_RELEASES=$(jq --raw-output ".releases != null" dist-manifest.json) |
| 73 | + echo "has-releases=$HAS_RELEASES" >> "$GITHUB_OUTPUT" |
| 74 | + echo "releases=$(jq --compact-output ".releases" dist-manifest.json)" >> "$GITHUB_OUTPUT" |
| 75 | +
|
| 76 | + # Build and packages all the platform-specific things |
| 77 | + upload-local-artifacts: |
| 78 | + # Let the initial task tell us to not run (currently very blunt) |
| 79 | + needs: plan |
| 80 | + if: ${{ needs.plan.outputs.has-releases == 'true' }} |
| 81 | + strategy: |
| 82 | + fail-fast: false |
| 83 | + matrix: |
| 84 | + # For these target platforms |
| 85 | + include: |
| 86 | + - os: "macos-11" |
| 87 | + dist-args: "--artifacts=local --target=aarch64-apple-darwin" |
| 88 | + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0-prerelease.6/cargo-dist-installer.sh | sh" |
| 89 | + - os: "macos-11" |
| 90 | + dist-args: "--artifacts=local --target=x86_64-apple-darwin" |
| 91 | + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0-prerelease.6/cargo-dist-installer.sh | sh" |
| 92 | + - os: "ubuntu-20.04" |
| 93 | + dist-args: "--artifacts=local --target=x86_64-unknown-linux-gnu" |
| 94 | + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0-prerelease.6/cargo-dist-installer.sh | sh" |
| 95 | + runs-on: ${{ matrix.os }} |
| 96 | + env: |
| 97 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v3 |
| 100 | + with: |
| 101 | + submodules: recursive |
| 102 | + - name: Install cargo-dist |
| 103 | + run: ${{ matrix.install-dist }} |
| 104 | + - name: Run cargo-dist |
| 105 | + # This logic is a bit janky because it's trying to be a polyglot between |
| 106 | + # powershell and bash since this will run on windows, macos, and linux! |
| 107 | + # The two platforms don't agree on how to talk about env vars but they |
| 108 | + # do agree on 'cat' and '$()' so we use that to marshal values between commands. |
| 109 | + run: | |
| 110 | + # Actually do builds and make zips and whatnot |
| 111 | + cargo dist build --tag=${{ github.ref_name }} --output-format=json ${{ matrix.dist-args }} > dist-manifest.json |
| 112 | + echo "dist ran successfully" |
| 113 | + cat dist-manifest.json |
| 114 | +
|
| 115 | + # Parse out what we just built and upload it to the Github Release™ |
| 116 | + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt |
| 117 | + echo "uploading..." |
| 118 | + cat uploads.txt |
| 119 | + gh release upload ${{ github.ref_name }} $(cat uploads.txt) |
| 120 | + echo "uploaded!" |
| 121 | +
|
| 122 | + # Build and package all the platform-agnostic(ish) things |
| 123 | + upload-global-artifacts: |
| 124 | + needs: upload-local-artifacts |
| 125 | + runs-on: "ubuntu-20.04" |
| 126 | + env: |
| 127 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + steps: |
| 129 | + - uses: actions/checkout@v3 |
| 130 | + with: |
| 131 | + submodules: recursive |
| 132 | + - name: Install cargo-dist |
| 133 | + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0-prerelease.6/cargo-dist-installer.sh | sh" |
| 134 | + # Get all the local artifacts for the global tasks to use (for e.g. checksums) |
| 135 | + - name: Fetch local artifacts |
| 136 | + run: | |
| 137 | + gh release download ${{ github.ref_name }} --dir target/distrib/ |
| 138 | + - name: Run cargo-dist |
| 139 | + run: | |
| 140 | + cargo dist build --tag=${{ github.ref_name }} --output-format=json "--artifacts=global" > 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 | + upload-homebrew-formula: |
| 152 | + needs: [plan, upload-global-artifacts] |
| 153 | + runs-on: "ubuntu-20.04" |
| 154 | + env: |
| 155 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 156 | + RELEASES: ${{ needs.plan.outputs.releases }} |
| 157 | + GITHUB_USER: "axo bot" |
| 158 | + |
| 159 | + steps: |
| 160 | + - uses: actions/checkout@v3 |
| 161 | + with: |
| 162 | + repository: "libsql/homebrew-sqld" |
| 163 | + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 164 | + # So we have access to the formula |
| 165 | + - name: Fetch local artifacts |
| 166 | + run: | |
| 167 | + gh release download ${{ github.ref_name }} --dir Formula --repo ${GITHUB_REPOSITORY} --clobber |
| 168 | + - name: Commit formula files |
| 169 | + run: | |
| 170 | + git config --global user.name "${GITHUB_USER}" |
| 171 | + git config --global user.email "${GITHUB_EMAIL}" |
| 172 | +
|
| 173 | + for release in $(echo "$RELEASES" | jq --compact-output '.[]'); do |
| 174 | + name=$(echo "$release" | jq .app_name --raw-output) |
| 175 | + version=$(echo "$release" | jq .app_version --raw-output) |
| 176 | +
|
| 177 | + git add Formula/${name}.rb |
| 178 | + git commit -m "${name} ${version}" |
| 179 | + done |
| 180 | + git push |
| 181 | +
|
| 182 | + # Mark the Github Release™ as a non-draft now that everything has succeeded! |
| 183 | + publish-release: |
| 184 | + # Only run after all the other tasks, but it's ok if upload-artifacts was skipped |
| 185 | + needs: [plan, upload-local-artifacts, upload-global-artifacts] |
| 186 | + if: ${{ always() && needs.plan.result == 'success' && (needs.upload-local-artifacts.result == 'skipped' || needs.upload-local-artifacts.result == 'success') && (needs.upload-global-artifacts.result == 'skipped' || needs.upload-global-artifacts.result == 'success') }} |
| 187 | + runs-on: ubuntu-latest |
| 188 | + env: |
| 189 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 190 | + steps: |
| 191 | + - uses: actions/checkout@v3 |
| 192 | + with: |
| 193 | + submodules: recursive |
| 194 | + - name: mark release as non-draft |
| 195 | + run: | |
| 196 | + gh release edit ${{ github.ref_name }} --draft=false |
0 commit comments