|
| 1 | +# This file is automatically added by @npmcli/template-oss. Do not edit. |
| 2 | + |
| 3 | +name: Release |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - latest |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + checks: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + outputs: |
| 19 | + pr: ${{ steps.release.outputs.pr }} |
| 20 | + releases: ${{ steps.release.outputs.releases }} |
| 21 | + release-flags: ${{ steps.release.outputs.release-flags }} |
| 22 | + branch: ${{ steps.release.outputs.pr-branch }} |
| 23 | + pr-number: ${{ steps.release.outputs.pr-number }} |
| 24 | + comment-id: ${{ steps.pr-comment.outputs.result }} |
| 25 | + check-id: ${{ steps.check.outputs.check_id }} |
| 26 | + name: Release |
| 27 | + if: github.repository_owner == 'npm' |
| 28 | + runs-on: ubuntu-latest |
| 29 | + defaults: |
| 30 | + run: |
| 31 | + shell: bash |
| 32 | + steps: |
| 33 | + - name: Checkout |
| 34 | + uses: actions/checkout@v3 |
| 35 | + - name: Setup Git User |
| 36 | + run: | |
| 37 | + git config --global user.email "npm-cli+bot@github.com" |
| 38 | + git config --global user.name "npm CLI robot" |
| 39 | + - name: Setup Node |
| 40 | + uses: actions/setup-node@v3 |
| 41 | + with: |
| 42 | + node-version: 18.x |
| 43 | + - name: Install npm@latest |
| 44 | + run: npm i --prefer-online --no-fund --no-audit -g npm@latest |
| 45 | + - name: npm Version |
| 46 | + run: npm -v |
| 47 | + - name: Install Dependencies |
| 48 | + run: npm i --ignore-scripts --no-audit --no-fund |
| 49 | + - name: Release Please |
| 50 | + id: release |
| 51 | + env: |
| 52 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + run: | |
| 54 | + npx --offline template-oss-release-please ${{ github.ref_name }} |
| 55 | + - name: Post Pull Request Comment |
| 56 | + if: steps.release.outputs.pr-number |
| 57 | + uses: actions/github-script@v6 |
| 58 | + id: pr-comment |
| 59 | + env: |
| 60 | + PR_NUMBER: ${{ steps.release.outputs.pr-number }} |
| 61 | + with: |
| 62 | + script: | |
| 63 | + const repo = { owner: context.repo.owner, repo: context.repo.repo } |
| 64 | + const issue = { ...repo, issue_number: process.env.PR_NUMBER } |
| 65 | +
|
| 66 | + const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: context.runId }) |
| 67 | +
|
| 68 | + let body = '## Release Manager\n\n' |
| 69 | +
|
| 70 | + const comments = await github.paginate(github.rest.issues.listComments, issue) |
| 71 | + let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id |
| 72 | +
|
| 73 | + body += `- Release workflow run: ${workflow.html_url}` |
| 74 | + if (commentId) { |
| 75 | + await github.rest.issues.updateComment({ ...repo, comment_id: commentId, body }) |
| 76 | + } else { |
| 77 | + const { data: comment } = await github.rest.issues.createComment({ ...issue, body }) |
| 78 | + commentId = comment?.id |
| 79 | + } |
| 80 | +
|
| 81 | + return commentId |
| 82 | + - name: Create Check |
| 83 | + uses: LouisBrunner/checks-action@v1.3.1 |
| 84 | + id: check |
| 85 | + if: steps.release.outputs.pr-number |
| 86 | + with: |
| 87 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + status: in_progress |
| 89 | + name: Release |
| 90 | + sha: ${{ steps.release.outputs.pr-sha }} |
| 91 | + # XXX: this does not work when using the default GITHUB_TOKEN. |
| 92 | + # Instead we post the main job url to the PR as a comment which |
| 93 | + # will link to all the other checks. To work around this we would |
| 94 | + # need to create a GitHub that would create on-demand tokens. |
| 95 | + # https://github.com/LouisBrunner/checks-action/issues/18 |
| 96 | + # details_url: |
| 97 | + |
| 98 | + update: |
| 99 | + needs: release |
| 100 | + outputs: |
| 101 | + sha: ${{ steps.commit.outputs.sha }} |
| 102 | + check-id: ${{ steps.check.outputs.check_id }} |
| 103 | + name: Update - Release |
| 104 | + if: github.repository_owner == 'npm' && needs.release.outputs.pr |
| 105 | + runs-on: ubuntu-latest |
| 106 | + defaults: |
| 107 | + run: |
| 108 | + shell: bash |
| 109 | + steps: |
| 110 | + - name: Checkout |
| 111 | + uses: actions/checkout@v3 |
| 112 | + with: |
| 113 | + fetch-depth: 0 |
| 114 | + ref: ${{ needs.release.outputs.branch }} |
| 115 | + - name: Setup Git User |
| 116 | + run: | |
| 117 | + git config --global user.email "npm-cli+bot@github.com" |
| 118 | + git config --global user.name "npm CLI robot" |
| 119 | + - name: Setup Node |
| 120 | + uses: actions/setup-node@v3 |
| 121 | + with: |
| 122 | + node-version: 18.x |
| 123 | + - name: Install npm@latest |
| 124 | + run: npm i --prefer-online --no-fund --no-audit -g npm@latest |
| 125 | + - name: npm Version |
| 126 | + run: npm -v |
| 127 | + - name: Install Dependencies |
| 128 | + run: npm i --ignore-scripts --no-audit --no-fund |
| 129 | + - name: Run Post Pull Request Actions |
| 130 | + env: |
| 131 | + RELEASE_PR_NUMBER: ${{ needs.release.outputs.pr-number }} |
| 132 | + RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }} |
| 133 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 134 | + run: | |
| 135 | + npm run rp-pull-request --ignore-scripts -ws -iwr --if-present |
| 136 | + - name: Commit |
| 137 | + id: commit |
| 138 | + env: |
| 139 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + run: | |
| 141 | + git commit --all --amend --no-edit || true |
| 142 | + git push --force-with-lease |
| 143 | + echo "::set-output name=sha::$(git rev-parse HEAD)" |
| 144 | + - name: Create Check |
| 145 | + uses: LouisBrunner/checks-action@v1.3.1 |
| 146 | + id: check |
| 147 | + |
| 148 | + with: |
| 149 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 150 | + status: in_progress |
| 151 | + name: Release |
| 152 | + sha: ${{ steps.commit.outputs.sha }} |
| 153 | + # XXX: this does not work when using the default GITHUB_TOKEN. |
| 154 | + # Instead we post the main job url to the PR as a comment which |
| 155 | + # will link to all the other checks. To work around this we would |
| 156 | + # need to create a GitHub that would create on-demand tokens. |
| 157 | + # https://github.com/LouisBrunner/checks-action/issues/18 |
| 158 | + # details_url: |
| 159 | + - name: Conclude Check |
| 160 | + uses: LouisBrunner/checks-action@v1.3.1 |
| 161 | + if: always() |
| 162 | + with: |
| 163 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 164 | + conclusion: ${{ job.status }} |
| 165 | + check_id: ${{ needs.release.outputs.check-id }} |
| 166 | + |
| 167 | + ci: |
| 168 | + name: CI - Release |
| 169 | + needs: [ release, update ] |
| 170 | + if: needs.release.outputs.pr |
| 171 | + uses: ./.github/workflows/ci-release.yml |
| 172 | + with: |
| 173 | + ref: ${{ needs.release.outputs.branch }} |
| 174 | + check-sha: ${{ needs.update.outputs.sha }} |
| 175 | + |
| 176 | + post-ci: |
| 177 | + needs: [ release, update, ci ] |
| 178 | + name: Post CI - Release |
| 179 | + if: github.repository_owner == 'npm' && needs.release.outputs.pr && always() |
| 180 | + runs-on: ubuntu-latest |
| 181 | + defaults: |
| 182 | + run: |
| 183 | + shell: bash |
| 184 | + steps: |
| 185 | + - name: Get Needs Result |
| 186 | + id: needs-result |
| 187 | + run: | |
| 188 | + result="" |
| 189 | + if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then |
| 190 | + result="failure" |
| 191 | + elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then |
| 192 | + result="cancelled" |
| 193 | + else |
| 194 | + result="success" |
| 195 | + fi |
| 196 | + echo "::set-output name=result::$result" |
| 197 | + - name: Conclude Check |
| 198 | + uses: LouisBrunner/checks-action@v1.3.1 |
| 199 | + if: always() |
| 200 | + with: |
| 201 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 202 | + conclusion: ${{ steps.needs-result.outputs.result }} |
| 203 | + check_id: ${{ needs.update.outputs.check-id }} |
| 204 | + |
| 205 | + post-release: |
| 206 | + needs: release |
| 207 | + name: Post Release - Release |
| 208 | + if: github.repository_owner == 'npm' && needs.release.outputs.releases |
| 209 | + runs-on: ubuntu-latest |
| 210 | + defaults: |
| 211 | + run: |
| 212 | + shell: bash |
| 213 | + steps: |
| 214 | + - name: Checkout |
| 215 | + uses: actions/checkout@v3 |
| 216 | + - name: Setup Git User |
| 217 | + run: | |
| 218 | + git config --global user.email "npm-cli+bot@github.com" |
| 219 | + git config --global user.name "npm CLI robot" |
| 220 | + - name: Setup Node |
| 221 | + uses: actions/setup-node@v3 |
| 222 | + with: |
| 223 | + node-version: 18.x |
| 224 | + - name: Install npm@latest |
| 225 | + run: npm i --prefer-online --no-fund --no-audit -g npm@latest |
| 226 | + - name: npm Version |
| 227 | + run: npm -v |
| 228 | + - name: Install Dependencies |
| 229 | + run: npm i --ignore-scripts --no-audit --no-fund |
| 230 | + - name: Run Post Release Actions |
| 231 | + env: |
| 232 | + RELEASES: ${{ needs.release.outputs.releases }} |
| 233 | + run: | |
| 234 | + npm run rp-release --ignore-scripts --if-present ${{ join(fromJSON(needs.release.outputs.release-flags), ' ') }} |
0 commit comments