diff --git a/.github/workflows/autobump.sh b/.github/workflows/autobump.sh new file mode 100755 index 0000000..cc4c392 --- /dev/null +++ b/.github/workflows/autobump.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +branch_name=autobump +repo= +deps=() + +function usage { + cat 1>&2 <<-EOL + +Usage: $0 [options] + +Bumps given Golang deps within the project. + +Options: + + -b,--branch Which branch to use for bumping + + -d,--dep List of dependencies to bump. Repeat the option to + pass multiple IP addresses. + + -r,--repo The GitHub repository to file the PRs to + +EOL +} + +while [[ $# -gt 0 ]]; do + case $1 in + -b|--branch) + branch_name="$2" + shift + shift + ;; + -d|--dep) + deps+=("$2") + shift + shift + ;; + -r|--repo) + repo="$2" + shift + shift + ;; + -h|--help) + usage + exit 0 + ;; + *) + error "Unknown option $1" + usage + exit 1 + ;; + esac +done + +pr="$(gh pr list --label 'ci/autobump' --author '@me' --repo "$repo" --json number --jq '.[].number')" + +set -x + +if (( pr )); then + gh pr checkout --repo "$repo" "$pr" +else + git checkout -b "$branch_name" +fi + +for dep in "${deps[@]}"; do + go get -u "$dep" +done + +go mod tidy +go work sync +git add . + +if [ "$(git status --porcelain | wc -l)" -eq 0 ]; then + echo 'no changes' + exit 0 +fi + +git commit -m 'Autobump of deps' + +if (( pr )); then + git push +else + gh pr create \ + --title ':robot: Autobump of deps' \ + --body 'This is automated PR' \ + --label 'skip-review' \ + --label 'kind/cleanup' \ + --label 'ci/autobump' \ + --repo "$repo" +fi diff --git a/.github/workflows/autobump.yaml b/.github/workflows/autobump.yaml new file mode 100644 index 0000000..7a57053 --- /dev/null +++ b/.github/workflows/autobump.yaml @@ -0,0 +1,23 @@ +name: Autobump + +on: + schedule: + - cron: '30 2 * * 1-5' + +jobs: + autobump-go: + name: Go + runs-on: ubuntu-latest + steps: + + - name: Install GH CLI + uses: dev-hanz-ops/install-gh-cli-action@v0.2.1 + + - uses: actions/checkout@v4 + + - name: Autobump + run: + .github/workflows/autobump.sh + --repo ${{ github.repository }} + --branch autobump/go + --dep github.com/openshift-knative/hack