Skip to content

Commit f0fa28c

Browse files
committed
.github/workflows: add dependabump
1 parent 29c0bf1 commit f0fa28c

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

.github/workflows/dependabump.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: dependabump.yml
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '0 0 * * 1-5' # every week-day at midnight
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
actions: read
11+
12+
jobs:
13+
dependabump:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v5
18+
with:
19+
ref: main
20+
21+
- name: Bump Dependencies
22+
run: make dependabot
23+
24+
- name: Detect Changes
25+
id: changes
26+
run: |
27+
git add --all
28+
git diff --cached --exit-code
29+
echo "exit_code=$?" >> "$GITHUB_OUTPUT"
30+
continue-on-error: true
31+
32+
- name: Notify Fatal Error
33+
if: !contains([0,1], steps.changes.outputs.exit_code != '0' ) # Fatal exit code
34+
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
35+
with:
36+
method: chat.postMessage
37+
token: ${{ secrets.QA_SLACK_API_KEY }}
38+
payload: |
39+
channel: ${{ secrets.SLACK_TEAM_CORE_CHANNEL_ID}}
40+
text: "Failed to run dependabump: <${{ format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }}|Run>"
41+
42+
- if: !contains([0,1], steps.changes.outputs.exit_code != '0' ) # Fatal exit code
43+
run: exit 1
44+
45+
- name: Create Pull Request & Notify
46+
id: pr
47+
if: steps.changes.outputs.exit_code == '1' # Changes detected
48+
run: |
49+
git switch -c dependabump/${{ GITHUB_EVENT_NAME }}-${{ GITHUB_RUN_ID }}
50+
# TODO how to sign verified commit?
51+
git commit -m "bump dependencies"
52+
git push -u origin dependabump/${{ GITHUB_EVENT_NAME }}-${{ GITHUB_RUN_ID }}
53+
gh pr create --base main --title "dependabump" --body "Bumping deps due to critical or high vulnerabilities." | gh variable set url --body -
54+
echo "exit_code=$?" >> "$GITHUB_OUTPUT"
55+
# TODO (close stale dependabump/ branches?)
56+
continue-on-error: true # Still notify
57+
58+
- name: Notify PR Failure
59+
if: steps.changes.outputs.exit_code == '1' && steps.pr.outputs.exit_code != '0' # Changes detected but failed to create PR
60+
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
61+
with:
62+
method: chat.postMessage
63+
token: ${{ secrets.QA_SLACK_API_KEY }}
64+
payload: |
65+
channel: ${{ secrets.SLACK_TEAM_CORE_CHANNEL_ID}}
66+
text: "Changes detected by dependabump, but failed to create PR: <${{ format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }}|Run>"
67+
68+
- if: steps.changes.outputs.exit_code == '1' && steps.pr.outputs.exit_code != '0' # Changes detected but failed to create PR
69+
run: exit 1
70+
71+
- name: Notify PR Created
72+
if: steps.changes.outputs.exit_code == '1' && steps.pr.outputs.exit_code == '0' # Changes detected and PR created
73+
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
74+
with:
75+
method: chat.postMessage
76+
token: ${{ secrets.QA_SLACK_API_KEY }}
77+
payload: |
78+
channel: ${{ secrets.SLACK_TEAM_CORE_CHANNEL_ID}}
79+
text: "Changes detected by dependabump: <${{ format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }}|Run> - <${gh.variable.url}|PR> :review_time:"

0 commit comments

Comments
 (0)