Repository: tektoncd/pipeline (language: go)

Issue:
Remove temporary `GOPATH`  creation for codegen and openapigen.
## Summary

Running `make generated` takes locally 15-20min, under the hood the `setup-temporary-gopath.sh` is called which uses the legacy `GOPATH` configuration, creates a temporary directory and downloads all the dependencies every time once for `codegen` and once for `openaipgen`.

```txt
You appear to be running from outside of GOPATH.
This script will create a temporary GOPATH at /tmp/tmp.6VNP0PcJTs/.gopath for code generation.
Moving to /tmp/tmp.6VNP0PcJTs/.gopath/src/github.com/tektoncd/pipeline
```

Running `make generated` without `setup-temporary-gopath.sh` takes under 2min.

## Tasks

- [x] Remove  `setup-temporary-gopath.sh` from `update-codegen.sh` and `update-openapigen.sh`.
- [x] Validate build, tests and CI remain running.



Discussion / hints:

Fix patch:
diff --git a/hack/setup-temporary-gopath.sh b/hack/setup-temporary-gopath.sh
deleted file mode 100755
index f16c051485b..00000000000
--- a/hack/setup-temporary-gopath.sh
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env bash
-
-set -o errexit
-set -o nounset
-
-# Conditionally create a temporary GOPATH for codegen
-# and openapigen to execute in. This is only done if
-# the current repo directory is not within GOPATH.
-function shim_gopath() {
-  local REPO_DIR=$(git rev-parse --show-toplevel)
-  local TEMP_GOPATH="$(mktemp -d)/.gopath"
-  local TEMP_TEKTONCD="${TEMP_GOPATH}/src/github.com/tektoncd"
-  local TEMP_PIPELINE="${TEMP_TEKTONCD}/pipeline"
-  local NEEDS_MOVE=1
-
-  # Checks if GOPATH exists without triggering nounset panic.
-  EXISTING_GOPATH=${GOPATH:-}
-
-  # Check if repo is in GOPATH already and return early if so.
-  # Unfortunately this doesn't respect a repo that's symlinked into
-  # GOPATH and will create a temporary anyway. I couldn't figure out
-  # a way to get the absolute path to the symlinked repo root.
-  if [ ! -z $EXISTING_GOPATH ] ; then
-    case $REPO_DIR/ in
-      $EXISTING_GOPATH/*) NEEDS_MOVE=0;;
-      *) NEEDS_MOVE=1;;
-    esac
-  fi
-
-  if [ $NEEDS_MOVE -eq 0 ]; then
-    return
-  fi
-
-  echo "You appear to be running from outside of GOPATH."
-  echo "This script will create a temporary GOPATH at $TEMP_GOPATH for code generation."
-
-  # Ensure that the temporary pipelines symlink doesn't exist
-  # before proceeding.
-  delete_pipeline_repo_symlink
-
-  mkdir -p "$TEMP_TEKTONCD"
-  # This will create a symlink from
-  # $(mktemp -d)/.gopath/src/github.com/tektoncd/pipeline
-  # to the user's pipeline checkout.
-  ln -s "$REPO_DIR" "$TEMP_PIPELINE"
-  echo "Moving to $TEMP_PIPELINE"
-  cd "$TEMP_PIPELINE"
-  export GOPATH="$TEMP_GOPATH"
-}
-
-# Helper that wraps deleting the temp pipelines repo symlink
-# and prints a message about deleting the temp GOPATH.
-#
-# Why doesn't this func just delete the temp GOPATH outright?
-# Because it might be reused across multiple hack scripts and many
-# packages seem to be installed into GOPATH with read-only
-# permissions, requiring sudo to delete the directory. Rather
-# than surprise the dev with a password entry at the end of the
-# script's execution we just print a message to let them know.
-function shim_gopath_clean() {
-  local REPO_DIR=$(git rev-parse --show-toplevel)
-  local TEMP_GOPATH="$(mktemp -d)/.gopath"
-  if [ -d "$TEMP_GOPATH" ] ; then
-    # Put the user back at the root of the pipelines repo
-    # after all the symlink shenanigans.
-    echo "Moving to $REPO_DIR"
-    cd "$REPO_DIR"
-    delete_pipeline_repo_symlink
-    echo "When you are finished with codegen you can safely run the following:"
-    echo "sudo rm -rf \".gopath\""
-   fi
-}
-
-# Delete the temp symlink to pipelines repo from the temp GOPATH dir.
-function delete_pipeline_repo_symlink() {
-  local REPO_DIR=$(git rev-parse --show-toplevel)
-  local TEMP_GOPATH="$(mktemp -d)/.gopath"
-  if [ -d "$TEMP_GOPATH" ] ; then
-    local REPO_SYMLINK="${TEMP_GOPATH}/src/github.com/tektoncd/pipeline"
-    if [ -L $REPO_SYMLINK ] ; then
-      echo "Deleting symlink to pipelines repo $REPO_SYMLINK"
-      rm -f "${REPO_SYMLINK}"
-    fi
-  fi
-}
diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh
index 8110cbc31ac..4fcf496b4a7 100755
--- a/hack/update-codegen.sh
+++ b/hack/update-codegen.sh
@@ -18,11 +18,6 @@ set -o errexit
 set -o nounset
 set -o pipefail
 
-source $(git rev-parse --show-toplevel)/hack/setup-temporary-gopath.sh
-shim_gopath
-trap shim_gopath_clean EXIT
-
-# source $(git rev-parse --show-toplevel)/vendor/github.com/tektoncd/plumbing/scripts/library.sh
 source $(git rev-parse --show-toplevel)/vendor/knative.dev/hack/codegen-library.sh
 
 PREFIX=${GOBIN:-${GOPATH}/bin}
diff --git a/hack/update-openapigen.sh b/hack/update-openapigen.sh
index c1595b300a8..f735c785e7a 100755
--- a/hack/update-openapigen.sh
+++ b/hack/update-openapigen.sh
@@ -18,18 +18,15 @@ set -o errexit
 set -o nounset
 
 source $(git rev-parse --show-toplevel)/vendor/github.com/tektoncd/plumbing/scripts/library.sh
-source $(git rev-parse --show-toplevel)/hack/setup-temporary-gopath.sh
 
 readonly TMP_DIFFROOT="$(mktemp -d ${REPO_ROOT_DIR}/tmpdiffroot.XXXXXX)"
 
 cleanup() {
   rm -rf "${TMP_DIFFROOT}"
-  shim_gopath_clean
 }
 
 cleanup
 
-shim_gopath
 mkdir -p "${TMP_DIFFROOT}"
 
 trap cleanup EXIT
@@ -44,11 +41,11 @@ do
 
   echo "Generating OpenAPI specification for ${APIVERSION} ..."
   GOFLAGS="-mod=mod" go run k8s.io/kube-openapi/cmd/openapi-gen \
-     --output-pkg github.com/tektoncd/pipeline/pkg/apis/pipeline/${APIVERSION} \
-     --output-dir ./pkg/apis/pipeline/${APIVERSION} \
-     --output-file openapi_generated.go \
-      --go-header-file hack/boilerplate/boilerplate.go.txt \
-      -r "${TMP_DIFFROOT}/api-report" ${input_dirs}
+    --output-pkg github.com/tektoncd/pipeline/pkg/apis/pipeline/${APIVERSION} \
+    --output-dir ./pkg/apis/pipeline/${APIVERSION} \
+    --output-file openapi_generated.go \
+    --go-header-file hack/boilerplate/boilerplate.go.txt \
+    -r "${TMP_DIFFROOT}/api-report" ${input_dirs}
 
   violations=$(diff --changed-group-format='%>' --unchanged-group-format='' <(sort "hack/ignored-openapi-violations.list") <(sort "${TMP_DIFFROOT}/api-report") || echo "")
   if [ -n "${violations}" ]; then


Test patch: