Repository: knative/pkg
Pull request #2430 (2022-02-17 01:26:56)

[main] Update actions
Cron -knative-prow-robot

/cc knative/serving-writers knative/eventing-writers
/assign knative/serving-writers knative/eventing-writers

Produced by: knative-sandbox/knobots/actions/update-actions

Details:
```

```

knative-prow-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2430#" title="Author self-approved">knative-automation</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **tcnghia** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @tcnghia` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/knative/pkg/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["tcnghia"]} -->
knative-prow-robot: @knative-automation: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-knative-pkg-unit-tests | 5365915c6a435d247fad7b1f80d9d908e6e5a61d | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/2430/pull-knative-pkg-unit-tests/1494121155148124160) | true | `/test pull-knative-pkg-unit-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_pkg/2430). [Your PR dashboard](https://gubernator.knative.dev/pr/knative-automation).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->

Patch:
diff --git a/.github/workflows/knative-style.yaml b/.github/workflows/knative-style.yaml
index ae84f7d34..e34df9328 100644
--- a/.github/workflows/knative-style.yaml
+++ b/.github/workflows/knative-style.yaml
@@ -246,6 +246,7 @@ jobs:
             cat > .wokeignore <<EOF
             vendor/*
             third_party/*
+            *.svg
           EOF
           fi
 
diff --git a/apis/url.go b/apis/url.go
index 89a4d2454..e54cb1d07 100644
--- a/apis/url.go
+++ b/apis/url.go
@@ -27,6 +27,7 @@ import (
 // URL is an alias of url.URL.
 // It has custom json marshal methods that enable it to be used in K8s CRDs
 // such that the CRD resource will have the URL but operator code can can work with url.URL struct
+// +kubebuilder:validation:Type=string
 type URL url.URL
 
 // ParseURL attempts to parse the given string as a URL.
diff --git a/changeset/commit.go b/changeset/commit.go
index 52c77998f..3668dfebd 100644
--- a/changeset/commit.go
+++ b/changeset/commit.go
@@ -17,6 +17,7 @@ limitations under the License.
 package changeset
 
 import (
+	"bufio"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -28,6 +29,10 @@ import (
 const (
 	commitIDFile      = "HEAD"
 	koDataPathEnvName = "KO_DATA_PATH"
+	// packedRefsFile is a file containing a list of refs, used to compact the
+	// list of refs instead of storing them on the filesystem directly.
+	// See https://git-scm.com/docs/git-pack-refs
+	packedRefsFile = "packed-refs"
 )
 
 var commitIDRE = regexp.MustCompile(`^[a-f0-9]{40}$`)
@@ -41,9 +46,27 @@ func Get() (string, error) {
 	}
 	commitID := strings.TrimSpace(string(data))
 	if rID := strings.TrimPrefix(commitID, "ref: "); rID != commitID {
+		// First try to read from the direct ref file - e.g. refs/heads/main
 		data, err := readFileFromKoData(rID)
 		if err != nil {
-			return "", err
+			if !os.IsNotExist(err) {
+				return "", err
+			}
+
+			// Ref file didn't exist - it might be contained in the packed-refs
+			// file.
+			var pferr error
+			data, pferr = findPackedRef(rID)
+			// Only return the sub-error if the packed-refs file exists, otherwise
+			// just let the original error return (e.g. treat it as if we didn't
+			// even attempt the operation). This is primarily to keep the error
+			// messages clean.
+			if pferr != nil {
+				if os.IsNotExist(pferr) {
+					return "", err
+				}
+				return "", pferr
+			}
 		}
 		commitID = strings.TrimSpace(string(data))
 	}
@@ -58,9 +81,49 @@ func Get() (string, error) {
 // to be wrapped into the container from /kodata by ko. If it fails, returns
 // the error it gets.
 func readFileFromKoData(filename string) ([]byte, error) {
+	f, err := koDataFile(filename)
+	if err != nil {
+		return nil, err
+	}
+	defer f.Close()
+	return ioutil.ReadAll(f)
+}
+
+// readFileFromKoData tries to open the file with given name under KO_DATA_PATH.
+// The file is expected to be wrapped into the container from /kodata by ko.
+// If it fails, returns the error it gets.
+func koDataFile(filename string) (*os.File, error) {
 	koDataPath := os.Getenv(koDataPathEnvName)
 	if koDataPath == "" {
 		return nil, fmt.Errorf("%q does not exist or is empty", koDataPathEnvName)
 	}
-	return ioutil.ReadFile(filepath.Join(koDataPath, filename))
+	return os.Open(filepath.Join(koDataPath, filename))
+}
+
+// findPackedRef searches the packed-ref file for ref values.
+// This can happen if the # of refs in a repo grows too much - git will try
+// and condense them into a file.
+// See https://git-scm.com/docs/git-pack-refs
+func findPackedRef(ref string) ([]byte, error) {
+	f, err := koDataFile(packedRefsFile)
+	if err != nil {
+		return nil, err
+	}
+	defer f.Close()
+
+	scanner := bufio.NewScanner(f)
+	for scanner.Scan() {
+		// We only care about lines with `<commit> <ref>` pairs.
+		// Why this might happen:
+		// 1. Lines starting with ^ refer to unpeeled tag SHAs
+		// 	  (e.g. the commits pointed to by annotated tags)
+		s := strings.Split(scanner.Text(), " ")
+		if len(s) != 2 {
+			continue
+		}
+		if ref == s[1] {
+			return []byte(s[0]), nil
+		}
+	}
+	return nil, fmt.Errorf("%q ref not found in packed-refs", ref)
 }
diff --git a/go.mod b/go.mod
index 7f5d14e88..94b63aa47 100644
--- a/go.mod
+++ b/go.mod
@@ -48,7 +48,7 @@ require (
 	k8s.io/code-generator v0.22.5
 	k8s.io/gengo v0.0.0-20211129171323-c02415ce4185
 	k8s.io/klog/v2 v2.40.1
-	knative.dev/hack v0.0.0-20220209225905-7331bb16ba00
+	knative.dev/hack v0.0.0-20220216040439-0456e8bf6547
 	sigs.k8s.io/yaml v1.3.0
 )
 
diff --git a/go.sum b/go.sum
index 8f5639cec..cf590afa0 100644
--- a/go.sum
+++ b/go.sum
@@ -1152,8 +1152,8 @@ k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c h1:jvamsI1tn9V0S8jicyX82q
 k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
 k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a h1:8dYfu/Fc9Gz2rNJKB9IQRGgQOh2clmRzNIPPY1xLY5g=
 k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
-knative.dev/hack v0.0.0-20220209225905-7331bb16ba00 h1:MbdDq3JZoCoUzYbw/liB0Idklk/fE2bXiSQnIRhgeC4=
-knative.dev/hack v0.0.0-20220209225905-7331bb16ba00/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
+knative.dev/hack v0.0.0-20220216040439-0456e8bf6547 h1:lEWsaG/yMLLp3onNushrawsHFXD4LXCXTo5FUUa2GiU=
+knative.dev/hack v0.0.0-20220216040439-0456e8bf6547/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
 pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
 pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
 rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
diff --git a/vendor/knative.dev/hack/README.md b/vendor/knative.dev/hack/README.md
index 570f37097..de565f7c5 100644
--- a/vendor/knative.dev/hack/README.md
+++ b/vendor/knative.dev/hack/README.md
@@ -111,7 +111,7 @@ main "$@"
 This is a helper script for Knative E2E test scripts. To use it:
 
 1. [optional] Customize the test cluster. Pass the flags as described
-   [here](../kntest/pkg/kubetest2/gke/README.md) to the `initialize` function
+   [here](../tools/kntest/pkg/kubetest2/gke/README.md) to the `initialize` function
    call if the default values don't fit your needs.
 
 1. Source the script.
diff --git a/vendor/knative.dev/hack/library.sh b/vendor/knative.dev/hack/library.sh
index 17ce662ed..8f7b3997e 100644
--- a/vendor/knative.dev/hack/library.sh
+++ b/vendor/knative.dev/hack/library.sh
@@ -695,7 +695,7 @@ function go_mod_gopath_hack() {
 # Parameters: $1..$n - parameters passed to the tool.
 function run_kntest() {
   if [[ ! -x "$(command -v kntest)" ]]; then
-    echo "--- FAIL: kntest not installed, please clone knative test-infra repo and run \`go install ./kntest/cmd/kntest\` to install it"; return 1;
+    echo "--- FAIL: kntest not installed, please clone knative test-infra repo and run \`go install ./tools/kntest/cmd/kntest\` to install it"; return 1;
   fi
   kntest "$@"
 }
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 1da7e5475..bdc8e5e00 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -1060,7 +1060,7 @@ k8s.io/utils/buffer
 k8s.io/utils/integer
 k8s.io/utils/pointer
 k8s.io/utils/trace
-# knative.dev/hack v0.0.0-20220209225905-7331bb16ba00
+# knative.dev/hack v0.0.0-20220216040439-0456e8bf6547
 ## explicit; go 1.14
 knative.dev/hack
 # sigs.k8s.io/structured-merge-diff/v4 v4.1.2


Test patch:
diff --git a/changeset/commit_test.go b/changeset/commit_test.go
index 6552971eb..057bccfe0 100644
--- a/changeset/commit_test.go
+++ b/changeset/commit_test.go
@@ -70,6 +70,15 @@ func TestReadFile(t *testing.T) {
 		koDataPath: "testdata/nonexisting",
 		wantErr:    true,
 		err:        errors.New("open testdata/nonexisting/HEAD: no such file or directory"),
+	}, {
+		name:       "packed-ref",
+		koDataPath: "testdata/packed-refs",
+		want:       testCommitID,
+	}, {
+		name:       "no refs with packed-ref",
+		koDataPath: "testdata/noncommited-packed-refs",
+		wantErr:    true,
+		err:        fmt.Errorf("%q ref not found in packed-refs", nonCommittedHeadRef),
 	}}
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
diff --git a/changeset/testdata/noncommited-packed-refs/HEAD b/changeset/testdata/noncommited-packed-refs/HEAD
new file mode 100644
index 000000000..89fe2d356
--- /dev/null
+++ b/changeset/testdata/noncommited-packed-refs/HEAD
@@ -0,0 +1,1 @@
+ref: refs/heads/non_committed_branch
diff --git a/changeset/testdata/noncommited-packed-refs/packed-refs b/changeset/testdata/noncommited-packed-refs/packed-refs
new file mode 100644
index 000000000..e69de29bb
diff --git a/changeset/testdata/packed-refs/HEAD b/changeset/testdata/packed-refs/HEAD
new file mode 100644
index 000000000..19af7398c
--- /dev/null
+++ b/changeset/testdata/packed-refs/HEAD
@@ -0,0 +1,1 @@
+ref: refs/heads/foo
diff --git a/changeset/testdata/packed-refs/packed-refs b/changeset/testdata/packed-refs/packed-refs
new file mode 100644
index 000000000..634ca6720
--- /dev/null
+++ b/changeset/testdata/packed-refs/packed-refs
@@ -0,0 +1,4 @@
+a2d1bdfe929516d7da141aef68631a7ee6941b2d refs/tags/bar
+^51be315ed160e68627a3bc51a244ec77e470c667
+a2d1bdfe929516d7da141aef68631a7ee6941b2d refs/tags/baz
+a2d1bdfe929516d7da141aef68631a7ee6941b2d refs/heads/foo