From 835d71a3a4b7c359cb5aa5d458d37a8e9e052c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 19:28:05 +0200 Subject: [PATCH 01/16] Remove some outright unused code from hack/make* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should not affect observable behavior. Signed-off-by: Miloslav Trmač --- hack/make.sh | 22 +++------------------- hack/make/.validate | 19 ++----------------- hack/make/test-integration | 7 +------ 3 files changed, 6 insertions(+), 42 deletions(-) diff --git a/hack/make.sh b/hack/make.sh index cd06cb2d..83ed2ffc 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -20,7 +20,6 @@ set -o pipefail export SKOPEO_PKG='github.com/containers/skopeo' export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -export MAKEDIR="$SCRIPTDIR/make" # Set this to 1 to enable installation/modification of environment/services export SKOPEO_CONTAINER_TESTS=${SKOPEO_CONTAINER_TESTS:-0} @@ -39,19 +38,6 @@ fi echo -# List of bundles to create when no argument is passed -# TODO(runcom): these are the one left from Docker...for now -# test-unit -# validate-dco -# cover -DEFAULT_BUNDLES=( - validate-gofmt - validate-lint - validate-vet - validate-git-marks - - test-integration -) # Go module support: set `-mod=vendor` to use the vendored sources # See also the top-level Makefile. @@ -66,7 +52,6 @@ go_test_dir() { ( echo '+ go test' $mod_vendor $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} "${SKOPEO_PKG}${dir#.}" cd "$dir" - export DEST="$ABS_DEST" # we're in a subshell, so this is safe -- our integration-cli tests need DEST, and "cd" screws it up go test $mod_vendor $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} ) } @@ -79,11 +64,10 @@ bundle() { main() { if [ $# -lt 1 ]; then - bundles=(${DEFAULT_BUNDLES[@]}) - else - bundles=($@) + echo 'At least one "bundle" argument expected' >&2 + return 1 fi - for bundle in ${bundles[@]}; do + for bundle in $@; do bundle "$bundle" echo done diff --git a/hack/make/.validate b/hack/make/.validate index c72a5a4e..e5919729 100644 --- a/hack/make/.validate +++ b/hack/make/.validate @@ -6,26 +6,11 @@ if [ -z "$VALIDATE_UPSTREAM" ]; then VALIDATE_REPO='https://github.com/containers/skopeo.git' VALIDATE_BRANCH='main' - - if [ "$TRAVIS" = 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then - VALIDATE_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git" - VALIDATE_BRANCH="${TRAVIS_BRANCH}" - fi - - VALIDATE_HEAD="$(git rev-parse --verify HEAD)" - + git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" - - VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD" - VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD" - + validate_diff() { git diff "$VALIDATE_UPSTREAM" "$@" } - validate_log() { - if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then - git log "$VALIDATE_COMMIT_LOG" "$@" - fi - } fi diff --git a/hack/make/test-integration b/hack/make/test-integration index 3c9e8717..a9c69b98 100755 --- a/hack/make/test-integration +++ b/hack/make/test-integration @@ -1,12 +1,7 @@ #!/bin/bash set -e -bundle_test_integration() { - go_test_dir ./integration -} - -# subshell so that we can export PATH without breaking other things ( make PREFIX=/usr install - bundle_test_integration + go_test_dir ./integration ) 2>&1 From 98b01af03190e33c490926ca16f437c9cc707ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 19:32:14 +0200 Subject: [PATCH 02/16] Fix Makefile dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit validate-docs requires bin/skopeo; test-unit-local ctually doesn't. Signed-off-by: Miloslav Trmač --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 29792546..e7fea1a8 100644 --- a/Makefile +++ b/Makefile @@ -234,11 +234,11 @@ validate-local: # This invokes bin/skopeo, hence cannot be run as part of validate-local .PHONY: validate-docs -validate-docs: +validate-docs: bin/skopeo hack/man-page-checker hack/xref-helpmsgs-manpages -test-unit-local: bin/skopeo +test-unit-local: $(GO) test $(MOD_VENDOR) -tags "$(BUILDTAGS)" $$($(GO) list $(MOD_VENDOR) -tags "$(BUILDTAGS)" -e ./... | grep -v '^github\.com/containers/skopeo/\(integration\|vendor/.*\)$$') vendor: From 225f239a69299d85ba7c2e48f9a6953ccb1e76b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 19:50:40 +0200 Subject: [PATCH 03/16] Remove no-longer-necessary module options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now require Go 1.18. As of that version: - GO111MODULE=on is implied by having a go.mod file - -mod=vendor is implied by having a vendor directory so just remove both options everywhere Signed-off-by: Miloslav Trmač --- Makefile | 13 +++---------- hack/make.sh | 13 ++----------- hack/make/validate-vet | 2 +- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index e7fea1a8..d6264b81 100644 --- a/Makefile +++ b/Makefile @@ -38,13 +38,6 @@ endif export CONTAINER_RUNTIME ?= $(if $(shell command -v podman ;),podman,docker) GOMD2MAN ?= $(if $(shell command -v go-md2man ;),go-md2man,$(GOBIN)/go-md2man) -# Go module support: set `-mod=vendor` to use the vendored sources. -# See also hack/make.sh. -ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true) - GO:=GO111MODULE=on $(GO) - MOD_VENDOR=-mod=vendor -endif - ifeq ($(DEBUG), 1) override GOGCFLAGS += -N -l endif @@ -133,9 +126,9 @@ binary: cmd/skopeo # Build w/o using containers .PHONY: bin/skopeo bin/skopeo: - $(GO) build $(MOD_VENDOR) ${GO_DYN_FLAGS} ${SKOPEO_LDFLAGS} -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o $@ ./cmd/skopeo + $(GO) build ${GO_DYN_FLAGS} ${SKOPEO_LDFLAGS} -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o $@ ./cmd/skopeo bin/skopeo.%: - GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO) build $(MOD_VENDOR) ${SKOPEO_LDFLAGS} -tags "containers_image_openpgp $(BUILDTAGS)" -o $@ ./cmd/skopeo + GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO) build ${SKOPEO_LDFLAGS} -tags "containers_image_openpgp $(BUILDTAGS)" -o $@ ./cmd/skopeo local-cross: bin/skopeo.darwin.amd64 bin/skopeo.linux.arm bin/skopeo.linux.arm64 bin/skopeo.windows.386.exe bin/skopeo.windows.amd64.exe $(MANPAGES): %: %.md @@ -239,7 +232,7 @@ validate-docs: bin/skopeo hack/xref-helpmsgs-manpages test-unit-local: - $(GO) test $(MOD_VENDOR) -tags "$(BUILDTAGS)" $$($(GO) list $(MOD_VENDOR) -tags "$(BUILDTAGS)" -e ./... | grep -v '^github\.com/containers/skopeo/\(integration\|vendor/.*\)$$') + $(GO) test -tags "$(BUILDTAGS)" $$($(GO) list -tags "$(BUILDTAGS)" -e ./... | grep -v '^github\.com/containers/skopeo/\(integration\|vendor/.*\)$$') vendor: $(GO) mod tidy diff --git a/hack/make.sh b/hack/make.sh index 83ed2ffc..7046810b 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -38,21 +38,12 @@ fi echo - -# Go module support: set `-mod=vendor` to use the vendored sources -# See also the top-level Makefile. -mod_vendor= -if go help mod >/dev/null 2>&1; then - export GO111MODULE=on - mod_vendor='-mod=vendor' -fi - go_test_dir() { dir=$1 ( - echo '+ go test' $mod_vendor $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} "${SKOPEO_PKG}${dir#.}" + echo '+ go test' $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} "${SKOPEO_PKG}${dir#.}" cd "$dir" - go test $mod_vendor $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} + go test $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} ) } diff --git a/hack/make/validate-vet b/hack/make/validate-vet index 17e5980c..6a66cd68 100755 --- a/hack/make/validate-vet +++ b/hack/make/validate-vet @@ -1,6 +1,6 @@ #!/bin/bash -errors=$(go vet -tags="${BUILDTAGS}" $mod_vendor $(go list $mod_vendor -e ./...)) +errors=$(go vet -tags="${BUILDTAGS}" $(go list -e ./...)) if [ -z "$errors" ]; then echo 'Congratulations! All Go source files have been vetted.' From 43090b2917c9905aa579fd9dc1ea789309ed055e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 19:57:03 +0200 Subject: [PATCH 04/16] Don't use hack/make.sh for validate-vet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hack/make.sh now does not make a difference, so simplify. Signed-off-by: Miloslav Trmač --- Makefile | 3 ++- hack/{make/validate-vet => validate-vet.sh} | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename hack/{make/validate-vet => validate-vet.sh} (97%) diff --git a/Makefile b/Makefile index d6264b81..e04e3481 100644 --- a/Makefile +++ b/Makefile @@ -223,7 +223,8 @@ test-all-local: validate-local validate-docs test-unit-local .PHONY: validate-local validate-local: - BUILDTAGS="${BUILDTAGS}" hack/make.sh validate-git-marks validate-gofmt validate-lint validate-vet + BUILDTAGS="${BUILDTAGS}" hack/make.sh validate-git-marks validate-gofmt validate-lint + BUILDTAGS="${BUILDTAGS}" hack/validate-vet.sh # This invokes bin/skopeo, hence cannot be run as part of validate-local .PHONY: validate-docs diff --git a/hack/make/validate-vet b/hack/validate-vet.sh similarity index 97% rename from hack/make/validate-vet rename to hack/validate-vet.sh index 6a66cd68..577c5802 100755 --- a/hack/make/validate-vet +++ b/hack/validate-vet.sh @@ -12,5 +12,5 @@ else echo 'Please fix the above errors. You can test via "go vet" and commit the result.' echo } >&2 - false + exit 1 fi From 694b1565d148f33c20f84013fff77fcd9605f56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:03:38 +0200 Subject: [PATCH 05/16] Lint many more files in validate-lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Always lint everything, not just changed files; that means that if we upgrade the linter, we will need to clean everything up, but that's a good thing for contributors who come after that linter upgrade. - Don't skip linting the integration tests, there's no good reason to skip them. Signed-off-by: Miloslav Trmač --- hack/make/validate-lint | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hack/make/validate-lint b/hack/make/validate-lint index 3674d723..a59b28c1 100755 --- a/hack/make/validate-lint +++ b/hack/make/validate-lint @@ -1,12 +1,7 @@ #!/bin/bash -source "$(dirname "$BASH_SOURCE")/.validate" - -# We will eventually get to the point where packages should be the complete list -# of subpackages, vendoring excluded, as given by: -# IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/\|^integration' || true) ) +files=( $(find . -name '*.go' | grep -v '^\./vendor/' | sort || true) ) unset IFS errors=() From 82268ea8bfc9ecd4fce72ac36f6a228989df105c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:06:40 +0200 Subject: [PATCH 06/16] Don't use hack/make.sh for validate-lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hack/make.sh now does not make a difference, so simplify. Signed-off-by: Miloslav Trmač --- Makefile | 3 ++- hack/{make/validate-lint => validate-lint.sh} | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename hack/{make/validate-lint => validate-lint.sh} (98%) diff --git a/Makefile b/Makefile index e04e3481..53516a0a 100644 --- a/Makefile +++ b/Makefile @@ -223,7 +223,8 @@ test-all-local: validate-local validate-docs test-unit-local .PHONY: validate-local validate-local: - BUILDTAGS="${BUILDTAGS}" hack/make.sh validate-git-marks validate-gofmt validate-lint + BUILDTAGS="${BUILDTAGS}" hack/make.sh validate-git-marks validate-gofmt + hack/validate-lint.sh BUILDTAGS="${BUILDTAGS}" hack/validate-vet.sh # This invokes bin/skopeo, hence cannot be run as part of validate-local diff --git a/hack/make/validate-lint b/hack/validate-lint.sh similarity index 98% rename from hack/make/validate-lint rename to hack/validate-lint.sh index a59b28c1..cc756902 100755 --- a/hack/make/validate-lint +++ b/hack/validate-lint.sh @@ -24,5 +24,5 @@ else echo 'Please fix the above errors. You can test via "golint" and commit the result.' echo } >&2 - false + exit 1 fi From 85fef03670b3877dcd6a37eb1b6f74f97d8fb6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:12:45 +0200 Subject: [PATCH 07/16] Run gofmt on all files, not just the changed ones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... so that if we upgrade gofmt, the updates need happen immediately. Signed-off-by: Miloslav Trmač --- hack/make/validate-gofmt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hack/make/validate-gofmt b/hack/make/validate-gofmt index 0f973f92..b589eb33 100755 --- a/hack/make/validate-gofmt +++ b/hack/make/validate-gofmt @@ -1,9 +1,7 @@ #!/bin/bash -source "$(dirname "$BASH_SOURCE")/.validate" - IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) ) +files=( $(find . -name '*.go' | grep -v '^./vendor/' | sort || true) ) unset IFS badFiles=() From bee51e5eedf7b433f2d0dce4c89a33c24aa25e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:21:16 +0200 Subject: [PATCH 08/16] Don't use hack/make.sh for validate-gofmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hack/make.sh now does not make a difference, so simplify. Signed-off-by: Miloslav Trmač --- Makefile | 3 ++- hack/{make/validate-gofmt => validate-gofmt.sh} | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename hack/{make/validate-gofmt => validate-gofmt.sh} (98%) diff --git a/Makefile b/Makefile index 53516a0a..8d521531 100644 --- a/Makefile +++ b/Makefile @@ -223,7 +223,8 @@ test-all-local: validate-local validate-docs test-unit-local .PHONY: validate-local validate-local: - BUILDTAGS="${BUILDTAGS}" hack/make.sh validate-git-marks validate-gofmt + BUILDTAGS="${BUILDTAGS}" hack/make.sh validate-git-marks + hack/validate-gofmt.sh hack/validate-lint.sh BUILDTAGS="${BUILDTAGS}" hack/validate-vet.sh diff --git a/hack/make/validate-gofmt b/hack/validate-gofmt.sh similarity index 98% rename from hack/make/validate-gofmt rename to hack/validate-gofmt.sh index b589eb33..72757215 100755 --- a/hack/make/validate-gofmt +++ b/hack/validate-gofmt.sh @@ -23,5 +23,5 @@ else echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' echo } >&2 - false + exit 1 fi From 789257f7679be237c9c45ff54c76782e743dc779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:24:53 +0200 Subject: [PATCH 09/16] Simplify the package list of (go vet) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That extra process is an extra 0.5s on macOS at least. Signed-off-by: Miloslav Trmač --- hack/validate-vet.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/validate-vet.sh b/hack/validate-vet.sh index 577c5802..a661c15f 100755 --- a/hack/validate-vet.sh +++ b/hack/validate-vet.sh @@ -1,6 +1,6 @@ #!/bin/bash -errors=$(go vet -tags="${BUILDTAGS}" $(go list -e ./...)) +errors=$(go vet -tags="${BUILDTAGS}" ./...) if [ -z "$errors" ]; then echo 'Congratulations! All Go source files have been vetted.' From 7e35ad54c3d0da5883dd42f2352ebcce5e788a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:28:36 +0200 Subject: [PATCH 10/16] Test all files by validate-git-marks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is simpler to do, cheap enough for our repo size, and it does not require a network access to see which files to check. And it's the last user of hack/make/.validate, which I wanted to remove in the first place. Signed-off-by: Miloslav Trmač --- hack/make/.validate | 16 ---------------- hack/make/validate-git-marks | 6 +----- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 hack/make/.validate diff --git a/hack/make/.validate b/hack/make/.validate deleted file mode 100644 index e5919729..00000000 --- a/hack/make/.validate +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -if [ -z "$VALIDATE_UPSTREAM" ]; then - # this is kind of an expensive check, so let's not do this twice if we - # are running more than one validate bundlescript - - VALIDATE_REPO='https://github.com/containers/skopeo.git' - VALIDATE_BRANCH='main' - - git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" - VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" - - validate_diff() { - git diff "$VALIDATE_UPSTREAM" "$@" - } -fi diff --git a/hack/make/validate-git-marks b/hack/make/validate-git-marks index daa6950e..3a118053 100755 --- a/hack/make/validate-git-marks +++ b/hack/make/validate-git-marks @@ -1,11 +1,7 @@ #!/usr/bin/env bash -source "$(dirname "$BASH_SOURCE")/.validate" - -# folders=$(find * -type d | egrep -v '^Godeps|bundles|.git') - IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*' | grep -v '^vendor/' || true) ) +files=( $(git ls-tree -r HEAD --name-only | grep -v '^vendor/' || true) ) unset IFS badFiles=() From 4298692dd40edc770849762055dac3a1753875a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:32:15 +0200 Subject: [PATCH 11/16] Don't use hack/make.sh for validate-git-marks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hack/make.sh now does not make a difference, so simplify. Signed-off-by: Miloslav Trmač --- Makefile | 2 +- hack/{make/validate-git-marks => validate-git-marks.sh} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename hack/{make/validate-git-marks => validate-git-marks.sh} (98%) diff --git a/Makefile b/Makefile index 8d521531..4d0b09bd 100644 --- a/Makefile +++ b/Makefile @@ -223,7 +223,7 @@ test-all-local: validate-local validate-docs test-unit-local .PHONY: validate-local validate-local: - BUILDTAGS="${BUILDTAGS}" hack/make.sh validate-git-marks + hack/validate-git-marks.sh hack/validate-gofmt.sh hack/validate-lint.sh BUILDTAGS="${BUILDTAGS}" hack/validate-vet.sh diff --git a/hack/make/validate-git-marks b/hack/validate-git-marks.sh similarity index 98% rename from hack/make/validate-git-marks rename to hack/validate-git-marks.sh index 3a118053..0ba98f45 100755 --- a/hack/make/validate-git-marks +++ b/hack/validate-git-marks.sh @@ -36,5 +36,5 @@ else echo 'Please fix the conflict(s) commit the result.' echo } >&2 - false + exit 1 fi From aebab49285849a62d084e08c6de49c4937352aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:34:21 +0200 Subject: [PATCH 12/16] Speed up validate-git-marks by about a factor of three MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miloslav Trmač --- hack/validate-git-marks.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/hack/validate-git-marks.sh b/hack/validate-git-marks.sh index 0ba98f45..57943942 100755 --- a/hack/validate-git-marks.sh +++ b/hack/validate-git-marks.sh @@ -6,17 +6,7 @@ unset IFS badFiles=() for f in "${files[@]}"; do - if [ $(grep -r "^<<<<<<<" $f) ]; then - badFiles+=( "$f" ) - continue - fi - - if [ $(grep -r "^>>>>>>>" $f) ]; then - badFiles+=( "$f" ) - continue - fi - - if [ $(grep -r "^=======$" $f) ]; then + if [ $(grep -r "^\(<<<<<<<\|>>>>>>>\|^=======$\)" $f) ]; then badFiles+=( "$f" ) continue fi From f8f5a25fe2c7e20be522ed9aceecc463730b0a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:37:48 +0200 Subject: [PATCH 13/16] Actually fail if (go vet) fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The errors are printed on stderr, so read that. Signed-off-by: Miloslav Trmač --- hack/validate-vet.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/validate-vet.sh b/hack/validate-vet.sh index a661c15f..35e2b1f4 100755 --- a/hack/validate-vet.sh +++ b/hack/validate-vet.sh @@ -1,6 +1,6 @@ #!/bin/bash -errors=$(go vet -tags="${BUILDTAGS}" ./...) +errors=$(go vet -tags="${BUILDTAGS}" ./... 2>&1) if [ -z "$errors" ]; then echo 'Congratulations! All Go source files have been vetted.' From c538340e3bea815f8938d5ada17f26f8747fc97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:46:37 +0200 Subject: [PATCH 14/16] Finally, eliminate hack/make.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only thing hack/make.sh is now really doing is the warning + sleep without SKOPEO_CONTAINER_TESTS . So, make that a separate script, and eliminate the hack/make directory. Signed-off-by: Miloslav Trmač --- Makefile | 6 +- hack/make.sh | 67 ----------------------- hack/make/test-integration | 7 --- hack/test-integration.sh | 8 +++ hack/{make/test-system => test-system.sh} | 0 hack/warn-destructive-tests.sh | 17 ++++++ 6 files changed, 29 insertions(+), 76 deletions(-) delete mode 100755 hack/make.sh delete mode 100755 hack/make/test-integration create mode 100755 hack/test-integration.sh rename hack/{make/test-system => test-system.sh} (100%) create mode 100755 hack/warn-destructive-tests.sh diff --git a/Makefile b/Makefile index 4d0b09bd..79687d0f 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,8 @@ test-integration: # Intended for CI, assumed to be running in quay.io/libpod/skopeo_cidev container. test-integration-local: bin/skopeo - hack/make.sh test-integration + hack/warn-destructive-tests.sh + hack/test-integration.sh # complicated set of options needed to run podman-in-podman test-system: @@ -209,7 +210,8 @@ test-system: # Intended for CI, assumed to already be running in quay.io/libpod/skopeo_cidev container. test-system-local: bin/skopeo - hack/make.sh test-system + hack/warn-destructive-tests.sh + hack/test-system.sh test-unit: # Just call (make test unit-local) here instead of worrying about environment differences diff --git a/hack/make.sh b/hack/make.sh deleted file mode 100755 index 7046810b..00000000 --- a/hack/make.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash -set -e - -# This script builds various binary from a checkout of the skopeo -# source code. DO NOT CALL THIS SCRIPT DIRECTLY. -# -# Requirements: -# - The current directory should be a checkout of the skopeo source code -# (https://github.com/containers/skopeo). Whatever version is checked out -# will be built. -# - The script is intended to be run inside the container specified -# in the output of hack/get_fqin.sh -# - The right way to call this script is to invoke "make" from -# your checkout of the skopeo repository. -# the Makefile will do a "docker build -t skopeo ." and then -# "docker run hack/make.sh" in the resulting image. -# - -set -o pipefail - -export SKOPEO_PKG='github.com/containers/skopeo' -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Set this to 1 to enable installation/modification of environment/services -export SKOPEO_CONTAINER_TESTS=${SKOPEO_CONTAINER_TESTS:-0} - -if [[ "$SKOPEO_CONTAINER_TESTS" == "0" ]] && [[ "$CI" != "true" ]]; then - ( - echo "***************************************************************" - echo "WARNING: Executing tests directly on the local development" - echo " host is highly discouraged. Many important items" - echo " will be skipped. For manual execution, please utilize" - echo " the Makefile targets WITHOUT the '-local' suffix." - echo "***************************************************************" - ) > /dev/stderr - sleep 5 -fi - -echo - -go_test_dir() { - dir=$1 - ( - echo '+ go test' $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} "${SKOPEO_PKG}${dir#.}" - cd "$dir" - go test $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} - ) -} - -bundle() { - local bundle="$1"; shift - echo "---> Making bundle: $(basename "$bundle")" - source "$SCRIPTDIR/make/$bundle" "$@" -} - -main() { - if [ $# -lt 1 ]; then - echo 'At least one "bundle" argument expected' >&2 - return 1 - fi - for bundle in $@; do - bundle "$bundle" - echo - done -} - -main "$@" diff --git a/hack/make/test-integration b/hack/make/test-integration deleted file mode 100755 index a9c69b98..00000000 --- a/hack/make/test-integration +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e - -( - make PREFIX=/usr install - go_test_dir ./integration -) 2>&1 diff --git a/hack/test-integration.sh b/hack/test-integration.sh new file mode 100755 index 00000000..63dc2485 --- /dev/null +++ b/hack/test-integration.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +make PREFIX=/usr install + +echo "cd ./integration;" go test $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} +cd ./integration +go test $TESTFLAGS ${BUILDTAGS:+-tags "$BUILDTAGS"} \ No newline at end of file diff --git a/hack/make/test-system b/hack/test-system.sh similarity index 100% rename from hack/make/test-system rename to hack/test-system.sh diff --git a/hack/warn-destructive-tests.sh b/hack/warn-destructive-tests.sh new file mode 100755 index 00000000..4e87a091 --- /dev/null +++ b/hack/warn-destructive-tests.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -e + +# Set this to 1 to enable installation/modification of environment/services +export SKOPEO_CONTAINER_TESTS=${SKOPEO_CONTAINER_TESTS:-0} + +if [[ "$SKOPEO_CONTAINER_TESTS" == "0" ]] && [[ "$CI" != "true" ]]; then + ( + echo "***************************************************************" + echo "WARNING: Executing tests directly on the local development" + echo " host is highly discouraged. Many important items" + echo " will be skipped. For manual execution, please utilize" + echo " the Makefile targets WITHOUT the '-local' suffix." + echo "***************************************************************" + ) > /dev/stderr + sleep 5 +fi From d4bd787e5fe071d305b562d36d83c37495725a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 20:57:55 +0200 Subject: [PATCH 15/16] Use golangci-lint instead of golint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miloslav Trmač --- .cirrus.yml | 3 ++- Makefile | 2 +- hack/validate-lint.sh | 22 +++++----------------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index be1a7b96..9375737f 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -53,6 +53,7 @@ validate_task: cpu: 4 memory: 8 script: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2 make validate-local make vendor && hack/tree_status.sh @@ -91,7 +92,7 @@ osx_task: export PATH=$GOPATH/bin:$PATH brew update brew install gpgme go go-md2man - go install golang.org/x/lint/golint@latest + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2 test_script: | export PATH=$GOPATH/bin:$PATH go version diff --git a/Makefile b/Makefile index 79687d0f..d9f92581 100644 --- a/Makefile +++ b/Makefile @@ -227,7 +227,7 @@ test-all-local: validate-local validate-docs test-unit-local validate-local: hack/validate-git-marks.sh hack/validate-gofmt.sh - hack/validate-lint.sh + GOBIN=$(GOBIN) hack/validate-lint.sh BUILDTAGS="${BUILDTAGS}" hack/validate-vet.sh # This invokes bin/skopeo, hence cannot be run as part of validate-local diff --git a/hack/validate-lint.sh b/hack/validate-lint.sh index cc756902..d3dc7d11 100755 --- a/hack/validate-lint.sh +++ b/hack/validate-lint.sh @@ -1,27 +1,15 @@ #!/bin/bash -IFS=$'\n' -files=( $(find . -name '*.go' | grep -v '^\./vendor/' | sort || true) ) -unset IFS +errors=$($GOBIN/golangci-lint run --build-tags "${BUILDTAGS}" 2>&1) -errors=() -for f in "${files[@]}"; do - failedLint=$(golint "$f") - if [ "$failedLint" ]; then - errors+=( "$failedLint" ) - fi -done - -if [ ${#errors[@]} -eq 0 ]; then +if [ -z "$errors" ]; then echo 'Congratulations! All Go source files have been linted.' else { - echo "Errors from golint:" - for err in "${errors[@]}"; do - echo "$err" - done + echo "Errors from golangci-lint:" + echo "$errors" echo - echo 'Please fix the above errors. You can test via "golint" and commit the result.' + echo 'Please fix the above errors. You can test via "golangci-lint" and commit the result.' echo } >&2 exit 1 From 7c66b7405ab53afd317d2592b042ebbbf754cd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 5 Apr 2023 21:39:45 +0200 Subject: [PATCH 16/16] Add (make tools) to install (for now only) golangci-lint, use it in Cirrus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miloslav Trmač --- .cirrus.yml | 7 ++++--- Makefile | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 9375737f..754a0792 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -52,8 +52,9 @@ validate_task: image: '${SKOPEO_CIDEV_CONTAINER_FQIN}' cpu: 4 memory: 8 - script: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2 + setup_script: | + make tools + test_script: | make validate-local make vendor && hack/tree_status.sh @@ -92,7 +93,7 @@ osx_task: export PATH=$GOPATH/bin:$PATH brew update brew install gpgme go go-md2man - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2 + make tools test_script: | export PATH=$GOPATH/bin:$PATH go version diff --git a/Makefile b/Makefile index d9f92581..46aa4d29 100644 --- a/Makefile +++ b/Makefile @@ -181,6 +181,11 @@ install-completions: completions shell: $(CONTAINER_RUN) bash +tools: + if [ ! -x "$(GOBIN)/golangci-lint" ]; then \ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.52.2 ; \ + fi + check: validate test-unit test-integration test-system test-integration: