|
26 | 26 | - run: pnpm install --frozen-lockfile |
27 | 27 |
|
28 | 28 | - run: pnpm test |
| 29 | + |
| 30 | + Yes, you can search for an existing open issue and add a comment instead of creating duplicates: |
| 31 | + |
| 32 | +```yaml |
| 33 | +name: Nightly Prettier Latest |
| 34 | +
|
| 35 | +on: |
| 36 | + schedule: |
| 37 | + - cron: '0 2 * * *' |
| 38 | + workflow_dispatch: |
| 39 | +
|
| 40 | +jobs: |
| 41 | + test-prettier-latest: |
| 42 | + runs-on: ubuntu-latest |
| 43 | +
|
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v6 |
| 46 | +
|
| 47 | + - uses: pnpm/action-setup@v4 |
| 48 | + with: |
| 49 | + run_install: false |
| 50 | +
|
| 51 | + - uses: actions/setup-node@v6 |
| 52 | + with: |
| 53 | + node-version: '24' |
| 54 | + cache: 'pnpm' |
| 55 | +
|
| 56 | + - run: pnpm add -D prettier@latest -w |
| 57 | +
|
| 58 | + - run: pnpm install --frozen-lockfile |
| 59 | +
|
| 60 | + - run: pnpm test |
| 61 | +
|
| 62 | + - name: Create or comment on issue |
| 63 | + if: failure() |
| 64 | + uses: actions/github-script@v8 |
| 65 | + with: |
| 66 | + script: | |
| 67 | + const issueTitle = 'Nightly Prettier Latest Test Failed'; |
| 68 | +
|
| 69 | + // Search for existing open issue |
| 70 | + const issues = await github.rest.issues.listForRepo({ |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + state: 'open', |
| 74 | + labels: ['automated', 'test-failure'] |
| 75 | + }); |
| 76 | +
|
| 77 | + const existingIssue = issues.data.find(issue => issue.title === issueTitle); |
| 78 | +
|
| 79 | + const body = `Test failed on run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 80 | + **Commit:** ${{ github.sha }} |
| 81 | + **Date:** ${new Date().toISOString()}`; |
| 82 | + |
| 83 | + if (existingIssue) { |
| 84 | + // Add comment to existing issue |
| 85 | + await github.rest.issues.createComment({ |
| 86 | + owner: context.repo.owner, |
| 87 | + repo: context.repo.repo, |
| 88 | + issue_number: existingIssue.number, |
| 89 | + body: body |
| 90 | + }); |
| 91 | + } else { |
| 92 | + // Create new issue |
| 93 | + await github.rest.issues.create({ |
| 94 | + owner: context.repo.owner, |
| 95 | + repo: context.repo.repo, |
| 96 | + title: issueTitle, |
| 97 | + body: body, |
| 98 | + labels: ['automated', 'test-failure'] |
| 99 | + }); |
| 100 | + } |
0 commit comments