|
| 1 | +# We've configured Renovate to open bump PRs for Angular dependencies within our |
| 2 | +# test fixtures. This workflow sends notifications when one of these PRs fails. |
| 3 | + |
| 4 | +name: Notify on Angular bump failures |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, labeled, unlabeled] |
| 9 | +jobs: |
| 10 | + waitForWorkflows: |
| 11 | + name: Wait for workflows |
| 12 | + runs-on: ubuntu-latest |
| 13 | + if: always() |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + ref: ${{ github.event.pull_request.head.sha }} |
| 19 | + |
| 20 | + - name: Wait for workflows |
| 21 | + id: wait |
| 22 | + uses: smartcontractkit/chainlink-github-actions/utils/wait-for-workflows@b49a9d04744b0237908831730f8553f26d73a94b |
| 23 | + with: |
| 24 | + max-timeout: '900' |
| 25 | + polling-interval: '30' |
| 26 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + notify-on-failure: |
| 28 | + name: Notify on failure |
| 29 | + needs: [waitForWorkflows] |
| 30 | + # Note that this doesn't imply success of the workflows themselves, just the waiting. |
| 31 | + if: needs.waitForWorkflows.result == 'success' |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + issues: write |
| 35 | + steps: |
| 36 | + - name: Check out the repository |
| 37 | + uses: actions/checkout@v4 |
| 38 | + - name: Check conditions for failure notification |
| 39 | + id: check_label |
| 40 | + uses: actions/github-script@v7 |
| 41 | + with: |
| 42 | + script: | |
| 43 | + const { owner, repo } = context.repo; |
| 44 | + const sha = context.payload.pull_request.head.sha; |
| 45 | + const prNumber = context.payload.pull_request.number; |
| 46 | +
|
| 47 | + // Get PR status, which is now settled |
| 48 | + const { data: {check_suites: checkSuites} } = await github.rest.checks.listSuitesForRef({ |
| 49 | + owner, |
| 50 | + repo, |
| 51 | + ref: sha |
| 52 | + }); |
| 53 | +
|
| 54 | + // Get current PR state and labels |
| 55 | + const { data: pullRequest } = await github.rest.pulls.get({ |
| 56 | + owner, |
| 57 | + repo, |
| 58 | + pull_number: prNumber, |
| 59 | + // Don't filter on `state` here so we can gracefuly handle an "expected" race |
| 60 | + // condition (PR closed between trigger and query) but still throw on unexpected errors. |
| 61 | + }); |
| 62 | + if (pullRequest == null) { |
| 63 | + core.setFailed("Aborting - cannot find PR corresponding to event trigger"); |
| 64 | + return; |
| 65 | + } |
| 66 | +
|
| 67 | + const prIsOpen = pullRequest.state === "open"; |
| 68 | + // NOTE: Technically, we should query both Check Suites and Commit Statuses. |
| 69 | + // We're assuming here that this repo exclusively uses the Checks API. |
| 70 | + const prDidFail = checkSuites.some(({conclusion}) => |
| 71 | + conclusion === "failure" || conclusion === "timed_out" |
| 72 | + ); |
| 73 | + // See `renovate.json5` at project root. |
| 74 | + const REQUIRED_LABEL = "bump-framework-in-fixtures"; |
| 75 | + const prHasRequiredLabel = pullRequest.labels.some(label => label.name === REQUIRED_LABEL); |
| 76 | + const shouldSendNotification = prIsOpen && prDidFail && prHasRequiredLabel; |
| 77 | + core.setOutput("should_send_notif", shouldSendNotification ? "true" : "false"); |
| 78 | + - name: Create issue on failure |
| 79 | + if: ${{ steps.check_label.outputs.should_send_notif == 'true' }} |
| 80 | + uses: actions/github-script@v7 |
| 81 | + with: |
| 82 | + script: | |
| 83 | + const ISSUE_LABEL = "framework-bump-failure"; |
| 84 | + const { owner, repo } = context.repo; |
| 85 | + const {data: issues} = await github.rest.issues.listForRepo({ |
| 86 | + owner, |
| 87 | + repo, |
| 88 | + state: "open", |
| 89 | + labels: [ISSUE_LABEL] |
| 90 | + }); |
| 91 | + if (issues.length > 0) { |
| 92 | + console.log(`Open issue already exists: ${issues[0].html_url}`); |
| 93 | + return; |
| 94 | + } |
| 95 | + const prUrl = context.payload.pull_request.html_url; |
| 96 | + const {data: issue} = await github.rest.issues.create({ |
| 97 | + owner, |
| 98 | + repo, |
| 99 | + title: "Possible regression with new framework release", |
| 100 | + labels: [ISSUE_LABEL], |
| 101 | + body: `A framework release bump in test fixtures has failed. Check ${prUrl}.` |
| 102 | + }); |
| 103 | + console.log(`Created issue: ${issue.html_url}`); |
0 commit comments