Skip to content

Commit 146c2e5

Browse files
committed
Autobump of Go deps
1 parent cb82a60 commit 146c2e5

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

.github/workflows/autobump.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
branch_name=autobump
6+
repo=
7+
deps=()
8+
9+
function usage {
10+
cat 1>&2 <<-EOL
11+
12+
Usage: $0 [options]
13+
14+
Bumps given Golang deps within the project.
15+
16+
Options:
17+
18+
-b,--branch <branch-name> Which branch to use for bumping
19+
20+
-d,--dep <dep-name> List of dependencies to bump. Repeat the option to
21+
pass multiple IP addresses.
22+
23+
-r,--repo <repo> The GitHub repository to file the PRs to
24+
25+
EOL
26+
}
27+
28+
while [[ $# -gt 0 ]]; do
29+
case $1 in
30+
-b|--branch)
31+
branch_name="$2"
32+
shift
33+
shift
34+
;;
35+
-d|--dep)
36+
deps+=("$2")
37+
shift
38+
shift
39+
;;
40+
-r|--repo)
41+
repo="$2"
42+
shift
43+
shift
44+
;;
45+
-h|--help)
46+
usage
47+
exit 0
48+
;;
49+
*)
50+
error "Unknown option $1"
51+
usage
52+
exit 1
53+
;;
54+
esac
55+
done
56+
57+
pr="$(gh pr list --label 'ci/autobump' --author '@me' --repo "$repo" --json number --jq '.[].number')"
58+
59+
set -x
60+
61+
if (( pr )); then
62+
gh pr checkout --repo "$repo" "$pr"
63+
else
64+
git checkout -b "$branch_name"
65+
fi
66+
67+
for dep in "${deps[@]}"; do
68+
go get -u "$dep"
69+
done
70+
71+
go mod tidy
72+
go work sync
73+
git add .
74+
75+
if [ "$(git status --porcelain | wc -l)" -eq 0 ]; then
76+
echo 'no changes'
77+
exit 0
78+
fi
79+
80+
git commit -m 'Autobump of deps'
81+
82+
if (( pr )); then
83+
git push
84+
else
85+
gh pr create \
86+
--title ':robot: Autobump of deps' \
87+
--body 'This is automated PR' \
88+
--label 'skip-review' \
89+
--label 'kind/cleanup' \
90+
--label 'ci/autobump' \
91+
--repo "$repo"
92+
fi

.github/workflows/autobump.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Autobump
2+
3+
on:
4+
schedule:
5+
- cron: '30 2 * * 1-5'
6+
7+
jobs:
8+
autobump-go:
9+
name: Go
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- name: Install GH CLI
14+
uses: dev-hanz-ops/[email protected]
15+
16+
- uses: actions/checkout@v4
17+
18+
- name: Autobump
19+
run:
20+
.github/workflows/autobump.sh
21+
--repo ${{ github.repository }}
22+
--branch autobump/go
23+
--dep github.com/openshift-knative/hack

0 commit comments

Comments
 (0)