Skip to content

Commit

Permalink
Automatically prepend license boilerplate header to release manifests
Browse files Browse the repository at this point in the history
Signed-off-by: James Munnelly <james@munnelly.eu>
  • Loading branch information
munnerz committed Mar 11, 2020
1 parent 5525bc0 commit 61cff09
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
36 changes: 36 additions & 0 deletions build/licensing.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2020 The Jetstack cert-manager contributors.
#
# 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.

def licensed_file(
name,
src,
# Default to use the 'bazel' boilerplate file.
# This uses '#' as a way to denote a comment.
# This will likely need changing depending on the type of the file being
# generated.
license_boilerplate = "//hack/boilerplate:boilerplate.bzl.txt",
**kwargs,
):
native.genrule(
name = "%s.genrule" % name,
srcs = [src, license_boilerplate],
outs = [name],
cmd = " ".join([
"cat",
"$(location %s)" % license_boilerplate,
"$(location %s)" % src,
"> $@",
]),
**kwargs,
)
23 changes: 17 additions & 6 deletions deploy/manifests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports_files(["00-crds.yaml"])

load("@io_k8s_repo_infra//defs:pkg.bzl", "pkg_tar")
load("//build:helm.bzl", "helm_tmpl")
load("//build:licensing.bzl", "licensed_file")

RELEASE_NAME = "cert-manager"

Expand All @@ -23,11 +24,11 @@ VARIANTS = {
) for (name, values) in VARIANTS.items()]

[genrule(
name = "%s.crds" % name,
name = "%s.crds.unlicensed" % name,
srcs = [
"00-crds.yaml",
],
outs = ["%s.crds.yaml" % name],
outs = ["%s.crds.unlicensed.yaml" % name],
cmd = " ".join([
"$(location //hack/filter-crd)",
"-variant=%s" % name,
Expand All @@ -39,23 +40,33 @@ VARIANTS = {
],
) for (name, values) in VARIANTS.items()]

[licensed_file(
name = "%s.crds.yaml" % name,
src = "%s.crds.unlicensed" % name,
) for (name, values) in VARIANTS.items()]

[genrule(
name = name,
name = "%s.unlicensed" % name,
srcs = [
"%s.crds" % name,
"%s.crds.unlicensed" % name,
"01-namespace.yaml",
"%s.manifests" % name,
],
outs = ["%s.yaml" % name],
outs = ["%s.unlicensed.yaml" % name],
cmd = " ".join([
"cat",
"$(location %s.crds)" % name,
"$(location %s.crds.unlicensed)" % name,
"$(location 01-namespace.yaml)",
"$(location %s.manifests)" % name,
"> $@",
]),
) for (name, values) in VARIANTS.items()]

[licensed_file(
name = "%s.yaml" % name,
src = "%s.unlicensed" % name,
) for (name, values) in VARIANTS.items()]

pkg_tar(
name = "manifests",
srcs = [":%s.yaml" % name for name in VARIANTS.keys()] +
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports_files(["boilerplate.go.txt"])
package(default_visibility = ["//visibility:public"])

filegroup(
name = "package-srcs",
Expand Down

0 comments on commit 61cff09

Please sign in to comment.