Skip to content

Commit

Permalink
Cleanup go.mod only if option -c is passed
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Grandfond <benjamin.grandfond@docker.com>
  • Loading branch information
benja-M-1 committed Apr 23, 2022
1 parent 267e36c commit a00f352
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ plugins: ## build example CLI plugins
.PHONY: vendor
vendor: ## update vendor with go modules
rm -rf vendor
./scripts/vendor update
./scripts/vendor update -c

.PHONY: validate-vendor
validate-vendor: ## validate vendor
./scripts/vendor validate
./scripts/vendor validate -c

.PHONY: mod-outdated
mod-outdated: ## check outdated dependencies
./scripts/vendor outdated
./scripts/vendor outdated -c

.PHONY: authors
authors: ## generate AUTHORS file from git history
Expand Down
6 changes: 3 additions & 3 deletions dockerfiles/Dockerfile.vendor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN --mount=target=/context \
--mount=target=/go/pkg/mod,type=cache <<EOT
set -e
rsync -a /context/. .
./scripts/vendor update
./scripts/vendor update -c
mkdir /out
cp -r vendor.mod vendor.sum vendor /out
EOT
Expand All @@ -30,7 +30,7 @@ rsync -a /context/. .
git add -A
rm -rf vendor
cp -rf /out/* .
./scripts/vendor validate
./scripts/vendor validate -c
EOT

FROM psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated
Expand All @@ -39,4 +39,4 @@ ARG UUID
RUN --mount=target=.,rw \
--mount=target=/go/pkg/mod,type=cache \
--mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \
./scripts/vendor outdated
./scripts/vendor outdated -c
2 changes: 2 additions & 0 deletions scripts/docs/generate-man.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ trap clean EXIT
go build -mod=vendor -modfile=vendor.mod -tags manpages -o /tmp/gen-manpages ./man/generate.go
# build go-md2man
go build -mod=vendor -modfile=vendor.mod -o /tmp/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
# clean vendor
./scripts/vendor clean
)

mkdir -p man/man1
Expand Down
2 changes: 2 additions & 0 deletions scripts/docs/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ trap clean EXIT
./scripts/vendor update
# build docsgen
go build -mod=vendor -modfile=vendor.mod -tags docsgen -o /tmp/docsgen ./docs/generate.go
# clean vendor
./scripts/vendor clean
)

mkdir -p docs/yaml
Expand Down
45 changes: 29 additions & 16 deletions scripts/vendor
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@

set -eu

TYP=$1

usage() {
echo "usage: ./scripts/vendor <init|update|validate|outdated>"
echo "usage: ./scripts/vendor <init|update|validate|outdated|clean> [-c]"
echo
echo "options:"
echo " c remove dummy go.mod after command execution"
exit 1
}

if [ -z "$TYP" ]; then
usage
fi

clean() {
rm go.mod
}

init() {
# create dummy go.mod, see comment in vendor.mod
cat > go.mod <<EOL
Expand Down Expand Up @@ -47,29 +40,49 @@ outdated() {
(set -x ; go list -mod=vendor -mod=readonly -modfile=vendor.mod -u -m -json all | go-mod-outdated -update -direct)
}

clean() {
echo "Remove dummy go.mod file"
rm go.mod
}

command=(${1:-"usage"})
if [ $# -gt 1 ]; then
shift # Remove command from the argument list
fi

case $TYP in
case $command in
"init")
init
exit 0
;;
"update")
init
update
clean
;;
"validate")
init
update
clean
validate
;;
"outdated")
init
outdated
;;
"clean")
clean
exit 0
;;
*)
echo >&2 "Unknown type $TYP"
exit 1
usage
;;
esac

while getopts ":c" opt; do
case $opt in
c)
clean
;;
*)
;;
esac
done

0 comments on commit a00f352

Please sign in to comment.