From 3c227710431a16e7327f92d84b0b523e0f9ff7b8 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 7 Mar 2024 11:14:27 -0800 Subject: [PATCH] Ensure modules are current and tidy in CI (#22546) * Ensure modules are current and tidy in CI Fails the build if go.mod or go.sum isn't current. * only fail on diff --- eng/.golangci.yml | 2 ++ eng/pipelines/templates/steps/analyze.yml | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/eng/.golangci.yml b/eng/.golangci.yml index c02d708f5a68..a7a340547449 100644 --- a/eng/.golangci.yml +++ b/eng/.golangci.yml @@ -1,5 +1,7 @@ #reference https://github.com/golangci/golangci-lint#config-file for more options run: + # ensure that go.mod files are current + modules-download-mode: readonly # default is true. Enables skipping of directories: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs-use-default: true diff --git a/eng/pipelines/templates/steps/analyze.yml b/eng/pipelines/templates/steps/analyze.yml index e5e1393a2531..b7379fc74bb0 100644 --- a/eng/pipelines/templates/steps/analyze.yml +++ b/eng/pipelines/templates/steps/analyze.yml @@ -72,6 +72,21 @@ steps: failOnStderr: false workingDirectory: $(System.DefaultWorkingDirectory) + - pwsh: | + $modDirs = ./eng/scripts/get_module_dirs.ps1 '${{ parameters.ServiceDirectory }}' + foreach ($md in $modDirs) { + pushd $md + Write-Host "##[command]Executing go mod tidy in $md" + go mod tidy + $diff = (git diff -w .) + Write-Host ($diff -join "`n") + if ($diff.Length -gt 0) { + exit 1 + } + } + displayName: 'go mod tidy' + workingDirectory: $(System.DefaultWorkingDirectory) + - pwsh: | $modDirs = ./eng/scripts/get_module_dirs.ps1 '${{ parameters.ServiceDirectory }}' foreach ($md in $modDirs) {