-
Notifications
You must be signed in to change notification settings - Fork 0
CI Integration
The simplest integration: one line of YAML, no binary download, no Docker pull. The action installs the correct binary for the runner OS and architecture, then runs addlicense.
name: License check
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
license:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: GregoireF/addlicense@v0.5.0
with:
args: --check .With a config file (.addlicenserc.yaml), args can be omitted — the default is --check .:
- uses: GregoireF/addlicense@v0.5.0To add headers automatically instead of checking:
- uses: GregoireF/addlicense@v0.5.0
with:
args: --license MIT --author "Your Name" .To use addlicense in multiple steps (setup only):
- uses: GregoireF/addlicense@v0.5.0
with:
args: '' # skip the built-in run step
- name: Check
run: addlicense --check .
- name: Report
run: addlicense --format json . | jq .Supported runners: ubuntu-*, macos-*, windows-* × amd64 + arm64.
name: License check
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
license:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install addlicense
run: |
curl -sSL https://github.com/GregoireF/addlicense/releases/latest/download/addlicense_linux_amd64.tar.gz \
| tar -xz -C /usr/local/bin addlicense
- name: Check license headers
run: addlicense --check . - name: Check license headers
run: |
docker run --rm -v "$PWD:/src" -w /src \
ghcr.io/gregoiref/addlicense:latest --check .name: Add license headers
on:
pull_request:
types: [opened, synchronize]
permissions:
contents: write
jobs:
add-headers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install addlicense
run: |
curl -sSL https://github.com/GregoireF/addlicense/releases/latest/download/addlicense_linux_amd64.tar.gz \
| tar -xz -C /usr/local/bin addlicense
- name: Add missing headers
run: addlicense --license MIT --author "Your Name" .
- name: Commit if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git diff --quiet || git commit -am "chore: add missing license headers"
git pushWhen the repo has a config file, the check command needs no extra flags:
- name: Check license headers
run: addlicense --check .license-check:
image: alpine:latest
stage: test
before_script:
- apk add --no-cache curl tar
- curl -sSL https://github.com/GregoireF/addlicense/releases/latest/download/addlicense_linux_amd64.tar.gz
| tar -xz -C /usr/local/bin addlicense
script:
- addlicense --check .addlicense ships an official .pre-commit-hooks.yaml since v0.4.0. pre-commit installs the binary automatically via go install — no manual setup required.
# .pre-commit-config.yaml
repos:
- repo: https://github.com/GregoireF/addlicense
rev: v0.4.0
hooks:
- id: addlicense-check
# optionally pass flags; or rely on .addlicenserc.yaml
# args: [--license, MIT, --author, "Your Name"]This hook exits non-zero if any tracked source file is missing a header. It does not modify files, making it safe for all CI runners.
repos:
- repo: https://github.com/GregoireF/addlicense
rev: v0.4.0
hooks:
- id: addlicense-add
args: [--license, MIT, --author, "Your Name"]This hook injects missing headers before the commit is finalised. If you use a config file (.addlicenserc.yaml), you can omit the args.
repos:
- repo: https://github.com/GregoireF/addlicense
rev: v0.4.0
hooks:
- id: addlicense-add # inject first
- id: addlicense-check # then verify.PHONY: license-check license-add
license-check:
addlicense --check .
license-add:
addlicense --license MIT --author "Your Name" .To avoid breaking CI when a new release ships, pin to a specific version:
- name: Install addlicense v0.4.0
run: |
curl -sSL https://github.com/GregoireF/addlicense/releases/download/v0.4.0/addlicense_linux_amd64.tar.gz \
| tar -xz -C /usr/local/bin addlicenseOr with Docker:
run: docker run --rm -v "$PWD:/src" -w /src ghcr.io/gregoiref/addlicense:v0.4.0 --check .addlicense's default ignore list covers vendor, node_modules, *.pb.go, *.gen.go. For additional paths, use --ignore or a config file:
- name: Check license headers
run: addlicense --check --ignore "third_party,testdata,*.mock.go" .