Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add Dependabot recursive go mod tidy support #1412

Merged
merged 8 commits into from
Dec 21, 2023
41 changes: 41 additions & 0 deletions .github/workflows/dependabot-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Dependabot Tidy Go Mods

on:
pull_request:
paths:
- '.github/workflows/**'
- '**/go.mod'
- '**/go.sum'

jobs:
tidy_go_mods:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x

- name: Tidy all Go mods
run: |
set -e
# Find all go.mod files
gomods=$(find . -type f -name go.mod)

# Tidy each go.mod file
for modfile in $gomods; do
dir=$(dirname "$modfile")

# Run go mod tidy in the directory
(cd "$dir" && go mod tidy -v) || exit 1
done

- name: Commit changes, if any
uses: stefanzweifel/git-auto-commit-action@v5
with:
skip_dirty_check: false # Enable dirty check, and skip unnecessary committing
commit_message: "Run 'go mod tidy' via GitHub Actions"
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ jobs:
else
echo 'Succeeded.'
fi
modtidy:
mod_tidy_check:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
Loading