Skip to content

Commit f9b2bff

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

2 files changed

Lines changed: 90 additions & 2 deletions

File tree

.github/workflows/dependabump.yml

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

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ DEPENDABOT_SEVERITY := "critical,high"
6666
endif
6767
dependabot: gomods
6868
gh api --paginate -H "Accept: application/vnd.github+json" --method GET \
69-
'/repos/smartcontractkit/chainlink-common/dependabot/alerts?state=open&ecosystem=Go&severity=$(DEPENDABOT_SEVERITY)' | \
70-
jq -r '.[] | select(.security_vulnerability.first_patched_version != null) | .dependency.manifest_path |= rtrimstr("go.mod") | "./\(.dependency.manifest_path) \(.security_vulnerability.package.name) \(.security_vulnerability.first_patched_version.identifier)"' | \
69+
'/repos/smartcontractkit/chainlink-common/dependabot/alerts?state=open&ecosystem=Go&severity=$(DEPENDABOT_SEVERITY)' \
70+
--jq '.[] | select(.security_vulnerability.first_patched_version != null) | .dependency.manifest_path |= rtrimstr("go.mod") | "./\(.dependency.manifest_path) \(.security_vulnerability.package.name) \(.security_vulnerability.first_patched_version.identifier)"' | \
7171
go run ./script/cmd/dependabot
7272
gomods tidy

0 commit comments

Comments
 (0)