1- #  Copyright 2022-2023 , axodotdev
1+ #  Copyright 2022-2024 , axodotdev
22#  SPDX-License-Identifier: MIT or Apache-2.0
33# 
44#  CI that:
55# 
66#  * checks for a Git Tag that looks like a release
77#  * builds artifacts with cargo-dist (archives, installers, hashes)
88#  * uploads those artifacts to temporary workflow zip
9- #  * on success, uploads the artifacts to a Github  Release
9+ #  * on success, uploads the artifacts to a GitHub  Release
1010# 
11- #  Note that the Github  Release will be created with a generated
11+ #  Note that the GitHub  Release will be created with a generated
1212#  title/body based on your changelogs.
1313
1414name : Release 
15- 
1615permissions :
17-   contents :  write 
16+   " contents " :  " write" 
1817
1918#  This task will run whenever you push a git tag that looks like a version
2019#  like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
@@ -31,22 +30,22 @@ permissions:
3130#  packages versioned/released in lockstep).
3231# 
3332#  If you push multiple tags at once, separate instances of this workflow will
34- #  spin up, creating an independent announcement for each one. However Github 
33+ #  spin up, creating an independent announcement for each one. However, GitHub 
3534#  will hard limit this to 3 tags per commit, as it will assume more tags is a
3635#  mistake.
3736# 
3837#  If there's a prerelease-style suffix to the version, then the release(s)
3938#  will be marked as a prerelease.
4039on :
40+   pull_request :
4141  push :
4242    tags :
4343      - ' **[0-9]+.[0-9]+.[0-9]+*' 
44-   pull_request :
4544
4645jobs :
4746  #  Run 'cargo dist plan' (or host) to determine what tasks we need to do
4847  plan :
49-     runs-on : ubuntu-latest  
48+     runs-on : " ubuntu-20.04 " 
5049    outputs :
5150      val : ${{ steps.plan.outputs.manifest }} 
5251      tag : ${{ !github.event.pull_request && github.ref_name || '' }} 
6261        #  we specify bash to get pipefail; it guards against the `curl` command
6362        #  failing. otherwise `sh` won't catch that `curl` returned non-0
6463        shell : bash 
65-         run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" 
64+         run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.21.0/cargo-dist-installer.sh | sh" 
65+       - name : Cache cargo-dist 
66+         uses : actions/upload-artifact@v4 
67+         with :
68+           name : cargo-dist-cache 
69+           path : ~/.cargo/bin/cargo-dist 
6670      #  sure would be cool if github gave us proper conditionals...
6771      #  so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
6872      #  functionality based on whether this is a pull_request, and whether it's from a fork.
@@ -105,10 +109,12 @@ jobs:
105109      GH_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
106110      BUILD_MANIFEST_NAME : target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json 
107111    steps :
112+       - name : enable windows longpaths 
113+         run : | 
114+           git config --global core.longpaths true  
108115       - uses : actions/checkout@v4 
109116        with :
110117          submodules : recursive 
111-       - uses : swatinem/rust-cache@v2 
112118      - name : Install cargo-dist 
113119        run : ${{ matrix.install_dist }} 
114120      #  Get the dist-manifest
@@ -135,7 +141,7 @@ jobs:
135141        run : | 
136142          # Parse out what we just built and upload it to scratch storage 
137143          echo "paths<<EOF" >> "$GITHUB_OUTPUT" 
138-           jq --raw-output ".artifacts[]?.path | select( . != null ) " dist-manifest.json >> "$GITHUB_OUTPUT" 
144+           jq --raw-output ".upload_files[] " dist-manifest.json >> "$GITHUB_OUTPUT" 
139145          echo "EOF" >> "$GITHUB_OUTPUT" 
140146
141147          cp dist-manifest.json "$BUILD_MANIFEST_NAME" 
@@ -160,9 +166,12 @@ jobs:
160166      - uses : actions/checkout@v4 
161167        with :
162168          submodules : recursive 
163-       - name : Install cargo-dist 
164-         shell : bash 
165-         run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" 
169+       - name : Install cached cargo-dist 
170+         uses : actions/download-artifact@v4 
171+         with :
172+           name : cargo-dist-cache 
173+           path : ~/.cargo/bin/ 
174+       - run : chmod +x ~/.cargo/bin/cargo-dist 
166175      #  Get all the local artifacts for the global tasks to use (for e.g. checksums)
167176      - name : Fetch local artifacts 
168177        uses : actions/download-artifact@v4 
@@ -178,7 +187,7 @@ jobs:
178187
179188          # Parse out what we just built and upload it to scratch storage 
180189          echo "paths<<EOF" >> "$GITHUB_OUTPUT" 
181-           jq --raw-output ".artifacts[]?.path | select( . != null ) " dist-manifest.json >> "$GITHUB_OUTPUT" 
190+           jq --raw-output ".upload_files[] " dist-manifest.json >> "$GITHUB_OUTPUT" 
182191          echo "EOF" >> "$GITHUB_OUTPUT" 
183192
184193          cp dist-manifest.json "$BUILD_MANIFEST_NAME" 
@@ -206,16 +215,19 @@ jobs:
206215      - uses : actions/checkout@v4 
207216        with :
208217          submodules : recursive 
209-       - name : Install cargo-dist 
210-         run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" 
218+       - name : Install cached cargo-dist 
219+         uses : actions/download-artifact@v4 
220+         with :
221+           name : cargo-dist-cache 
222+           path : ~/.cargo/bin/ 
223+       - run : chmod +x ~/.cargo/bin/cargo-dist 
211224      #  Fetch artifacts from scratch-storage
212225      - name : Fetch artifacts 
213226        uses : actions/download-artifact@v4 
214227        with :
215228          pattern : artifacts-* 
216229          path : target/distrib/ 
217230          merge-multiple : true 
218-       #  This is a harmless no-op for Github Releases, hosting for that happens in "announce"
219231      - id : host 
220232        shell : bash 
221233        run : | 
@@ -229,8 +241,29 @@ jobs:
229241          #  Overwrite the previous copy
230242          name : artifacts-dist-manifest 
231243          path : dist-manifest.json 
244+       #  Create a GitHub Release while uploading all files to it
245+       - name : " Download GitHub Artifacts" 
246+         uses : actions/download-artifact@v4 
247+         with :
248+           pattern : artifacts-* 
249+           path : artifacts 
250+           merge-multiple : true 
251+       - name : Cleanup 
252+         run : | 
253+           # Remove the granular manifests 
254+           rm -f artifacts/*-dist-manifest.json 
255+        - name : Create GitHub Release 
256+         env :
257+           PRERELEASE_FLAG : " ${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}" 
258+           ANNOUNCEMENT_TITLE : " ${{ fromJson(steps.host.outputs.manifest).announcement_title }}" 
259+           ANNOUNCEMENT_BODY : " ${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}" 
260+           RELEASE_COMMIT : " ${{ github.sha }}" 
261+         run : | 
262+           # Write and read notes from a file to avoid quoting breaking things 
263+           echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt 
264+ 
265+           gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/* 
232266
233-   #  Create a Github Release while uploading all files to it
234267   announce :
235268    needs :
236269      - plan 
@@ -246,21 +279,3 @@ jobs:
246279      - uses : actions/checkout@v4 
247280        with :
248281          submodules : recursive 
249-       - name : " Download Github Artifacts" 
250-         uses : actions/download-artifact@v4 
251-         with :
252-           pattern : artifacts-* 
253-           path : artifacts 
254-           merge-multiple : true 
255-       - name : Cleanup 
256-         run : | 
257-           # Remove the granular manifests 
258-           rm -f artifacts/*-dist-manifest.json 
259-        - name : Create Github Release 
260-         uses : ncipollo/release-action@v1 
261-         with :
262-           tag : ${{ needs.plan.outputs.tag }} 
263-           name : ${{ fromJson(needs.host.outputs.val).announcement_title }} 
264-           body : ${{ fromJson(needs.host.outputs.val).announcement_github_body }} 
265-           prerelease : ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }} 
266-           artifacts : " artifacts/*" 
0 commit comments