|
1 | 1 | name: Continuous Releases |
2 | 2 | on: |
3 | | - issue_comment: |
4 | | - types: [created] |
| 3 | + pull_request: |
| 4 | + types: |
| 5 | + - labeled |
5 | 6 |
|
6 | 7 | jobs: |
7 | 8 | build: |
8 | | - if: ${{ github.event.comment.body == '/preview' && github.event.issue.pull_request }} |
| 9 | + if: ${{ github.event.label.name == 'preview' }} |
9 | 10 | runs-on: ubuntu-latest |
10 | 11 |
|
11 | 12 | steps: |
|
25 | 26 | run: npm run build |
26 | 27 |
|
27 | 28 | - name: Publish packages |
28 | | - run: npx pkg-pr-new publish './packages/circuit-ui' './packages/design-tokens' './packages/icons' |
| 29 | + run: npx pkg-pr-new publish './packages/circuit-ui' './packages/design-tokens' './packages/icons' --json output.json --comment=off |
| 30 | + |
| 31 | + - name: Post or update comment |
| 32 | + uses: actions/github-script@v6 |
| 33 | + with: |
| 34 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + script: | |
| 36 | + const fs = require('fs'); |
| 37 | + const output = JSON.parse(fs.readFileSync('output.json', 'utf8')); |
| 38 | + console.log(output); |
| 39 | + |
| 40 | + const packages = output.packages |
| 41 | + .map((p) => `- ${p.name}: ${p.url}`) |
| 42 | + .join('\n'); |
| 43 | + |
| 44 | + const sha = context.payload.pull_request.head.sha |
| 45 | + |
| 46 | + const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`; |
| 47 | + |
| 48 | + const body = `## 🚀 Your packages were published |
| 49 | + |
| 50 | + ### Published Packages: |
| 51 | + |
| 52 | + ${packages} |
| 53 | + |
| 54 | + [View Commit](${commitUrl})`; |
| 55 | + |
| 56 | + const botCommentIdentifier = '## 🚀 Your packages were published '; |
| 57 | + |
| 58 | + async function findBotComment(issueNumber) { |
| 59 | + if (!issueNumber) return null; |
| 60 | + const comments = await github.rest.issues.listComments({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + issue_number: issueNumber, |
| 64 | + }); |
| 65 | + return comments.data.find((comment) => |
| 66 | + comment.body.includes(botCommentIdentifier) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + async function createOrUpdateComment(issueNumber) { |
| 71 | + if (!issueNumber) { |
| 72 | + console.log('No issue number provided. Cannot post or update comment.'); |
| 73 | + return; |
| 74 | + } |
| 75 | + |
| 76 | + const existingComment = await findBotComment(issueNumber); |
| 77 | + if (existingComment) { |
| 78 | + await github.rest.issues.updateComment({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + comment_id: existingComment.id, |
| 82 | + body: body, |
| 83 | + }); |
| 84 | + } else { |
| 85 | + await github.rest.issues.createComment({ |
| 86 | + issue_number: issueNumber, |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + body: body, |
| 90 | + }); |
| 91 | + } |
| 92 | + } |
| 93 | + if (context.issue.number) { |
| 94 | + await createOrUpdateComment(context.issue.number); |
| 95 | + } |
| 96 | + |
| 97 | + - name: Delete label |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + PR_NUMBER: |
| 101 | + ${{ github.event.pull_request.number }} |
| 102 | + run: | |
| 103 | + gh pr edit $PR_NUMBER --remove-label "preview" |
0 commit comments