|
| 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:" |
0 commit comments