diff --git a/.circleci/config.yml b/.circleci/config.yml index 90483a3..633ce35 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,18 @@ jobs: - restore-go-mod-cache - run: name: lint and test - command: make test-circle + command: make test-circle && make test-coverage + - run: + name: Upload Coverage Results to Codacy + command: | + if [ -x "$(which curl)" ]; then + curl -Ls https://coverage.codacy.com/get.sh > get.sh + elif [ -x "$(which wget)" ] ; then + wget -qO - https://coverage.codacy.com/get.sh > get.sh + else + printf "Could not find curl or wget, please install one." + fi + source get.sh report --force-coverage-parser go -r coverage.out # Tag for release release: executor: go-build @@ -91,4 +102,4 @@ workflows: filters: branches: only: - - main \ No newline at end of file + - main diff --git a/README.MD b/README.MD index cb90147..9057015 100644 --- a/README.MD +++ b/README.MD @@ -2,6 +2,8 @@ [![Early Access](https://img.shields.io/badge/Pantheon-Early_Access-yellow?logo=pantheon&color=FFDC28)](https://docs.pantheon.io/oss-support-levels#early-access) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/5a16739ac87e496c80e9578e64ab79ca)](https://app.codacy.com/gh/pantheon-systems/sites-yml-validator/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) + A utility for validating a `sites.yml` file on a Pantheon site during a WordPress multisite's search and replace tasks. For more information, see [Pantheon's Multisite Docs](https://docs.pantheon.io/guides/multisite/search-replace/). ## Usage @@ -73,8 +75,6 @@ curl -LO https://github.com/pantheon-systems/sites-yml-validator/releases/latest ## Testing -[![Coverage Status](https://coveralls.io/repos/github/pantheon-systems/sites-yml-validator/badge.svg?t=PGhafd)](https://coveralls.io/github/pantheon-systems/sites-yml-validator) - `make test` runs linting and testing. ## Releases diff --git a/devops/make/common-go.mk b/devops/make/common-go.mk index a46fd74..7b58a17 100644 --- a/devops/make/common-go.mk +++ b/devops/make/common-go.mk @@ -3,7 +3,6 @@ # INPUT VARIABLES # - GOLINT_ARGS: Override the options passed to golangci-lint for linting (-v --timeout 3m by default) # - GOTEST_ARGS: Override the options passed by default ot go test (--race by default) -# - COVERALLS_TOKEN: Token to use when pushing coverage to coveralls. # # - FETCH_CA_CERT: The presence of this variable will cause the root CA certs # to be downloaded to the file ca-certificates.crt before building. @@ -16,11 +15,12 @@ deps:: deps-go deps-circle:: deps-circle-go deps lint:: lint-go test:: lint-go test-go-tparse -test-circle:: test test-coveralls +test-circle:: test test-coverage:: test-coverage-go build:: $(APP) build-go:: $(APP) clean:: clean-go +format:: format-go ifndef GOLINT_ARGS GOLINT_ARGS := -v --timeout 3m @@ -70,9 +70,17 @@ deps-go:: deps-lint ## install dependencies for project assumes you have go bina ifneq (,$(wildcard vendor)) @find ./vendor/* -maxdepth 0 -type d -exec rm -rf "{}" \; || true endif - $(call INFO, "restoring dependencies using modules via: go get $(GO_GET_ARGS)") - @GO111MODULE=on go get $(GO_GET_ARGS) - + $(call INFO, "restoring dependencies using modules via: go mod download $(GO_GET_ARGS)") + @GO111MODULE=on go mod download $(GO_GET_ARGS) + +format-go: + $(call INFO, "cleaning up go.mod") + @go mod tidy + $(call INFO, "formatting go-code") + @go fmt + $(call INFO, "running golangci-lint with fixes") + @# TODO: call lint-go + @golangci-lint run -E goimports --fix $(GOLINT_ARGS) lint-go:: deps-go deps-lint $(call INFO, "scanning source with golangci-lint") @@ -109,12 +117,6 @@ else endif endif -deps-coveralls-go:: ## install goveralls for sending go test coverage reports to Coveralls.io -ifeq (, $(shell command -v goveralls;)) - $(call INFO, "installing goveralls") - @GO111MODULE=off go get github.com/mattn/goveralls > /dev/null -endif - deps-status:: ## check status of deps with gostatus ifeq (, $(shell command -v gostatus;)) $(call INFO, "installing gostatus") @@ -131,14 +133,6 @@ test-coverage-go:: ## run coverage report $(call INFO, "running go coverage tests with $(GO_TEST_COVERAGE_ARGS)") @$(GO_TEST_COVERAGE_CMD) > /dev/null -test-coveralls:: deps-coveralls-go test-coverage-go ## run coverage and report to coveralls -ifdef COVERALLS_TOKEN - $(call INFO, "reporting coverage to coveralls") - @goveralls -repotoken $$COVERALLS_TOKEN -service=circleci -coverprofile=coverage.out > /dev/null -else - $(call WARN, "You asked to use Coveralls but neglected to set the COVERALLS_TOKEN environment variable") -endif - test-coverage-html:: test-coverage ## output html coverage file $(call INFO, "generating html coverage report") @go tool cover -html=coverage.out > /dev/null @@ -153,5 +147,5 @@ ifdef FETCH_CA_CERT @curl -s -L https://curl.haxx.se/ca/cacert.pem -o ca-certificates.crt > /dev/null endif -.PHONY:: _fetch-cert test-coverage-html test-coveralls deps-status deps-coveralls-go deps-circle deps-go deps-lint \ +.PHONY:: _fetch-cert test-coverage-html deps-status deps-circle deps-go deps-lint \ lint-go test-circle test-go build-circle build-linux build-go clean-go diff --git a/devops/make/common.mk b/devops/make/common.mk index e79b650..a860eb3 100644 --- a/devops/make/common.mk +++ b/devops/make/common.mk @@ -19,8 +19,11 @@ ROOT_DIR ?= $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) # override to use eg your own checkout for making pr's to upstream COMMON_MAKE_DIR ?= $(ROOT_DIR)/devops/make +# the branch or ref to get common-make updates from +COMMON_MAKE_UPDATE_TARGET ?= master + help: ## print list of tasks and descriptions - @grep --no-filename -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) $(filter_tasks_cmd) | sort | awk 'BEGIN {FS = ":.*?##"}; { printf "\033[36m%-30s\033[0m %s \n", $$1, $$2}' + @grep --no-filename -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) $(filter_tasks_cmd) | sort | uniq | awk 'BEGIN {FS = ":.*?##"}; { printf "\033[36m%-30s\033[0m %s \n", $$1, $$2}' .DEFAULT_GOAL := help # Invoke this with $(call INFO,) @@ -50,7 +53,7 @@ ifndef BRANCH endif ifndef COMMIT_NO - COMMIT_NO := $(shell git rev-parse --short HEAD) + COMMIT_NO := $(shell git rev-parse --short=8 HEAD) endif ifndef COMMIT @@ -68,6 +71,19 @@ test-circle:: ## invoke test tasks for CI test-coverage:: ## run test coverage reports build:: ## run all build clean:: ## clean up artifacts from test and build +format:: ## attempts to properly format or cleanup files, writing changes to disk + +# runs format and errors if anything has changed +check-format: format + @s=$$(git status --porcelain); if [ -z "$$s" ]; then \ + echo "workdir is clean"; \ + else \ + echo "The following files have changed on disk"; \ + echo "$$s"; \ + git diff; \ + exit 1; \ + fi + update-makefiles:: ## update the make subtree, assumes the subtree is in devops/make ifneq (, $(wildcard scripts/make)) @@ -79,12 +95,12 @@ update-makefiles:: ## update the make subtree, assumes the subtree is in devops/ @echo "git commit -am \"Move common_makefiles to new prefix\"" @exit 1 endif - # best effort attempt to do one time setup - @set -x; if ! git remote show common_makefiles &> /dev/null; then \ - echo "adding common_makefiles as a remote"; \ + @if ! git remote show common_makefiles &> /dev/null; then \ + echo "temporarily adding common_makefiles as a remote"; \ git remote add common_makefiles git@github.com:pantheon-systems/common_makefiles.git --no-tags; \ - git subtree add --prefix devops/make common_makefiles master --squash &>/dev/null || true; \ + git subtree add --prefix devops/make common_makefiles $(COMMON_MAKE_UPDATE_TARGET) --squash &>/dev/null || true; \ fi - @git subtree pull --prefix devops/make common_makefiles master --squash + @git subtree pull --prefix devops/make common_makefiles $(COMMON_MAKE_UPDATE_TARGET) --squash -m 'update common make' + @git remote remove common_makefiles .PHONY:: all help update-makefiles