Skip to content

Commit 30bf1f3

Browse files
author
Chris Gilmer
committed
Add auto-approve step for go code by dependabot
1 parent fa469ec commit 30bf1f3

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

.github/workflows/go-auto-approve.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: auto approve and tidy
2+
on:
3+
pull_request:
4+
paths:
5+
- '.github/workflows/gosum.yml'
6+
- 'go.mod'
7+
- 'go.sum'
8+
9+
# job level conditions don't seem to work at the moment
10+
# https://github.community/t5/GitHub-Actions/Status-of-workflows-with-no-running-jobs/td-p/37160
11+
# which is why github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' is
12+
# repeated over and over
13+
jobs:
14+
tidy:
15+
name: run go mod tidy and updated
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: checkout
19+
uses: actions/checkout@v1
20+
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
21+
- name: reattach HEAD to Head Ref
22+
# b/c checkout action leaves in detached head state https://github.com/actions/checkout/issues/6
23+
run: git checkout "$(echo ${{ github.head_ref }})"
24+
if: github.head_ref != '' && (github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
25+
- name: setup go
26+
uses: actions/setup-go@v1
27+
with:
28+
go-version: '1.14'
29+
- name: Tidy
30+
run: |
31+
go version
32+
go mod tidy
33+
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
34+
- name: set up Git
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: |
38+
git config user.name "${GITHUB_ACTOR}"
39+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
40+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
41+
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
42+
- name: commit and push changes
43+
run: |
44+
git add .
45+
if output=$(git status --porcelain) && [ ! -z "$output" ]; then
46+
git commit -m 'Fix go modules'
47+
git push
48+
fi
49+
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
50+
approve:
51+
name: auto-approve dependabot PRs
52+
runs-on: ubuntu-latest
53+
needs: [tidy]
54+
steps:
55+
- name: approve
56+
uses: hmarr/[email protected]
57+
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
58+
with:
59+
github-token: "${{ secrets.GITHUB_TOKEN }}"

0 commit comments

Comments
 (0)