...

Text file src/sigs.k8s.io/cli-utils/hack/run-in-gopath.sh

Documentation: sigs.k8s.io/cli-utils/hack

     1#!/usr/bin/env bash
     2# Copyright 2021 The Kubernetes Authors.
     3# SPDX-License-Identifier: Apache-2.0
     4
     5set -o errexit -o nounset -o pipefail -o posix
     6
     7PKG_PATH="sigs.k8s.io/cli-utils"
     8
     9REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
    10
    11# Make a new temporary GOPATH directory
    12export GOPATH=$(mktemp -d -t cli-utils-gopath.XXXXXXXXXX)
    13# Clean up on exit (modcache has read-only files, so clean that first)
    14trap "go clean -modcache && rm '${GOPATH}/src/${PKG_PATH}' && rm -rf '${GOPATH}'" EXIT
    15
    16# Make sure we can read, write, and delete
    17chmod a+rw "${GOPATH}"
    18
    19# Use a temporary cache
    20export GOCACHE="${GOPATH}/cache"
    21
    22# Create a symlink for the local repo in the GOPATH
    23mkdir -p "${GOPATH}/src/${PKG_PATH}"
    24rm -r "${GOPATH}/src/${PKG_PATH}"
    25ln -s "${REPO_ROOT}" "${GOPATH}/src/${PKG_PATH}"
    26
    27# Make sure our own Go binaries are in PATH.
    28export PATH="${GOPATH}/bin:${PATH}"
    29
    30# Set GOROOT so binaries that parse code can work properly.
    31export GOROOT=$(go env GOROOT)
    32
    33# Unset GOBIN in case it already exists in the current session.
    34unset GOBIN
    35
    36# enter the GOPATH before executing the command
    37cd "${GOPATH}/src/${PKG_PATH}"
    38
    39# Run the user-provided command.
    40"${@}"
    41
    42# exit the GOPATH before deleting it
    43cd "${REPO_ROOT}"

View as plain text