Giter Site home page Giter Site logo

boilersuite's Introduction

boilersuite

Boilersuite is a tool for checking license boilerplate in cert-manager projects. It was ported to Golang from a Python script originally written for Kubernetes. That Python script was also used in cert-manager itself.

It uses boilerplate template files to specify how boilerplate should look in a variety of file formats including Makefiles, go files, Dockerfiles and bash scripts.

Since it's written in Go, it's easy to install in projects which already use Go (as is the case for cert-manager). Plus, it doesn't add a dependency on Python allowing for more compact CI environments which don't need to include Python.

Boilerplate Templates

All templates are in boilerplate-templates/ and can be changed as needed. The templates are embedded into the built Go binary to ensure portability.

Templates will be interpreted as:

  • "suffix type" (e.g. boilerplate.go.boilertmpl will be used for *.go files)
  • "prefix type" (e.g. boilerplate.Dockerfile.boilertmpl will be used for Dockerfile or Dockerfile.*)

All templates can be both types, e.g. boilerplate.go.boilertmpl will match main.go and go.mod. There are built-in exceptions made for several files, including go.mod, go.sum, git directories and others.

Validation Process

Assume in this example we're validating a go file, but the same applies to any supported file.

  1. Load and parse all templates, replacing the <<AUTHOR>> marker with the configured author
  2. Find the go template in the list of bundled templates
  3. Check if the file has been generated or marked to be skipped. If so, skip.
  4. Normalise the target file, removing shebang lines, Go build constraints and replacing dates with the <<YEAR>> marker.
  5. Normalise spaces (e.g. Windows newlines, prefixed newlines) in the target file
  6. Ensure the target file is at least as long as the template. If not, it can't possibly match and we error.
  7. Ensure the target file starts with the template. If not, we error.

Running

boilersuite [--skip "paths to skip"] [--author "example"] [--verbose] <path-to-validate>

The --author parameter defaults to cert-manager.

The --skip parameter gives a list of space-separated paths which should not be validated.

The --verbose parameter prints output for every validated file or skipped directory.

The <path-to-validate> can either be a directory (which will be searched recursively) or a single file.

NB: The boilersuite repo (this repo!) includes a set of intentionally incorrect test fixtures under fixture/, and so that directory needs to be skipped when validating this repo specifically. See make validate-local-boilerplate.

Building

make build

After this, boilersuite will be available at _bin/boilersuite.

Testing

make test-all

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.