Skip to content

Commit

Permalink
Generate and verify copyright in source files (shipwright-io#369)
Browse files Browse the repository at this point in the history
* Add script to generate copyright

Per guidance from Red Hat's Open Source Program Office (OSPO), all
source files should have the following copyright notice:

```
Copyright The Shipwright Contributors

SPDX-License-Identifier: Apache-2.0
```

The SPDX-License-Identifier is a stand-in for the standard Apache 2.0
boilerplate notice, with the added benefit that this can be easily
identified by license parsers [1]. Dropping the date in the copyright
notice is likewise acceptable, per the Linux Foundation's latest
guidance [2].

The generator script creates copyright for golang, shell, Markdown, and
Dockerfiles. A Makefile target has also been added.

[1] https://spdx.dev/ids/
[2] https://www.linuxfoundation.org/blog/2020/01/copyright-notices-in-open-source-software-projects/

* make gen-copyright

* Verify copyright

Added Makefile target that verifies copyright is applied to all
files we track. Updated Travis to verify copyright on all PRs.

Note - the following files are excluded from the copyright verifier:

- go.mod and go.sum
- vendor/*
  • Loading branch information
adambkaplan authored Sep 1, 2020
1 parent 051b652 commit ce34d83
Show file tree
Hide file tree
Showing 93 changed files with 523 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ install:
script:
- set -e
- make
- make verify-copyright
# https://github.com/shipwright-io/build/issues/123
- make test-unit-coverage
- make test-e2e TEST_IMAGE_REPO="$(./hack/install-registry.sh show):5000/shipwright-io/build-e2e"
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

FROM openshift/origin-release:golang-1.13 AS builder

ENV LANG=en_US.utf8
Expand Down
6 changes: 6 additions & 0 deletions HACK.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->


# Running the Operator

Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ push-image:
release:
hack/release.sh

.PHONY: gen-copyright
gen-copyright:
hack/generate-copyright.sh

.PHONY: verify-copyright
verify-copyright: gen-copyright
# TODO: Fix travis issue with ginkgo install updating go.mod and go.sum
# TODO: Verify vendor tree is accurate
git diff --quiet -- ':(exclude)go.mod' ':(exclude)go.sum' ':(exclude)vendor/*'

install-ginkgo:
go get -u github.com/onsi/ginkgo/ginkgo
go get -u github.com/onsi/gomega/...
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

<p align="center">
<img alt="Work in Progress" src="https://img.shields.io/badge/Status-Work%20in%20Progress-informational">
<a alt="GoReport" href="https://goreportcard.com/report/github.com/shipwright-io/build">
Expand Down
4 changes: 4 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ENV OPERATOR=/usr/local/bin/build-operator \
Expand Down
5 changes: 5 additions & 0 deletions build/bin/entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/sh -e

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0


# This is documented here:
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines

Expand Down
5 changes: 5 additions & 0 deletions build/bin/user_setup
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/sh

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

set -x

# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be)
Expand Down
4 changes: 4 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright The Shipwright Contributors
//
// SPDX-License-Identifier: Apache-2.0

package main

import (
Expand Down
6 changes: 6 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

# Build Controllers

Build or codenamed **build-v2** is an API open-source implementation that build container-images on Kubernetes from a _dockerfile-based_ or a _source-based_ approach.
Expand Down
6 changes: 6 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

# Build

- [Overview](#overview)
Expand Down
6 changes: 6 additions & 0 deletions docs/buildrun.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

# BuildRun

- [Overview](#overview)
Expand Down
6 changes: 6 additions & 0 deletions docs/buildstrategies.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

# BuildStrategies

- [Overview](#overview)
Expand Down
6 changes: 6 additions & 0 deletions docs/development/deploying.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

# Deploying the operator pod

The following set of steps highlight how to deploy a Build operator pod into an existing Kubernetes cluster.
Expand Down
6 changes: 6 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

# Build Controller Metrics

The Build component exposes several metrics to help you monitor the health and behavior of your build resources.
Expand Down
6 changes: 6 additions & 0 deletions docs/proposals/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

# Enhancement Proposals

An Enhancement Proposal is a way to propose, communicate, and coordinate on new efforts for the `build` project.
Expand Down
6 changes: 6 additions & 0 deletions docs/proposals/build-execution-using-build-run.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

---
title: build-execution-using-build-run
authors:
Expand Down
6 changes: 6 additions & 0 deletions docs/proposals/buildstrategy-steps-resources.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

---
title: Build Strategies steps resource limitations
authors:
Expand Down
6 changes: 6 additions & 0 deletions docs/proposals/buildstrategy.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

---
title: buildstrategy
authors:
Expand Down
6 changes: 6 additions & 0 deletions docs/proposals/guidelines/proposal-template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

---
title: neat-enhancement-idea
authors:
Expand Down
6 changes: 6 additions & 0 deletions docs/proposals/local-registry-image-specs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

---
title: local-registries
authors:
Expand Down
6 changes: 6 additions & 0 deletions docs/proposals/runtime-image.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright The Shipwright Contributors
SPDX-License-Identifier: Apache-2.0
-->

---
title: runtime-image-support
authors:
Expand Down
5 changes: 5 additions & 0 deletions hack/build-logs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0


set -euo pipefail

# Read the build run name
Expand Down
5 changes: 5 additions & 0 deletions hack/crd.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

#
# Manages the deployment and removal of CRDs in a cluster. Usage:
#
Expand Down
111 changes: 111 additions & 0 deletions hack/generate-copyright.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

set -e

copyrightTxt="Copyright The Shipwright Contributors"
spdxTxt="SPDX-License-Identifier: Apache-2.0"

function listPkgDirs() {
go list -f '{{.Dir}}' ./cmd/... ./pkg/... ./test/... ./version/...
local goFiles=$?
}

function listGoFiles() {
# pipeline is much faster than for loop
listPkgDirs | xargs -I {} find {} -name '*.go'
local goFiles=$?
echo $PWD/tools.go
goFiles="$goFiles $?"
}

function listDockerfiles() {
find -name 'Dockerfile*' -not -path './vendor/*'
}

function listBashFiles() {
find -name '*.sh' -not -path './vendor/*'
local bashFiles=$?
find ./build/bin -type f
bashFiles="$bashFiles $?"
}

function listMarkdownFiles() {
find -name '*.md' -not -path './vendor/*'
}

function generateGoCopyright() {
allFiles=$(listGoFiles)

for file in $allFiles ; do
if ! head -n3 "${file}" | grep -Eq "(Copyright|SPDX-License-Identifier)" ; then
cp "${file}" "${file}.bak"
echo "// ${copyrightTxt}" > "${file}"
echo "// " >> "${file}"
echo "// ${spdxTxt}" >> "${file}"
echo "" >> "${file}"
cat "${file}.bak" >> "${file}"
rm "${file}.bak"
fi
done
}

function generateDockerfileCopyright() {
dockerfiles=$(listDockerfiles)
for file in $dockerfiles ; do
if ! head -n3 "${file}" | grep -Eq "(Copyright|SPDX-License-Identifier)" ; then
cp "${file}" "${file}.bak"
echo "# ${copyrightTxt}" > "${file}"
echo "# " >> "${file}"
echo "# ${spdxTxt}" >> "${file}"
echo "" >> "${file}"
cat "${file}.bak" >> "${file}"
rm "${file}.bak"
fi
done
}

function generateBashCopyright() {
bashFiles=$(listBashFiles)
for file in $bashFiles ; do
if ! head -n5 "${file}" | grep -Eq "(Copyright|SPDX-License-Identifier)" ; then
cp "${file}" "${file}.bak"
# Copy the shebang first - this is assumed to be the first line
head -n1 "${file}.bak" > "${file}"
echo "" >> "${file}"
echo "# ${copyrightTxt}" >> "${file}"
echo "# " >> "${file}"
echo "# ${spdxTxt}" >> "${file}"
echo "" >> "${file}"
tail -n +2 "${file}.bak" >> "${file}"
rm "${file}.bak"
fi
done
}

function generateMarkdownCopyright() {
mdFiles=$(listMarkdownFiles)
for file in $mdFiles ; do
if ! head -n4 "${file}" | grep -Eq "(Copyright|SPDX-License-Identifier)" ; then
cp "${file}" "${file}.bak"
echo "<!--" > "${file}"
echo "${copyrightTxt}" >> "${file}"
echo "" >> "${file}"
echo "${spdxTxt}" >> "${file}"
echo "-->" >> "${file}"
echo "" >> "${file}"
cat "${file}.bak" >> "${file}"
rm "${file}.bak"
fi
done
}

generateGoCopyright
generateDockerfileCopyright
generateBashCopyright
generateMarkdownCopyright

set +e
5 changes: 5 additions & 0 deletions hack/generate-fakes.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0


set -euo pipefail

[ ! -d "vendor" ] && echo "$0 requires vendor/ folder, run 'go mod vendor'"
Expand Down
5 changes: 5 additions & 0 deletions hack/install-kind.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

#
# Installs KinD (Kubernetes in Docker) via "go get" and configure it as current context.
#
Expand Down
5 changes: 5 additions & 0 deletions hack/install-kubectl.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

#
# Installs "kubectl" on Travis-CI Ubuntu.
#
Expand Down
5 changes: 5 additions & 0 deletions hack/install-operator-sdk.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

#
# Installs Operator-SDK binary at "$HOME/bin" directory, meant to work in Travis-CI (Ubuntu).
#
Expand Down
Loading

0 comments on commit ce34d83

Please sign in to comment.