Skip to content

Commit 8966a23

Browse files
authored
Fix: [AEA-0000] - add workflow dependabot (#5)
## Summary - Routine Change ### Details - add workflow dependabot workflows
1 parent ad79b8f commit 8966a23

File tree

3 files changed

+129
-1
lines changed

3 files changed

+129
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: "Combine PRs"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
branchPrefix:
7+
description: "Branch prefix to find combinable PRs based on"
8+
default: "dependabot"
9+
type: string
10+
mustBeGreen:
11+
description: "Only combine PRs that are green (status is success)"
12+
default: true
13+
type: boolean
14+
combineBranchName:
15+
description: "Name of the branch to combine PRs into"
16+
default: "combine-dependabot-PRs"
17+
type: string
18+
ignoreLabel:
19+
description: "Exclude PRs with this label"
20+
default: "nocombine"
21+
type: string
22+
23+
# Allow manual triggering of the workflow for this repo
24+
workflow_dispatch:
25+
inputs:
26+
branchPrefix:
27+
description: "Branch prefix to find combinable PRs based on"
28+
default: "dependabot"
29+
type: string
30+
mustBeGreen:
31+
description: "Only combine PRs that are green (status is success)"
32+
default: true
33+
type: boolean
34+
combineBranchName:
35+
description: "Name of the branch to combine PRs into"
36+
default: "combine-dependabot-PRs"
37+
type: string
38+
ignoreLabel:
39+
description: "Exclude PRs with this label"
40+
default: "nocombine"
41+
type: string
42+
43+
jobs:
44+
combine-prs:
45+
runs-on: ubuntu-22.04
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
49+
with:
50+
repository: NHSDigital/eps-workflow-dependabot
51+
sparse-checkout-cone-mode: false
52+
sparse-checkout: |
53+
combine-prs.js
54+
55+
- name: Create Combined PR
56+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
57+
id: create-combined-pr
58+
env:
59+
branchPrefix: ${{ inputs.branchPrefix }}
60+
mustBeGreen: ${{ inputs.mustBeGreen }}
61+
combineBranchName: ${{ inputs.combineBranchName }}
62+
ignoreLabel: ${{ inputs.ignoreLabel }}
63+
with:
64+
github-token: ${{secrets.GITHUB_TOKEN}}
65+
script: |
66+
const combinePRs = require('./combine-prs.js');
67+
await combinePRs({ github, context, core });
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Dependabot auto-approve
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
AUTOMERGE_APP_ID:
7+
required: true
8+
AUTOMERGE_PEM:
9+
required: true
10+
11+
permissions:
12+
pull-requests: write
13+
contents: write
14+
15+
jobs:
16+
dependabot:
17+
runs-on: ubuntu-22.04
18+
if: ${{ github.actor == 'dependabot[bot]' }}
19+
steps:
20+
- name: Get token from Github App
21+
id: get_app_token
22+
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42
23+
with:
24+
app-id: ${{ secrets.AUTOMERGE_APP_ID }}
25+
private-key: ${{ secrets.AUTOMERGE_PEM }}
26+
27+
- name: Dependabot metadata
28+
id: dependabot-metadata
29+
uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b
30+
with:
31+
github-token: "${{ secrets.GITHUB_TOKEN }}"
32+
33+
- name: Approve patch and minor updates
34+
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' || steps.dependabot-metadata.outputs.update-type == 'version-update:semver-minor'}}
35+
run: gh pr review "$PR_URL" --approve -b "I'm **approving** this pull request because **it includes a patch or minor update**"
36+
env:
37+
PR_URL: ${{github.event.pull_request.html_url}}
38+
GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }}
39+
40+
- name: Approve major updates of development dependencies
41+
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:development'}}
42+
run: gh pr review "$PR_URL" --approve -b "I'm **approving** this pull request because **it includes a major update of a dependency used only in development**"
43+
env:
44+
PR_URL: ${{github.event.pull_request.html_url}}
45+
GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }}
46+
47+
- name: Comment on major updates of non-development dependencies
48+
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:production'}}
49+
run: |
50+
gh pr comment "$PR_URL" --body "I'm **not approving** this PR because **it includes a major update of a dependency used in production**"
51+
gh pr edit "$PR_URL" --add-label "requires-manual-qa"
52+
env:
53+
PR_URL: ${{github.event.pull_request.html_url}}
54+
GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }}
55+
56+
# enable auto merge on all dependabot prs
57+
- name: Enable auto-merge for Dependabot PRs
58+
run: gh pr merge --auto --squash "$PR_URL"
59+
env:
60+
PR_URL: ${{github.event.pull_request.html_url}}
61+
GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }}

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
jobs:
1111
dependabot-auto-approve-and-merge:
1212
needs: quality_checks
13-
uses: NHSDigital/eps-workflow-dependabot/.github/workflows/dependabot-auto-approve-and-merge.yml@4b56ed8edd7c5357fd0123a2bd84b3429d3a6b20
13+
uses: ./.github/workflows/dependabot-auto-approve-and-merge.yml
1414
secrets:
1515
AUTOMERGE_APP_ID: ${{ secrets.AUTOMERGE_APP_ID }}
1616
AUTOMERGE_PEM: ${{ secrets.AUTOMERGE_PEM }}

0 commit comments

Comments
 (0)