Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: license header gen/check #947

Merged
merged 1 commit into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make license-check

- name: Check license header
env:
GOTEMPLATE_DEBUG: true
GOTEMPLATE_INTERNAL_LOG_LEVEL: debug
GOTEMPLATE_TEMPLATE_LOG_LEVEL: debug
run: make license-header-check

- name: Build
run: |
make generate
Expand Down
40 changes: 28 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SHELL = /bin/bash

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
BIN_DIR := $(PROJECT_DIR)/bin
BOILERPLATE_DIR := $(PROJECT_DIR)/hack/boilerplate

# Image URL to use all building/pushing image targets
TAG ?= $(shell git describe --tags --abbrev=0 --match 'v[0-9].*[0-9].*[0-9]' 2>/dev/null )
Expand Down Expand Up @@ -143,8 +144,8 @@ vet:
cd properties && go vet ./...

# Generate code
generate: bin/controller-gen
cd api && $(CONTROLLER_GEN) object:headerFile=./../hack/boilerplate.go.txt paths="./..."
generate: bin/controller-gen gen-license-header ## Generate source code for APIs, Mocks, etc
cd api && $(CONTROLLER_GEN) object:headerFile=$(BOILERPLATE_DIR)/header.go.generated.txt paths="./..."

# Build the docker image
docker-build:
Expand Down Expand Up @@ -204,23 +205,38 @@ $(BIN_DIR)/addlicense-$(ADDLICENSE_VERSION):
@GOBIN=$(BIN_DIR) go install github.com/google/addlicense@v$(ADDLICENSE_VERSION)
@mv $(BIN_DIR)/addlicense $(BIN_DIR)/addlicense-$(ADDLICENSE_VERSION)

ADDLICENSE_COPYRIGHT_HOLDER := Cisco Systems, Inc. and/or its affiliates
ADDLICENSE_SOURCE_DIRS := api controllers internal pkg properties
ADDLICENSE_SOURCE_DIRS := api controllers internal pkg properties scripts
ADDLICENSE_OPTS_IGNORE := -ignore '**/*.yml' -ignore '**/*.yaml' -ignore '**/*.xml'

.PHONY: license-header-check
license-header-check: bin/addlicense ## Find missing license header in source code files
@bin/addlicense \
-c "$(ADDLICENSE_COPYRIGHT_HOLDER)" \
license-header-check: gen-license-header bin/addlicense ## Find missing license header in source code files
bin/addlicense \
-check \
-s \
-f $(BOILERPLATE_DIR)/header.generated.txt \
$(ADDLICENSE_OPTS_IGNORE) \
$(ADDLICENSE_SOURCE_DIRS)

.PHONY: license-header-fix
license-header-fix: bin/addlicense ## Fix missing license header in source code files
@bin/addlicense \
-c "$(ADDLICENSE_COPYRIGHT_HOLDER)" \
-s \
license-header-fix: gen-license-header bin/addlicense ## Fix missing license header in source code files
bin/addlicense \
-f $(BOILERPLATE_DIR)/header.generated.txt \
$(ADDLICENSE_OPTS_IGNORE) \
$(ADDLICENSE_SOURCE_DIRS)

GOTEMPLATE_VERSION := 3.7.3

bin/gotemplate: $(BIN_DIR)/gotemplate-$(GOTEMPLATE_VERSION)
@ln -sf gotemplate-$(GOTEMPLATE_VERSION) $(BIN_DIR)/gotemplate

$(BIN_DIR)/gotemplate-$(GOTEMPLATE_VERSION):
@mkdir -p $(BIN_DIR)
@GOBIN=$(BIN_DIR) go install github.com/coveooss/gotemplate/v3@v$(GOTEMPLATE_VERSION)
@mv $(BIN_DIR)/gotemplate $(BIN_DIR)/gotemplate-$(GOTEMPLATE_VERSION)

.PHONY: gen-license-header
gen-license-header: bin/gotemplate ## Generate license header used in source code files
GOTEMPLATE_NO_STDIN=true \
$(BIN_DIR)/gotemplate run \
--follow-symlinks \
--import="$(BOILERPLATE_DIR)/vars.yml" \
--source="$(BOILERPLATE_DIR)"
13 changes: 0 additions & 13 deletions hack/boilerplate.go.txt

This file was deleted.

13 changes: 13 additions & 0 deletions hack/boilerplate/header.generated.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2023 Cisco Systems, Inc. and/or its affiliates

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
15 changes: 15 additions & 0 deletions hack/boilerplate/header.go.generated.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2023 Cisco Systems, Inc. and/or its affiliates

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
10 changes: 10 additions & 0 deletions hack/boilerplate/header.go.txt.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Copyright {{ date "2006" now }} {{ .copyright.owner }}

{{ .license.content }}
@-if(.spdx.enabled)
SPDX-FileCopyrightText: {{ date "2006" now }} {{ .copyright.owner }} <{{ .copyright.contact }}>

SPDX-License-Identifier: {{ .license.id }}
@-end
*/
8 changes: 8 additions & 0 deletions hack/boilerplate/header.txt.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright {{ date "2006" now }} {{ .copyright.owner }}

{{ .license.content }}
@-if(.spdx.enabled)
SPDX-FileCopyrightText: {{ date "2006" now }} {{ .copyright.owner }} <{{ .copyright.contact }}>

SPDX-License-Identifier: {{ .license.id }}
@-end
20 changes: 20 additions & 0 deletions hack/boilerplate/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
license:
id: Apache-2.0
content: |-
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
copyright:
owner: Cisco Systems, Inc. and/or its affiliates
contact: https://cisco.com
spdx:
# enable/disable including SPDX fields in license header
enabled: false
14 changes: 14 additions & 0 deletions scripts/image_patch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/usr/bin/env bash
# Copyright 2023 Cisco Systems, Inc. and/or its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


: ${1?"Usage: $0 PATCH_FILE IMG_NAME"}
: ${2?"Usage: $0 PATCH_FILE IMG_NAME"}
Expand Down
14 changes: 14 additions & 0 deletions scripts/increment_version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
# Copyright 2023 Cisco Systems, Inc. and/or its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


while getopts ":Mmp" opt; do
case $opt in
Expand Down
14 changes: 14 additions & 0 deletions scripts/install_kustomize.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/usr/bin/env bash
# Copyright 2023 Cisco Systems, Inc. and/or its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


version=3.1.0
opsys=$(echo "$(uname -s)" | awk '{print tolower($0)}')
Expand Down