From 877d72b10b7b1b2c276535bfaf336254a0e553b2 Mon Sep 17 00:00:00 2001 From: Katrina Verey Date: Fri, 1 Apr 2022 17:42:38 -0400 Subject: [PATCH] Run license check in CI --- .github/workflows/go.yml | 3 +++ Makefile | 18 ++++++------------ hack/add-license.sh | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 12 deletions(-) create mode 100755 hack/add-license.sh diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6a028749a..e593a027c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -29,6 +29,9 @@ jobs: env: KUSTOMIZE_DOCKER_E2E: false # don't need to do e2e tests for linting + - name: Verify boilerplate + run: make check-license + test-linux: name: Test Linux runs-on: [ubuntu-latest] diff --git a/Makefile b/Makefile index 062153e56..97859429f 100644 --- a/Makefile +++ b/Makefile @@ -114,18 +114,12 @@ prow-presubmit-check: \ .PHONY: license license: $(MYGOBIN)/addlicense - $(MYGOBIN)/addlicense \ - -y 2022 \ - -c "The Kubernetes Authors." \ - -f LICENSE_TEMPLATE \ - -ignore "kyaml/internal/forked/github.com/**/*" \ - -ignore "site/**/*" \ - -ignore "**/*.md" \ - -ignore "**/*.json" \ - -ignore "**/*.yml" \ - -ignore "**/*.yaml" \ - -v \ - . + ./hack/add-license.sh run + +.PHONY: check-license +check-license: $(MYGOBIN)/addlicense + ./hack/add-license.sh check + .PHONY: lint lint: $(MYGOBIN)/golangci-lint $(builtinplugins) diff --git a/hack/add-license.sh b/hack/add-license.sh new file mode 100755 index 000000000..ca1da5112 --- /dev/null +++ b/hack/add-license.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Copyright 2019 The Kubernetes Authors. +# SPDX-License-Identifier: Apache-2.0 + +set -x +set -e +set -o pipefail +set -o nounset + +if [[ -z "${1-}" ]] ; then + echo "Usage: $0 " + echo "Example: $0 check" + exit 1 +fi + +if [[ $1 == "check" || $1 == "run" ]]; then + mode=$1 +else + echo "Error: mode must be check or run" + exit 1 +fi + +args=( + -y 2022 + -c "The Kubernetes Authors." + -f LICENSE_TEMPLATE + -ignore "kyaml/internal/forked/github.com/**/*" + -ignore "site/**/*" + -ignore "**/*.md" + -ignore "**/*.json" + -ignore "**/*.yml" + -ignore "**/*.yaml" + -v +) +if [[ $mode == "check" ]]; then + args+=(-check) +fi + +addlicense "${args[@]}" .