Dependabot Notifications #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Dependabot Notifications | |
| # This workflow sends Slack notifications when CI completes for Dependabot PRs. | |
| # It uses workflow_run to trigger AFTER the CI workflow finishes. | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| actions: read | |
| jobs: | |
| notify-success: | |
| name: Notify Success | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.actor.login == 'dependabot[bot]' | |
| steps: | |
| - name: Get PR information | |
| id: pr-info | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: pullRequests } = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}` | |
| }); | |
| if (pullRequests.length > 0) { | |
| const pr = pullRequests[0]; | |
| core.setOutput('pr_number', pr.number); | |
| core.setOutput('pr_title', pr.title); | |
| core.setOutput('pr_url', pr.html_url); | |
| core.setOutput('found', 'true'); | |
| } else { | |
| core.setOutput('found', 'false'); | |
| } | |
| - name: Send Slack notification (Success) | |
| if: steps.pr-info.outputs.found == 'true' | |
| run: | | |
| curl -X POST -H 'Content-type: application/json' --data '{ | |
| "attachments": [{ | |
| "color": "#36a64f", | |
| "blocks": [ | |
| { | |
| "type": "header", | |
| "text": {"type": "plain_text", "text": "✅ Dependabot Update - CI Passed", "emoji": true} | |
| }, | |
| { | |
| "type": "section", | |
| "fields": [ | |
| {"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"}, | |
| {"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}>"} | |
| ] | |
| }, | |
| { | |
| "type": "section", | |
| "text": {"type": "mrkdwn", "text": "${{ steps.pr-info.outputs.pr_title }}"} | |
| }, | |
| { | |
| "type": "context", | |
| "elements": [{"type": "mrkdwn", "text": "Auto-merge enabled • logzio-python-handler CI"}] | |
| } | |
| ] | |
| }] | |
| }' "$SLACK_WEBHOOK" | |
| env: | |
| SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
| notify-failure: | |
| name: Notify Failure | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.workflow_run.conclusion == 'failure' && | |
| github.event.workflow_run.actor.login == 'dependabot[bot]' | |
| steps: | |
| - name: Get PR information | |
| id: pr-info | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: pullRequests } = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}` | |
| }); | |
| if (pullRequests.length > 0) { | |
| const pr = pullRequests[0]; | |
| core.setOutput('pr_number', pr.number); | |
| core.setOutput('pr_title', pr.title); | |
| core.setOutput('pr_url', pr.html_url); | |
| core.setOutput('found', 'true'); | |
| } else { | |
| core.setOutput('found', 'false'); | |
| } | |
| - name: Get workflow run URL | |
| id: run-url | |
| run: | | |
| echo "url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}" >> $GITHUB_OUTPUT | |
| - name: Send Slack notification (Failure) | |
| if: steps.pr-info.outputs.found == 'true' | |
| run: | | |
| curl -X POST -H 'Content-type: application/json' --data '{ | |
| "attachments": [{ | |
| "color": "#ff0000", | |
| "blocks": [ | |
| { | |
| "type": "header", | |
| "text": {"type": "plain_text", "text": "🚨 Dependabot Update - CI Failed", "emoji": true} | |
| }, | |
| { | |
| "type": "section", | |
| "fields": [ | |
| {"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"}, | |
| {"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}>"} | |
| ] | |
| }, | |
| { | |
| "type": "section", | |
| "text": {"type": "mrkdwn", "text": "${{ steps.pr-info.outputs.pr_title }}\n\n<${{ steps.run-url.outputs.url }}|View CI Run> to investigate"} | |
| }, | |
| { | |
| "type": "context", | |
| "elements": [{"type": "mrkdwn", "text": "Manual intervention required • logzio-python-handler CI"}] | |
| } | |
| ] | |
| }] | |
| }' "$SLACK_WEBHOOK" | |
| env: | |
| SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
| notify-merged: | |
| name: Notify Merged | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| contains(github.event.workflow_run.head_commit.message, 'dependabot') | |
| steps: | |
| - name: Send Slack notification (Merged) | |
| run: | | |
| curl -X POST -H 'Content-type: application/json' --data '{ | |
| "attachments": [{ | |
| "color": "#2eb886", | |
| "blocks": [ | |
| { | |
| "type": "header", | |
| "text": {"type": "plain_text", "text": "🎉 Dependencies Updated Successfully", "emoji": true} | |
| }, | |
| { | |
| "type": "section", | |
| "fields": [ | |
| {"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"}, | |
| {"type": "mrkdwn", "text": "*Commit:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.workflow_run.head_sha }}|${{ github.event.workflow_run.head_sha }}>"} | |
| ] | |
| }, | |
| { | |
| "type": "context", | |
| "elements": [{"type": "mrkdwn", "text": "Merged to main • logzio-python-handler CI"}] | |
| } | |
| ] | |
| }] | |
| }' "$SLACK_WEBHOOK" | |
| env: | |
| SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |