■ ■ ■ ■ ■ ■
.github/workflows/release.yml
| 1 | + | # CI that: |
| 2 | + | # |
| 3 | + | # * checks for a Git Tag that looks like a release ("v1.2.0") |
| 4 | + | # * creates a Github Release™️ |
| 5 | + | # * builds binaries/packages with cargo-dist |
| 6 | + | # * uploads those packages to the Github Release™️ |
| 7 | + | # |
| 8 | + | # Note that the Github Release™️ will be created before the packages, |
| 9 | + | # so there will be a few minutes where the release has no packages |
| 10 | + | # and then they will slowly trickle in, possibly failing. To make |
| 11 | + | # this more pleasant we mark the release as a "draft" until all |
| 12 | + | # artifacts have been successfully uploaded. This allows you to |
| 13 | + | # choose what to do with partial successes and avoids spamming |
| 14 | + | # anyone with notifications before the release is actually ready. |
1 | 15 | | name: Release |
2 | 16 | | |
3 | | - | env: |
4 | | - | PROJECT_NAME: deduplicator |
5 | | - | PROJECT_DESC: "Filter, Sort & Delete Duplicate Files Recursively" |
6 | | - | PROJECT_AUTH: "sreedevk" |
| 17 | + | permissions: |
| 18 | + | contents: write |
7 | 19 | | |
| 20 | + | # This task will run whenever you push a git tag that looks like |
| 21 | + | # a version number. We just look for `v` followed by at least one number |
| 22 | + | # and then whatever. so `v1`, `v1.0.0`, and `v1.0.0-prerelease` all work. |
| 23 | + | # |
| 24 | + | # If there's a prerelease-style suffix to the version then the Github Release™️ |
| 25 | + | # will be marked as a prerelease (handled by taiki-e/create-gh-release-action). |
| 26 | + | # |
| 27 | + | # Note that when generating links to uploaded artifacts, cargo-dist will currently |
| 28 | + | # assume that your git tag is always v{VERSION} where VERSION is the version in |
| 29 | + | # the published package's Cargo.toml (this is the default behaviour of cargo-release). |
| 30 | + | # In the future this may be made more robust/configurable. |
8 | 31 | | on: |
9 | | - | release: |
10 | | - | types: |
11 | | - | - created |
| 32 | + | push: |
| 33 | + | tags: |
| 34 | + | - v[0-9]+.* |
| 35 | + | |
| 36 | + | env: |
| 37 | + | ALL_CARGO_DIST_TARGET_ARGS: --target=x86_64-unknown-linux-gnu --target=x86_64-apple-darwin --target=x86_64-pc-windows-msvc |
| 38 | + | ALL_CARGO_DIST_INSTALLER_ARGS: |
12 | 39 | | |
13 | 40 | | jobs: |
14 | | - | upload-assets: |
| 41 | + | # Create the Github Release™️ so the packages have something to be uploaded to |
| 42 | + | create-release: |
| 43 | + | runs-on: ubuntu-latest |
| 44 | + | outputs: |
| 45 | + | tag: ${{ steps.create-gh-release.outputs.computed-prefix }}${{ steps.create-gh-release.outputs.version }} |
| 46 | + | steps: |
| 47 | + | - uses: actions/checkout@v3 |
| 48 | + | - id: create-gh-release |
| 49 | + | uses: taiki-e/create-gh-release-action@v1 |
| 50 | + | with: |
| 51 | + | draft: true |
| 52 | + | # (required) GitHub token for creating GitHub Releases. |
| 53 | + | token: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + | |
| 55 | + | |
| 56 | + | # Build and packages all the things |
| 57 | + | upload-artifacts: |
| 58 | + | needs: create-release |
15 | 59 | | strategy: |
16 | 60 | | matrix: |
17 | | - | os: |
18 | | - | - ubuntu-latest |
19 | | - | - macos-latest |
20 | | - | - windows-latest |
| 61 | + | # For these target platforms |
| 62 | + | include: |
| 63 | + | - target: x86_64-unknown-linux-gnu |
| 64 | + | os: ubuntu-20.04 |
| 65 | + | install-dist: curl --proto '=https' --tlsv1.2 -L -sSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.2/installer.sh | sh |
| 66 | + | - target: x86_64-apple-darwin |
| 67 | + | os: macos-11 |
| 68 | + | install-dist: curl --proto '=https' --tlsv1.2 -L -sSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.2/installer.sh | sh |
| 69 | + | - target: x86_64-pc-windows-msvc |
| 70 | + | os: windows-2019 |
| 71 | + | install-dist: irm 'https://github.com/axodotdev/cargo-dist/releases/download/v0.0.2/installer.ps1' | iex |
21 | 72 | | runs-on: ${{ matrix.os }} |
| 73 | + | env: |
| 74 | + | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
22 | 75 | | steps: |
23 | 76 | | - uses: actions/checkout@v3 |
24 | | - | - uses: taiki-e/upload-rust-binary-action@v1 |
25 | | - | with: |
26 | | - | bin: deduplicator |
27 | | - | tar: unix |
28 | | - | zip: windows |
29 | | - | token: ${{ secrets.GITHUB_TOKEN }} |
30 | | - | env: |
31 | | - | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + | - name: Install Rust |
| 78 | + | run: rustup update stable && rustup default stable |
| 79 | + | - name: Install cargo-dist |
| 80 | + | run: ${{ matrix.install-dist }} |
| 81 | + | - name: Run cargo-dist |
| 82 | + | # This logic is a bit janky because it's trying to be a polyglot between |
| 83 | + | # powershell and bash since this will run on windows, macos, and linux! |
| 84 | + | # The two platforms don't agree on how to talk about env vars but they |
| 85 | + | # do agree on 'cat' and '$()' so we use that to marshal values between commmands. |
| 86 | + | run: | |
| 87 | + | # Actually do builds and make zips and whatnot |
| 88 | + | cargo dist --target=${{ matrix.target }} --output-format=json > dist-manifest.json |
| 89 | + | echo "dist ran successfully" |
| 90 | + | cat dist-manifest.json |
| 91 | + | # Parse out what we just built and upload it to the Github Release™️ |
| 92 | + | cat dist-manifest.json | jq --raw-output ".releases[].artifacts[].path" > uploads.txt |
| 93 | + | echo "uploading..." |
| 94 | + | cat uploads.txt |
| 95 | + | gh release upload ${{ needs.create-release.outputs.tag }} $(cat uploads.txt) |
| 96 | + | echo "uploaded!" |
| 97 | + | |
| 98 | + | # Compute and upload the manifest for everything |
| 99 | + | upload-manifest: |
| 100 | + | needs: create-release |
| 101 | + | runs-on: ubuntu-latest |
| 102 | + | env: |
| 103 | + | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + | steps: |
| 105 | + | - uses: actions/checkout@v3 |
| 106 | + | - name: Install Rust |
| 107 | + | run: rustup update stable && rustup default stable |
| 108 | + | - name: Install cargo-dist |
| 109 | + | run: curl --proto '=https' --tlsv1.2 -L -sSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.2/installer.sh | sh |
| 110 | + | - name: Run cargo-dist manifest |
| 111 | + | run: | |
| 112 | + | # Generate a manifest describing everything |
| 113 | + | cargo dist manifest --no-local-paths --output-format=json $ALL_CARGO_DIST_TARGET_ARGS $ALL_CARGO_DIST_INSTALLER_ARGS > dist-manifest.json |
| 114 | + | echo "dist manifest ran successfully" |
| 115 | + | cat dist-manifest.json |
| 116 | + | # Upload the manifest to the Github Release™️ |
| 117 | + | gh release upload ${{ needs.create-release.outputs.tag }} dist-manifest.json |
| 118 | + | echo "uploaded manifest!" |
| 119 | + | # Edit the Github Release™️ title/body to match what cargo-dist thinks it should be |
| 120 | + | CHANGELOG_TITLE=$(cat dist-manifest.json | jq --raw-output ".releases[].changelog_title") |
| 121 | + | cat dist-manifest.json | jq --raw-output ".releases[].changelog_body" > new_dist_changelog.md |
| 122 | + | gh release edit ${{ needs.create-release.outputs.tag }} --title="$CHANGELOG_TITLE" --notes-file=new_dist_changelog.md |
| 123 | + | echo "updated release notes!" |
| 124 | + | |
| 125 | + | # Mark the Github Release™️ as a non-draft now that everything has succeeded! |
| 126 | + | publish-release: |
| 127 | + | needs: [create-release, upload-artifacts, upload-manifest] |
| 128 | + | runs-on: ubuntu-latest |
| 129 | + | env: |
| 130 | + | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + | steps: |
| 132 | + | - uses: actions/checkout@v3 |
| 133 | + | - name: mark release as non-draft |
| 134 | + | run: | |
| 135 | + | gh release edit ${{ needs.create-release.outputs.tag }} --draft=false |
| 136 | + | |
32 | 137 | | |