|
5 | 5 | branches: |
6 | 6 | - master |
7 | 7 |
|
| 8 | + issue_comment: |
| 9 | + types: [created] |
| 10 | + |
8 | 11 | env: |
9 | | - npm-token: ${{ secrets.NPM_TOKEN }} |
10 | 12 | github-token: ${{ secrets.GITHUB_TOKEN }} |
11 | 13 | node-version: '24.x' |
| 14 | + snapshot-release-tag: pr${{ github.event.issue.number }}-run${{ github.run_number }}-${{ github.run_attempt }} |
12 | 15 |
|
13 | 16 | jobs: |
14 | 17 | release: |
15 | 18 | name: Release |
16 | 19 | runs-on: ubuntu-24.04 |
17 | 20 | permissions: |
| 21 | + id-token: write # allows ODIC publishing |
18 | 22 | contents: write |
19 | 23 | pull-requests: write |
20 | 24 |
|
21 | 25 | steps: |
22 | | - - name: Check out repository |
23 | | - uses: actions/checkout@v4 |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: ${{ env.node-version }} |
| 31 | + cache: yarn |
| 32 | + cache-dependency-path: '**/yarn.lock' |
| 33 | + |
| 34 | + - run: yarn install --prefer-offline |
| 35 | + |
| 36 | + # - name: Create Release Pull Request or Publish to NPM |
| 37 | + # id: changesets |
| 38 | + # uses: changesets/[email protected] |
| 39 | + # with: |
| 40 | + # publish: yarn release |
| 41 | + # commit: 'chore(release): update packages versions' |
| 42 | + # title: 'Upcoming Release Changes' |
| 43 | + # env: |
| 44 | + # GITHUB_TOKEN: ${{ env.github-token }} |
| 45 | + |
| 46 | + release-snapshot-check: |
| 47 | + if: github.event.comment != '' |
| 48 | + runs-on: ubuntu-24.04 |
| 49 | + permissions: |
| 50 | + pull-requests: write |
| 51 | + outputs: |
| 52 | + triggered: ${{ steps.check.outputs.triggered }} |
| 53 | + steps: |
| 54 | + - name: Acknowledge deployment request to commenter |
| 55 | + id: check |
| 56 | + |
| 57 | + with: |
| 58 | + trigger: '/release-snapshot' |
| 59 | + reaction: rocket |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ env.github-token }} |
| 62 | + |
| 63 | + - name: Validate user |
| 64 | + if: ${{ steps.check.outputs.triggered == 'true' }} |
| 65 | + run: | |
| 66 | + if [[ "${AUTHOR_ASSOCIATION}" != 'OWNER' ]] |
| 67 | + then |
| 68 | + echo "User authorization failed" |
| 69 | + exit 1 |
| 70 | + else |
| 71 | + echo "User authorization successful" |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | + env: |
| 75 | + AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }} |
| 76 | + |
| 77 | + - name: Report failure |
| 78 | + if: failure() |
| 79 | + |
| 80 | + with: |
| 81 | + route: POST /repos/{owner}/{repo}/issues/{issue_number}/comments |
| 82 | + owner: ${{ github.repository_owner }} |
| 83 | + repo: ${{ github.event.repository.name }} |
| 84 | + issue_number: ${{ github.event.issue.number }} |
| 85 | + body: '❌ No permission to release snapshot' |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ env.github-token }} |
| 88 | + |
| 89 | + release-snapshot: |
| 90 | + runs-on: ubuntu-24.04 |
| 91 | + needs: release-snapshot-check |
| 92 | + permissions: |
| 93 | + id-token: write # allows ODIC publishing |
| 94 | + contents: read |
| 95 | + pull-requests: write # allows posting a message to the PR about success/error |
| 96 | + if: needs.release-snapshot-check.outputs.triggered == 'true' |
| 97 | + steps: |
| 98 | + - name: Get Pull Request ref |
| 99 | + id: get_pull_request_ref |
| 100 | + |
| 101 | + with: |
| 102 | + route: GET /repos/{owner}/{repo}/pulls/{issue_number} |
| 103 | + owner: ${{ github.repository_owner }} |
| 104 | + repo: ${{ github.event.repository.name }} |
| 105 | + issue_number: ${{ github.event.issue.number }} |
| 106 | + env: |
| 107 | + GITHUB_TOKEN: ${{ env.github-token }} |
24 | 108 |
|
25 | | - - name: Set up Node.js |
26 | | - uses: actions/setup-node@v4 |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + with: |
| 111 | + persist-credentials: true |
| 112 | + repository: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.repo.full_name }} |
| 113 | + ref: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.ref }} |
| 114 | + |
| 115 | + - uses: actions/setup-node@v4 |
27 | 116 | with: |
28 | 117 | node-version: ${{ env.node-version }} |
| 118 | + registry-url: 'https://registry.npmjs.org' |
29 | 119 | cache: yarn |
30 | 120 | cache-dependency-path: '**/yarn.lock' |
31 | 121 |
|
32 | | - - name: Install packages |
33 | | - run: yarn install --prefer-offline |
| 122 | + - run: yarn install --prefer-offline |
| 123 | + |
| 124 | + - name: Deploy snapshot |
| 125 | + run: | |
| 126 | + yarn changeset version --snapshot $RELEASE_TAG |
| 127 | + yarn nx run-many --target=build |
| 128 | + yarn changeset publish --tag $RELEASE_TAG --no-git-tag |
| 129 | + env: |
| 130 | + GITHUB_TOKEN: ${{ env.github-token }} |
| 131 | + RELEASE_TAG: ${{ env.snapshot-release-tag }} |
| 132 | + |
| 133 | + - name: Report success |
| 134 | + if: success() |
| 135 | + |
| 136 | + with: |
| 137 | + route: POST /repos/{owner}/{repo}/issues/{issue_number}/comments |
| 138 | + owner: ${{ github.repository_owner }} |
| 139 | + repo: ${{ github.event.repository.name }} |
| 140 | + issue_number: ${{ github.event.issue.number }} |
| 141 | + body: '✅ Successfully published package/s with tag `${{ env.snapshot-release-tag }}`!' |
| 142 | + env: |
| 143 | + GITHUB_TOKEN: ${{ env.github-token }} |
34 | 144 |
|
35 | | - - name: Create Release Pull Request or Publish to NPM |
36 | | - id: changesets |
37 | | - uses: changesets/action@v1.5.3 |
| 145 | + - name: Report failure |
| 146 | + if: failure() |
| 147 | + uses: octokit/request-action@v2.4.0 |
38 | 148 | with: |
39 | | - publish: yarn release |
40 | | - commit: 'chore(release): update packages versions' |
41 | | - title: 'Upcoming Release Changes' |
| 149 | + route: POST /repos/{owner}/{repo}/issues/{issue_number}/comments |
| 150 | + owner: ${{ github.repository_owner }} |
| 151 | + repo: ${{ github.event.repository.name }} |
| 152 | + issue_number: ${{ github.event.issue.number }} |
| 153 | + body: '❌ Failed to publish package/s with tag `${{ env.snapshot-release-tag }}`' |
42 | 154 | env: |
43 | 155 | GITHUB_TOKEN: ${{ env.github-token }} |
44 | | - NPM_TOKEN: ${{ env.npm-token }} |
|
0 commit comments