From 898341ac03d2a6b96cf5028c2ea011a045727b93 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Tue, 5 Dec 2023 11:14:31 +0100 Subject: [PATCH 1/4] Add Dependabot recursive go mod tidy support --- .github/workflows/dependabot-tidy.yml | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/dependabot-tidy.yml diff --git a/.github/workflows/dependabot-tidy.yml b/.github/workflows/dependabot-tidy.yml new file mode 100644 index 00000000000..78567ae2d1f --- /dev/null +++ b/.github/workflows/dependabot-tidy.yml @@ -0,0 +1,49 @@ +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 + run: | + set -e + changes=$(git status --porcelain) + + if [ -n "$changes" ]; then + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + git add -A + git commit -m "Run 'go mod tidy' via GitHub Actions" && git push + else + echo "No changes to Go mods. Skipping commit" + fi From f1c78b0cda786b5b4c2b9b80eb5c4509b5aae1b6 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Tue, 5 Dec 2023 11:23:37 +0100 Subject: [PATCH 2/4] Don't run the tidy check on Dependabot PRs --- .github/workflows/misc.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/misc.yml b/.github/workflows/misc.yml index 64be9b4e829..9f138bcaa80 100644 --- a/.github/workflows/misc.yml +++ b/.github/workflows/misc.yml @@ -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 From 65ad24640edb3ef9b03ac6e106a113f53f93664a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20=C5=BDivkovi=C4=87?= Date: Thu, 21 Dec 2023 12:25:35 +0100 Subject: [PATCH 3/4] Update .github/workflows/dependabot-tidy.yml Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com> --- .github/workflows/dependabot-tidy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-tidy.yml b/.github/workflows/dependabot-tidy.yml index 78567ae2d1f..e8b4bab251c 100644 --- a/.github/workflows/dependabot-tidy.yml +++ b/.github/workflows/dependabot-tidy.yml @@ -43,7 +43,8 @@ jobs: git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" git add -A - git commit -m "Run 'go mod tidy' via GitHub Actions" && git push + git commit -m "Run 'go mod tidy' via GitHub Actions" + git push else echo "No changes to Go mods. Skipping commit" fi From 345a5cf8021eded12d2c5fb11549a196cf46ec7d Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Thu, 21 Dec 2023 12:36:28 +0100 Subject: [PATCH 4/4] Use action for committing changes --- .github/workflows/dependabot-tidy.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dependabot-tidy.yml b/.github/workflows/dependabot-tidy.yml index 78567ae2d1f..e13390fa831 100644 --- a/.github/workflows/dependabot-tidy.yml +++ b/.github/workflows/dependabot-tidy.yml @@ -34,16 +34,8 @@ jobs: (cd "$dir" && go mod tidy -v) || exit 1 done - - name: Commit changes - run: | - set -e - changes=$(git status --porcelain) - - if [ -n "$changes" ]; then - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - git add -A - git commit -m "Run 'go mod tidy' via GitHub Actions" && git push - else - echo "No changes to Go mods. Skipping commit" - fi + - 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"