From 98f1fe7944ed436b88759d3cd64b8fac846423b0 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Thu, 14 Mar 2024 10:38:58 +0000 Subject: [PATCH] Makefile: check git diff exit-code (#2651) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2651 Reviewed-by: Gusted --- .forgejo/workflows/testing.yml | 2 - Makefile | 56 ++++++--------------- routers/web/admin/admin_test.go | 1 + tests/integration/codeowner_test.go | 1 + tests/integration/repo_archive_text_test.go | 1 + tests/integration/repo_pagination_test.go | 1 + 6 files changed, 18 insertions(+), 44 deletions(-) diff --git a/.forgejo/workflows/testing.yml b/.forgejo/workflows/testing.yml index 5093c3d39e..85d7691cd1 100644 --- a/.forgejo/workflows/testing.yml +++ b/.forgejo/workflows/testing.yml @@ -21,8 +21,6 @@ jobs: check-latest: true - run: make deps-backend deps-tools - run: make --always-make -j$(nproc) lint-backend checks-backend # ensure the "go-licenses" make target runs - env: - TAGS: bindata sqlite sqlite_unlock_notify frontend-checks: if: ${{ !startsWith(vars.ROLE, 'forgejo-') }} runs-on: docker diff --git a/Makefile b/Makefile index 1a835e31fd..7a19be9ffc 100644 --- a/Makefile +++ b/Makefile @@ -313,12 +313,8 @@ fmt: .PHONY: fmt-check fmt-check: fmt - @diff=$$(git diff --color=always $(GO_SOURCES) templates $(WEB_DIRS)); \ - if [ -n "$$diff" ]; then \ - echo "Please run 'make fmt' and commit the result:"; \ - echo "$${diff}"; \ - exit 1; \ - fi + @git diff --exit-code --color=always $(GO_SOURCES) templates $(WEB_DIRS) \ + || (code=$$?; echo "Please run 'make fmt' and commit the result"; exit $${code}) .PHONY: $(TAGS_EVIDENCE) $(TAGS_EVIDENCE): @@ -339,12 +335,8 @@ generate-forgejo-api: $(FORGEJO_API_SPEC) .PHONY: forgejo-api-check forgejo-api-check: generate-forgejo-api - @diff=$$(git diff $(FORGEJO_API_SERVER) ; \ - if [ -n "$$diff" ]; then \ - echo "Please run 'make generate-forgejo-api' and commit the result:"; \ - echo "$${diff}"; \ - exit 1; \ - fi + @git diff --exit-code --color=always $(FORGEJO_API_SERVER) \ + || (code=$$?; echo "Please run 'make generate-forgejo-api' and commit the result"; exit $${code}) .PHONY: forgejo-api-validate forgejo-api-validate: @@ -361,12 +353,8 @@ $(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA) .PHONY: swagger-check swagger-check: generate-swagger - @diff=$$(git diff --color=always '$(SWAGGER_SPEC)'); \ - if [ -n "$$diff" ]; then \ - echo "Please run 'make generate-swagger' and commit the result:"; \ - echo "$${diff}"; \ - exit 1; \ - fi + @git diff --exit-code --color=always '$(SWAGGER_SPEC)' \ + || (code=$$?; echo "Please run 'make generate-swagger' and commit the result"; exit $${code}) .PHONY: swagger-validate swagger-validate: @@ -437,11 +425,8 @@ lint-spell-fix: lint-go: $(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS) $(GO) run $(DEADCODE_PACKAGE) -generated=false -test code.gitea.io/gitea > .cur-deadcode-out - @$(DIFF) .deadcode-out .cur-deadcode-out; \ - if [ $$? -eq 1 ]; then \ - echo "Please run 'make lint-go-fix' and commit the result"; \ - exit 1; \ - fi + @$(DIFF) .deadcode-out .cur-deadcode-out \ + || (code=$$?; echo "Please run 'make lint-go-fix' and commit the result"; exit $${code}) .PHONY: lint-go-fix lint-go-fix: @@ -541,12 +526,8 @@ vendor: go.mod go.sum .PHONY: tidy-check tidy-check: tidy - @diff=$$(git diff --color=always go.mod go.sum $(GO_LICENSE_FILE)); \ - if [ -n "$$diff" ]; then \ - echo "Please run 'make tidy' and commit the result:"; \ - echo "$${diff}"; \ - exit 1; \ - fi + @git diff --exit-code --color=always go.mod go.sum $(GO_LICENSE_FILE) \ + || (code=$$?; echo "Please run 'make tidy' and commit the result"; exit $${code}) .PHONY: go-licenses go-licenses: $(GO_LICENSE_FILE) @@ -985,23 +966,14 @@ svg: node-check | node_modules .PHONY: svg-check svg-check: svg @git add $(SVG_DEST_DIR) - @diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \ - if [ -n "$$diff" ]; then \ - echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \ - echo "$${diff}"; \ - exit 1; \ - fi + @git diff --exit-code --color=always --cached $(SVG_DEST_DIR) \ + || (code=$$?; echo "Please run 'make svg' and commit the result"; exit $${code}) .PHONY: lockfile-check lockfile-check: npm install --package-lock-only - @diff=$$(git diff --color=always package-lock.json); \ - if [ -n "$$diff" ]; then \ - echo "package-lock.json is inconsistent with package.json"; \ - echo "Please run 'npm install --package-lock-only' and commit the result:"; \ - echo "$${diff}"; \ - exit 1; \ - fi + @git diff --exit-code --color=always package-lock.json \ + || (code=$$?; echo "Please run 'npm install --package-lock-only' and commit the result"; exit $${code}) .PHONY: update-translations update-translations: diff --git a/routers/web/admin/admin_test.go b/routers/web/admin/admin_test.go index c73780d60f..3518869ede 100644 --- a/routers/web/admin/admin_test.go +++ b/routers/web/admin/admin_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/services/contexttest" + "github.com/stretchr/testify/assert" ) diff --git a/tests/integration/codeowner_test.go b/tests/integration/codeowner_test.go index 7668755547..76b292e3cb 100644 --- a/tests/integration/codeowner_test.go +++ b/tests/integration/codeowner_test.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/git" files_service "code.gitea.io/gitea/services/repository/files" "code.gitea.io/gitea/tests" + "github.com/stretchr/testify/assert" ) diff --git a/tests/integration/repo_archive_text_test.go b/tests/integration/repo_archive_text_test.go index a14fdbf84f..3f44562ad6 100644 --- a/tests/integration/repo_archive_text_test.go +++ b/tests/integration/repo_archive_text_test.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/translation" + "github.com/PuerkitoBio/goquery" "github.com/stretchr/testify/assert" ) diff --git a/tests/integration/repo_pagination_test.go b/tests/integration/repo_pagination_test.go index 81cc191dce..1c1f2ac82e 100644 --- a/tests/integration/repo_pagination_test.go +++ b/tests/integration/repo_pagination_test.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/tests" + "github.com/stretchr/testify/assert" )