|
| 1 | +name: Publish a pre-release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: release-pre-release |
| 10 | + # Do not cancel a run after it may have begun replacing release assets. |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-tag: |
| 15 | + name: Check for a version tag |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + is_tagged: ${{ steps.check.outputs.is_tagged }} |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v6 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - id: check |
| 25 | + name: Detect version tag |
| 26 | + run: | |
| 27 | + is_tagged=false |
| 28 | +
|
| 29 | + if [[ -n "$(git tag --points-at "$GITHUB_SHA" --list 'v*')" ]]; then |
| 30 | + is_tagged=true |
| 31 | + echo "$GITHUB_SHA has a version tag; the stable workflow will publish it" |
| 32 | + fi |
| 33 | +
|
| 34 | + echo "is_tagged=$is_tagged" >> "$GITHUB_OUTPUT" |
| 35 | +
|
| 36 | + build: |
| 37 | + name: Build for ${{ matrix.package }} |
| 38 | + needs: check-tag |
| 39 | + if: needs.check-tag.outputs.is_tagged == 'false' |
| 40 | + runs-on: ${{ matrix.runner }} |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + include: |
| 44 | + # - package: aarch64-linux |
| 45 | + # runner: ubuntu-latest |
| 46 | + - package: x86_64-linux |
| 47 | + runner: ubuntu-latest |
| 48 | + # - package: aarch64-darwin |
| 49 | + # runner: macos-14 |
| 50 | + # - package: x86_64-darwin |
| 51 | + # runner: macos-14 |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v6 |
| 54 | + |
| 55 | + - name: Install Nix |
| 56 | + uses: NixOS/nix-installer-action@main |
| 57 | + |
| 58 | + - name: Build package |
| 59 | + run: nix build ".#${{ matrix.package }}" |
| 60 | + |
| 61 | + - name: Stage artifact |
| 62 | + run: | |
| 63 | + cp result/bin/cache-action "cache-action-${{ matrix.package }}" |
| 64 | + gzip -9n "cache-action-${{ matrix.package }}" |
| 65 | +
|
| 66 | + - name: Upload artifact |
| 67 | + uses: actions/upload-artifact@v7 |
| 68 | + with: |
| 69 | + name: cache-action-${{ matrix.package }}.gz |
| 70 | + path: cache-action-${{ matrix.package }}.gz |
| 71 | + if-no-files-found: error |
| 72 | + |
| 73 | + release-dev: |
| 74 | + name: Publish pre-release |
| 75 | + needs: |
| 76 | + - check-tag |
| 77 | + - build |
| 78 | + if: needs.check-tag.outputs.is_tagged == 'false' |
| 79 | + runs-on: ubuntu-latest |
| 80 | + permissions: |
| 81 | + contents: write |
| 82 | + env: |
| 83 | + RELEASE_TAG: pre-release |
| 84 | + steps: |
| 85 | + - name: Download artifacts |
| 86 | + uses: actions/download-artifact@v8 |
| 87 | + with: |
| 88 | + pattern: cache-action-* |
| 89 | + path: dist |
| 90 | + merge-multiple: true |
| 91 | + |
| 92 | + - name: Create or update pre-release |
| 93 | + env: |
| 94 | + GH_TOKEN: ${{ github.token }} |
| 95 | + run: | |
| 96 | + if gh api \ |
| 97 | + "repos/$GITHUB_REPOSITORY/git/ref/tags/$RELEASE_TAG" \ |
| 98 | + >/dev/null 2>&1; then |
| 99 | + gh api --method PATCH \ |
| 100 | + "repos/$GITHUB_REPOSITORY/git/refs/tags/$RELEASE_TAG" \ |
| 101 | + --raw-field sha="$GITHUB_SHA" \ |
| 102 | + --field force=true \ |
| 103 | + --silent |
| 104 | + else |
| 105 | + gh api --method POST \ |
| 106 | + "repos/$GITHUB_REPOSITORY/git/refs" \ |
| 107 | + --raw-field ref="refs/tags/$RELEASE_TAG" \ |
| 108 | + --raw-field sha="$GITHUB_SHA" \ |
| 109 | + --silent |
| 110 | + fi |
| 111 | +
|
| 112 | + command=create |
| 113 | +
|
| 114 | + if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then |
| 115 | + command=edit |
| 116 | + fi |
| 117 | +
|
| 118 | + gh release "$command" "$RELEASE_TAG" \ |
| 119 | + --repo "$GITHUB_REPOSITORY" \ |
| 120 | + --title "$RELEASE_TAG" \ |
| 121 | + --notes "Pre-release for commit $GITHUB_SHA" \ |
| 122 | + --prerelease \ |
| 123 | + --latest=false \ |
| 124 | + --target "$GITHUB_SHA" \ |
| 125 | + --verify-tag |
| 126 | +
|
| 127 | + - name: Upload release artifacts |
| 128 | + env: |
| 129 | + GH_TOKEN: ${{ github.token }} |
| 130 | + run: gh release upload "$RELEASE_TAG" dist/* --clobber --repo "$GITHUB_REPOSITORY" |
0 commit comments