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

chore: add a check for go mod tidy #2481

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/scan-go-mod-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Validate Go Mod Tidy
on:
pull_request:
paths:
- "go.mod"
- "go.sum"

permissions:
contents: read

jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup golang
uses: ./.github/actions/golang

- name: Check go mod tidy
run: make test-go-mod-tidy

- name: Save logs
if: always()
uses: ./.github/actions/save-logs
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ repos:
files: .go$
language: system
pass_filenames: true
- id: check-go-mod-tidy
name: Check for out of sync Go module dependencies
entry: make test-go-mod-tidy
language: system
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.14.0
hooks:
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ test-docs-and-schema:
test-cves:
go run main.go tools sbom scan . -o json --exclude './site' --exclude './examples' | grype --fail-on low

# INTERNAL: used to test that a dev has ran `go mod tidy` in their PR
test-go-mod-tidy:
./hack/check-go-mod-tidy.sh

cve-report: ## Create a CVE report for the current project (must `brew install grype` first)
@test -d ./build || mkdir ./build
go run main.go tools sbom scan . -o json --exclude './site' --exclude './examples' | grype -o template -t hack/grype.tmpl > build/zarf-known-cves.csv
Expand Down
9 changes: 9 additions & 0 deletions hack/check-go-mod-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail

go mod tidy
if ! git diff --quiet go.mod go.sum; then
echo "ERROR: Changes detected after running 'go mod tidy'. Please run 'go mod tidy' and commit the changes."
exit 1
fi
Loading