From: Bjørn Erik Pedersen Date: Thu, 29 Jan 2026 12:23:19 +0000 (+0100) Subject: Add ./check.sh script X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=d67925f5a1f596f2257d286ea97eb7fa2b025948;p=brevno-suite%2Fhugo Add ./check.sh script Running `mage check` takes too long time for user (and agent) iterations. That will eventualy run on CI. This is a faster version that: * Checks gofmt. * Runs go vet. * Runs staticcheck. * Runs unit tests without the race flag. It assumes that Go is installed, but will check if staticcheck is available and install it if not with go install. It takes an optional argument to specify packages to check, otherwise it checks all packages. This commit also enable local runs of the image golden tests. --- diff --git a/AGENTS.md b/AGENTS.md index 365cef232..8cdf9fdb1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,8 @@ * Never export symbols that's not needed outside of the package. * Avoid global state at (almost) all cost. * This is a project with a long history; assume that a similiar problem has been solved before, look hard for helper functions before creating new ones. -* Use `go test ./somepackage/...` when iterating. -* Use `mage check` when you're done. +* Use `./check.sh ./somepackage/...` when iterating. +* Use `./check.sh` when you're done. + [^1]: CI build fail if you forget to remove the debug printing. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3cefd04c4..c672637ce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,7 +77,7 @@ To make the contribution process as seamless as possible, we ask for the followi * Run `go fmt`. * Add documentation if you are adding new features or changing functionality. The docs site lives in `/docs`. * Squash your commits into a single commit. `git rebase -i`. It’s okay to force update your pull request with `git push -f`. - * Ensure that `mage check` succeeds. [Travis CI](https://travis-ci.org/gohugoio/hugo) (Windows, Linux and macOS) will fail the build if `mage check` fails. + * Ensure that `./check.sh` succeeds. Note that some tests are skipped when running locally, some because they are slow. To run these locally, do `CI_LOCAL=true ./check.sh ./somepackage/...`. * Follow the **Git Commit Message Guidelines** below. ## AI Assistance Notice diff --git a/check.sh b/check.sh new file mode 100755 index 000000000..53d4fe6a5 --- /dev/null +++ b/check.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +set -e + +# Default to all packages if none specified +PACKAGES="${1:-./...}" + +echo "==> Checking packages: $PACKAGES" + +# Timing arrays +declare -a STEP_NAMES +declare -a STEP_TIMES + +time_step() { + local name="$1" + shift + local start=$(date +%s.%N) + "$@" + local end=$(date +%s.%N) + local elapsed=$(echo "$end - $start" | bc) + STEP_NAMES+=("$name") + STEP_TIMES+=("$elapsed") +} + +# Check gofmt +run_gofmt() { + echo "==> Running gofmt..." + # Convert package pattern to path (e.g., ./hugolib/... -> ./hugolib) + local path="${PACKAGES%/...}" + GOFMT_OUTPUT=$(gofmt -l "$path" 2>&1) || true + if [ -n "$GOFMT_OUTPUT" ]; then + echo "gofmt found issues in:" + echo "$GOFMT_OUTPUT" + exit 1 + fi + echo " OK" +} + +# Run go vet +run_govet() { + echo "==> Running go vet..." + go vet $PACKAGES + echo " OK" +} + +# Run staticcheck +run_staticcheck() { + # Check if staticcheck is installed, install if not + if ! command -v staticcheck &> /dev/null; then + echo "==> Installing staticcheck..." + go install honnef.co/go/tools/cmd/staticcheck@latest + fi + echo "==> Running staticcheck..." + staticcheck $PACKAGES + echo " OK" +} + +# Run tests +run_tests() { + echo "==> Running tests..." + local output + if ! output=$(go test $PACKAGES 2>&1); then + echo "$output" + exit 1 + fi + echo " OK" +} + +# Run all steps with timing +TOTAL_START=$(date +%s.%N) + +time_step "gofmt" run_gofmt +time_step "go vet" run_govet +time_step "staticcheck" run_staticcheck +time_step "tests" run_tests + +TOTAL_END=$(date +%s.%N) +TOTAL_ELAPSED=$(echo "$TOTAL_END - $TOTAL_START" | bc) + +# Print timing summary +echo "" +echo "==> All checks passed!" +echo "" +echo "Timing summary:" +echo "---------------" +for i in "${!STEP_NAMES[@]}"; do + printf " %-15s %6.2fs\n" "${STEP_NAMES[$i]}" "${STEP_TIMES[$i]}" +done +echo "---------------" +printf " %-15s %6.2fs\n" "Total" "$TOTAL_ELAPSED" diff --git a/resources/images/images_golden_integration_test.go b/resources/images/images_golden_integration_test.go index ac147a287..6b6b41e41 100644 --- a/resources/images/images_golden_integration_test.go +++ b/resources/images/images_golden_integration_test.go @@ -18,7 +18,6 @@ import ( "strings" "testing" - "github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/resources/images/imagetesting" ) @@ -36,7 +35,6 @@ const goldenProcess = ` // Note, if you're enabling writeGoldenFiles on a MacOS ARM 64 you need to run the test with GOARCH=amd64, e.g. func TestImagesGoldenFiltersMisc(t *testing.T) { t.Parallel() - htesting.SkipSlowTestUnlessCI(t) if imagetesting.SkipGoldenTests { t.Skip("Skip golden test on this architecture") @@ -113,7 +111,6 @@ Home. func TestImagesGoldenFiltersMask(t *testing.T) { t.Parallel() - htesting.SkipSlowTestUnlessCI(t) if imagetesting.SkipGoldenTests { t.Skip("Skip golden test on this architecture") @@ -175,7 +172,6 @@ the last entry will win. // Issue 13272, 13273. func TestImagesGoldenFiltersMaskCacheIssues(t *testing.T) { - htesting.SkipSlowTestUnlessCI(t) if imagetesting.SkipGoldenTests { t.Skip("Skip golden test on this architecture") } @@ -352,7 +348,6 @@ Home. func TestImagesGoldenProcessWebP(t *testing.T) { t.Parallel() - htesting.SkipSlowTestUnlessCI(t) if imagetesting.SkipGoldenTests { t.Skip("Skip golden test on this architecture") @@ -427,7 +422,6 @@ Home. func TestImagesGoldenWebPAnimation(t *testing.T) { t.Parallel() - htesting.SkipSlowTestUnlessCI(t) if imagetesting.SkipGoldenTests { t.Skip("Skip golden test on this architecture") @@ -463,7 +457,6 @@ Home. func TestImagesGoldenMethods(t *testing.T) { t.Parallel() - htesting.SkipSlowTestUnlessCI(t) if imagetesting.SkipGoldenTests { t.Skip("Skip golden test on this architecture") @@ -535,7 +528,6 @@ Home. func TestImagesGoldenConfigLossyVsQuality(t *testing.T) { t.Parallel() - htesting.SkipSlowTestUnlessCI(t) if imagetesting.SkipGoldenTests { t.Skip("Skip golden test on this architecture")