|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + types: [closed] |
| 8 | + branches: [main] |
| 9 | + # this is required to trigger releases when the release PR is merged, or to rerun a release if needed |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: {} |
| 13 | + |
| 14 | +jobs: |
| 15 | + # Parse commits since the last tag, push a `release/vX.Y.Z` branch, open |
| 16 | + # or update a draft release PR, and close any superseded release PRs |
| 17 | + # (e.g. `release/v1.0.1` when the bump is now `release/v1.1.0`). |
| 18 | + pr: |
| 19 | + if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: write # push the `release/vX.Y.Z` branch and delete superseded ones |
| 23 | + pull-requests: write # create a release PR, update its body, close superseded PRs |
| 24 | + steps: |
| 25 | + - uses: danielroe/uppt/pr@7bcfb5397c37202ef882363f755423130419d28a # v0.5.5 |
| 26 | + with: |
| 27 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + packages: | |
| 29 | + aliases |
| 30 | + core |
| 31 | + fetchindex |
| 32 | + newest |
| 33 | + oldest |
| 34 | + parsefiles |
| 35 | + ranges |
| 36 | + static |
| 37 | + !opt |
| 38 | + !translate |
| 39 | + |
| 40 | + # The release PR was merged: tag the squash commit, cut a GitHub release |
| 41 | + # from the PR body, and dispatch the publish workflow. The `release/v` |
| 42 | + # head-ref guard keeps regular feature-PR merges from triggering this; |
| 43 | + # the head-repo guard keeps merged fork PRs from triggering it. |
| 44 | + release: |
| 45 | + if: | |
| 46 | + github.event_name == 'pull_request' |
| 47 | + && github.event.pull_request.merged == true |
| 48 | + && startsWith(github.event.pull_request.head.ref, 'release/v') |
| 49 | + && github.event.pull_request.head.repo.full_name == github.repository |
| 50 | + runs-on: ubuntu-latest |
| 51 | + concurrency: |
| 52 | + group: release-${{ github.event.pull_request.number }} |
| 53 | + cancel-in-progress: false |
| 54 | + permissions: |
| 55 | + contents: write # push the `vX.Y.Z` tag and create the GitHub release |
| 56 | + actions: write # `gh workflow run release.yml --ref vX.Y.Z` chained dispatch |
| 57 | + steps: |
| 58 | + - uses: danielroe/uppt/release@7bcfb5397c37202ef882363f755423130419d28a # v0.5.5 |
| 59 | + with: |
| 60 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + packages: | |
| 62 | + aliases |
| 63 | + core |
| 64 | + fetchindex |
| 65 | + newest |
| 66 | + oldest |
| 67 | + parsefiles |
| 68 | + ranges |
| 69 | + static |
| 70 | + !opt |
| 71 | + !translate |
| 72 | +
|
| 73 | + # The chained dispatch from `release` lands here as a `workflow_dispatch` |
| 74 | + # event on a `vX.Y.Z` tag ref. The `pack` job installs deps, runs |
| 75 | + # `pnpm pack` (or `npm pack`), and uploads the tarball as a workflow |
| 76 | + # artifact. See "Lifecycle scripts" below for what runs where. Manual |
| 77 | + # recovery uses the same path (Run workflow -> pick a `v*` tag). |
| 78 | + pack: |
| 79 | + if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v') |
| 80 | + runs-on: ubuntu-latest |
| 81 | + concurrency: |
| 82 | + group: pack-${{ github.ref }} |
| 83 | + cancel-in-progress: false |
| 84 | + permissions: {} |
| 85 | + outputs: |
| 86 | + files: ${{ steps.pack.outputs.files }} |
| 87 | + steps: |
| 88 | + - id: pack |
| 89 | + uses: danielroe/uppt/pack@7bcfb5397c37202ef882363f755423130419d28a # v0.5.5 |
| 90 | + with: |
| 91 | + packages: | |
| 92 | + aliases |
| 93 | + core |
| 94 | + fetchindex |
| 95 | + newest |
| 96 | + oldest |
| 97 | + parsefiles |
| 98 | + ranges |
| 99 | + static |
| 100 | + !opt |
| 101 | + !translate |
| 102 | +
|
| 103 | + # `publish` downloads the prebuilt tarball from the pack job's |
| 104 | + # artifact and stages it for publish. |
| 105 | + publish: |
| 106 | + if: | |
| 107 | + github.event_name == 'workflow_dispatch' |
| 108 | + && startsWith(github.ref, 'refs/tags/v') |
| 109 | + && needs.pack.outputs.files != '[]' |
| 110 | + needs: pack |
| 111 | + runs-on: ubuntu-latest |
| 112 | + concurrency: |
| 113 | + group: publish-${{ github.ref }} |
| 114 | + cancel-in-progress: false |
| 115 | + permissions: |
| 116 | + id-token: write # OIDC claim for npm trusted publisher |
| 117 | + environment: npm # must match the trusted-publisher entry on npmjs.com |
| 118 | + steps: |
| 119 | + - uses: danielroe/uppt/publish@7bcfb5397c37202ef882363f755423130419d28a # v0.5.5 |
| 120 | + with: |
| 121 | + files: ${{ needs.pack.outputs.files }} |
0 commit comments