Add update_licenses() to library.sh
* Add update_licenses() to library.sh
This function run `dep-collector` in the prow-tests container to update the licenses used by the project.
For an example of usage see knative/serving#1649
* Prefer a system wide dep-collector over the one in the container.
@@ -237,3 +237,25 @@ function start_latest_knative_build() {
kubectl apply -f ${KNATIVE_BUILD_RELEASE} || return 1
wait_until_pods_running knative-build || return 1
}
+
+# Run dep-collector to update licenses.
+# Parameters: $1 - output file, relative to repo root dir.
+# $2...$n - directories and files to inspect.
+function update_licenses() {
+ cd ${REPO_ROOT_DIR} || return 1
+ if [[ ! $PWD =~ (.*)/go/src/(.*) ]]; then
+ echo "ERROR: expected to be under /go/src, but actually in '$PWD'"
+ return 1
+ fi
+ local go_src="/go/src/${BASH_REMATCH[2]}"
+ local dst=$1
+ shift
+ local local_dep_collector="$(which dep-collector)"
+ if [[ -n ${local_dep_collector} ]]; then
+ dep-collector $@ > ./${dst}
+ else
+ docker run -v $PWD:${go_src} --entrypoint sh \
+ gcr.io/knative-tests/test-infra/prow-tests -c \
+ "cd ${go_src} ; dep-collector $@ > ${go_src}/${dst}"
+ fi
+}
