Skip to content

scripts/with-go-mod.sh: use symlink instead of -modfile #6039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/docs/generate-man.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ set -eu
if ! command -v "$GO_MD2MAN" > /dev/null; then
(
set -x
go build -mod=vendor -modfile=vendor.mod -o ./build/tools/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
go build -mod=vendor -o ./build/tools/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
)
GO_MD2MAN=$(realpath ./build/tools/go-md2man)
fi

mkdir -p man/man1
(
set -x
go run -mod=vendor -modfile=vendor.mod -tags manpages ./man/generate.go --source "./man/src" --target "./man/man1"
go run -mod=vendor -tags manpages ./man/generate.go --source "./man/src" --target "./man/man1"
)

(
Expand Down
2 changes: 1 addition & 1 deletion scripts/docs/generate-md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu

(
set -x
go run -mod=vendor -modfile=vendor.mod -tags docsgen ./docs/generate/generate.go --formats md --source "./docs/reference/commandline" --target "./docs/reference/commandline"
go run -mod=vendor -tags docsgen ./docs/generate/generate.go --formats md --source "./docs/reference/commandline" --target "./docs/reference/commandline"
)

# remove generated help.md file
Expand Down
2 changes: 1 addition & 1 deletion scripts/docs/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -eu

mkdir -p docs/yaml
set -x
go run -mod=vendor -modfile=vendor.mod -tags docsgen ./docs/generate/generate.go --formats yaml --source "./docs/reference/commandline" --target "./docs/yaml"
go run -mod=vendor -tags docsgen ./docs/generate/generate.go --formats yaml --source "./docs/reference/commandline" --target "./docs/yaml"
4 changes: 2 additions & 2 deletions scripts/vendor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ -z "$TYP" ]; then
fi

update() {
(set -x ; go mod tidy -modfile=vendor.mod; go mod vendor -modfile=vendor.mod)
(set -x ; go mod tidy; go mod vendor)
}

validate() {
Expand All @@ -31,7 +31,7 @@ outdated() {
echo "go-mod-outdated not found. Install with 'go install github.com/psampaz/[email protected]'"
exit 1
fi
(set -x ; go list -mod=vendor -mod=readonly -modfile=vendor.mod -u -m -json all | go-mod-outdated -update -direct)
(set -x ; go list -mod=readonly -u -m -json all | go-mod-outdated -update -direct)
}

case $TYP in
Expand Down
38 changes: 23 additions & 15 deletions scripts/with-go-mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,36 @@
# when the command is finished. This script should be dropped when this
# repository is a proper Go module with a permanent go.mod.

set -e
set -euo pipefail

SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOTDIR="$(cd "${SCRIPTDIR}/.." && pwd)"

if test -e "${ROOTDIR}/go.mod"; then
{
scriptname=$(basename "$0")
cat >&2 <<- EOF
$scriptname: WARN: go.mod exists in the repository root!
$scriptname: WARN: Using your go.mod instead of our generated version -- this may misbehave!
EOF
} >&2
else
cleanup_paths=()

create_symlink() {
local target="$1"
local link="$2"

if [ -e "$link" ]; then
# see https://superuser.com/a/196698
if ! [ "$link" -ef "${ROOTDIR}/${target}" ]; then
echo "$(basename "$0"): WARN: $link exists but is not the expected symlink!" >&2
echo "$(basename "$0"): WARN: Using your version instead of our generated version -- this may misbehave!" >&2
fi
return
fi

set -x
ln -s "$target" "$link"
cleanup_paths+=( "$link" )
}

tee "${ROOTDIR}/go.mod" >&2 <<- EOF
module github.com/docker/cli
create_symlink "vendor.mod" "${ROOTDIR}/go.mod"
create_symlink "vendor.sum" "${ROOTDIR}/go.sum"

go 1.23.0
EOF
trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
if [ "${#cleanup_paths[@]}" -gt 0 ]; then
trap 'rm -f "${cleanup_paths[@]}"' EXIT
fi

GO111MODULE=on GOTOOLCHAIN=local "$@"
Loading