|
| 1 | +name: Dependabot Notifications |
| 2 | + |
| 3 | +# This workflow sends Slack notifications when CI completes for Dependabot PRs. |
| 4 | +# It uses workflow_run to trigger AFTER the CI workflow finishes. |
| 5 | + |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_run: |
| 9 | + workflows: ["CI"] |
| 10 | + types: |
| 11 | + - completed |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + pull-requests: read |
| 16 | + actions: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + notify-success: |
| 20 | + name: Notify Success |
| 21 | + runs-on: ubuntu-latest |
| 22 | + if: | |
| 23 | + github.event.workflow_run.conclusion == 'success' && |
| 24 | + github.event.workflow_run.actor.login == 'dependabot[bot]' |
| 25 | +
|
| 26 | + steps: |
| 27 | + - name: Get PR information |
| 28 | + id: pr-info |
| 29 | + uses: actions/github-script@v7 |
| 30 | + with: |
| 31 | + script: | |
| 32 | + const { data: pullRequests } = await github.rest.pulls.list({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + state: 'open', |
| 36 | + head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}` |
| 37 | + }); |
| 38 | + |
| 39 | + if (pullRequests.length > 0) { |
| 40 | + const pr = pullRequests[0]; |
| 41 | + core.setOutput('pr_number', pr.number); |
| 42 | + core.setOutput('pr_title', pr.title); |
| 43 | + core.setOutput('pr_url', pr.html_url); |
| 44 | + core.setOutput('found', 'true'); |
| 45 | + } else { |
| 46 | + core.setOutput('found', 'false'); |
| 47 | + } |
| 48 | +
|
| 49 | + - name: Send Slack notification (Success) |
| 50 | + if: steps.pr-info.outputs.found == 'true' |
| 51 | + run: | |
| 52 | + curl -X POST -H 'Content-type: application/json' --data '{ |
| 53 | + "attachments": [{ |
| 54 | + "color": "#36a64f", |
| 55 | + "blocks": [ |
| 56 | + { |
| 57 | + "type": "header", |
| 58 | + "text": {"type": "plain_text", "text": "✅ Dependabot Update - CI Passed", "emoji": true} |
| 59 | + }, |
| 60 | + { |
| 61 | + "type": "section", |
| 62 | + "fields": [ |
| 63 | + {"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"}, |
| 64 | + {"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}>"} |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "type": "section", |
| 69 | + "text": {"type": "mrkdwn", "text": "${{ steps.pr-info.outputs.pr_title }}"} |
| 70 | + }, |
| 71 | + { |
| 72 | + "type": "context", |
| 73 | + "elements": [{"type": "mrkdwn", "text": "Auto-merge enabled • logzio-python-handler CI"}] |
| 74 | + } |
| 75 | + ] |
| 76 | + }] |
| 77 | + }' "$SLACK_WEBHOOK" |
| 78 | + env: |
| 79 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 80 | + |
| 81 | + |
| 82 | + notify-failure: |
| 83 | + name: Notify Failure |
| 84 | + runs-on: ubuntu-latest |
| 85 | + if: | |
| 86 | + github.event.workflow_run.conclusion == 'failure' && |
| 87 | + github.event.workflow_run.actor.login == 'dependabot[bot]' |
| 88 | +
|
| 89 | + steps: |
| 90 | + - name: Get PR information |
| 91 | + id: pr-info |
| 92 | + uses: actions/github-script@v7 |
| 93 | + with: |
| 94 | + script: | |
| 95 | + const { data: pullRequests } = await github.rest.pulls.list({ |
| 96 | + owner: context.repo.owner, |
| 97 | + repo: context.repo.repo, |
| 98 | + state: 'open', |
| 99 | + head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}` |
| 100 | + }); |
| 101 | + |
| 102 | + if (pullRequests.length > 0) { |
| 103 | + const pr = pullRequests[0]; |
| 104 | + core.setOutput('pr_number', pr.number); |
| 105 | + core.setOutput('pr_title', pr.title); |
| 106 | + core.setOutput('pr_url', pr.html_url); |
| 107 | + core.setOutput('found', 'true'); |
| 108 | + } else { |
| 109 | + core.setOutput('found', 'false'); |
| 110 | + } |
| 111 | +
|
| 112 | + - name: Get workflow run URL |
| 113 | + id: run-url |
| 114 | + run: | |
| 115 | + echo "url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}" >> $GITHUB_OUTPUT |
| 116 | +
|
| 117 | + - name: Send Slack notification (Failure) |
| 118 | + if: steps.pr-info.outputs.found == 'true' |
| 119 | + run: | |
| 120 | + curl -X POST -H 'Content-type: application/json' --data '{ |
| 121 | + "attachments": [{ |
| 122 | + "color": "#ff0000", |
| 123 | + "blocks": [ |
| 124 | + { |
| 125 | + "type": "header", |
| 126 | + "text": {"type": "plain_text", "text": "🚨 Dependabot Update - CI Failed", "emoji": true} |
| 127 | + }, |
| 128 | + { |
| 129 | + "type": "section", |
| 130 | + "fields": [ |
| 131 | + {"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"}, |
| 132 | + {"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}>"} |
| 133 | + ] |
| 134 | + }, |
| 135 | + { |
| 136 | + "type": "section", |
| 137 | + "text": {"type": "mrkdwn", "text": "${{ steps.pr-info.outputs.pr_title }}\n\n<${{ steps.run-url.outputs.url }}|View CI Run> to investigate"} |
| 138 | + }, |
| 139 | + { |
| 140 | + "type": "context", |
| 141 | + "elements": [{"type": "mrkdwn", "text": "Manual intervention required • logzio-python-handler CI"}] |
| 142 | + } |
| 143 | + ] |
| 144 | + }] |
| 145 | + }' "$SLACK_WEBHOOK" |
| 146 | + env: |
| 147 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 148 | + |
| 149 | + notify-merged: |
| 150 | + name: Notify Merged |
| 151 | + runs-on: ubuntu-latest |
| 152 | + if: | |
| 153 | + github.event.workflow_run.conclusion == 'success' && |
| 154 | + github.event.workflow_run.event == 'push' && |
| 155 | + contains(github.event.workflow_run.head_commit.message, 'dependabot') |
| 156 | +
|
| 157 | + steps: |
| 158 | + - name: Send Slack notification (Merged) |
| 159 | + run: | |
| 160 | + curl -X POST -H 'Content-type: application/json' --data '{ |
| 161 | + "attachments": [{ |
| 162 | + "color": "#2eb886", |
| 163 | + "blocks": [ |
| 164 | + { |
| 165 | + "type": "header", |
| 166 | + "text": {"type": "plain_text", "text": "🎉 Dependencies Updated Successfully", "emoji": true} |
| 167 | + }, |
| 168 | + { |
| 169 | + "type": "section", |
| 170 | + "fields": [ |
| 171 | + {"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"}, |
| 172 | + {"type": "mrkdwn", "text": "*Commit:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.workflow_run.head_sha }}|${{ github.event.workflow_run.head_sha }}>"} |
| 173 | + ] |
| 174 | + }, |
| 175 | + { |
| 176 | + "type": "context", |
| 177 | + "elements": [{"type": "mrkdwn", "text": "Merged to main • logzio-python-handler CI"}] |
| 178 | + } |
| 179 | + ] |
| 180 | + }] |
| 181 | + }' "$SLACK_WEBHOOK" |
| 182 | + env: |
| 183 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 184 | + |
0 commit comments