|
| 1 | +# Adapted from create-t3-app. |
| 2 | +name: Write Beta Release comment |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_run: |
| 6 | + workflows: ["Release - Beta"] |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +jobs: |
| 11 | + comment: |
| 12 | + if: | |
| 13 | + github.repository_owner == 'shadcn-ui' && |
| 14 | + ${{ github.event.workflow_run.conclusion == 'success' }} |
| 15 | + runs-on: ubuntu-latest |
| 16 | + name: Write comment to the PR |
| 17 | + steps: |
| 18 | + - name: "Comment on PR" |
| 19 | + uses: actions/github-script@v6 |
| 20 | + with: |
| 21 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + script: | |
| 23 | + const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 24 | + owner: context.repo.owner, |
| 25 | + repo: context.repo.repo, |
| 26 | + run_id: context.payload.workflow_run.id, |
| 27 | + }); |
| 28 | +
|
| 29 | + for (const artifact of allArtifacts.data.artifacts) { |
| 30 | + // Extract the PR number and package version from the artifact name |
| 31 | + const match = /^npm-package-shadcn-ui@(.*?)-pr-(\d+)/.exec(artifact.name); |
| 32 | + |
| 33 | + if (match) { |
| 34 | + require("fs").appendFileSync( |
| 35 | + process.env.GITHUB_ENV, |
| 36 | + `\nBETA_PACKAGE_VERSION=${match[1]}` + |
| 37 | + `\nWORKFLOW_RUN_PR=${match[2]}` + |
| 38 | + `\nWORKFLOW_RUN_ID=${context.payload.workflow_run.id}` |
| 39 | + ); |
| 40 | + break; |
| 41 | + } |
| 42 | + } |
| 43 | +
|
| 44 | + - name: "Comment on PR with Link" |
| 45 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 46 | + with: |
| 47 | + number: ${{ env.WORKFLOW_RUN_PR }} |
| 48 | + message: | |
| 49 | + A new prerelease is available for testing: |
| 50 | +
|
| 51 | + ```sh |
| 52 | + npx shadcn-ui@${{ env.BETA_PACKAGE_VERSION }} |
| 53 | + ``` |
| 54 | +
|
| 55 | + - name: "Remove the autorelease label once published" |
| 56 | + uses: actions/github-script@v6 |
| 57 | + with: |
| 58 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + script: | |
| 60 | + github.rest.issues.removeLabel({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + issue_number: '${{ env.WORKFLOW_RUN_PR }}', |
| 64 | + name: '🚀 autorelease', |
| 65 | + }); |
0 commit comments