Skip to content

Commit 7c3e7fa

Browse files
committed
feat: license check ci and commands
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent 2b851c9 commit 7c3e7fa

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

.github/workflows/lint.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ on:
44
branches:
55
- main
66
pull_request:
7+
permissions:
8+
contents: read # to fetch code (actions/checkout)
79
jobs:
8-
lint:
9-
name: Lint
10+
validate:
11+
name: Validate license and lint
1012
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
target:
17+
- validate-headers
18+
- lint
1119
permissions:
1220
id-token: write
1321
pull-requests: write
1422
contents: write
1523
steps:
16-
- uses: actions/checkout@v4
24+
- name: Checkout
25+
uses: actions/checkout@v4
1726
- name: Setup Go
1827
uses: actions/setup-go@v5
1928
with:
@@ -31,4 +40,4 @@ jobs:
3140
endpoint: "docker/secrets-engine"
3241
install: true
3342
- name: Lint
34-
run: make BUILDER=${{ steps.buildx.outputs.name }} lint
43+
run: make BUILDER=${{ steps.buildx.outputs.name }} ${{ matrix.target }}

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#syntax=docker/dockerfile:1
22

3+
ARG ALPINE_VERSION=3.23.3
34
ARG GO_VERSION=latest
45
ARG GOLANGCI_LINT_VERSION=v2.2.1
56
ARG OSXCROSS_VERSION=15.5
7+
ARG ADDLICENSE_VERSION=v1.2.0
8+
ARG LICENSE_ARGS="-c 'Docker, Inc.' -l apache -ignore '**/*.yaml' -ignore '**/*.yml' -ignore '.github/**' -ignore 'store/keychain/internal/go-keychain/**' -ignore 'vendor/**' -ignore '.git/**' ."
9+
10+
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
611

712
FROM --platform=${BUILDPLATFORM} golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS lint-base
813

@@ -13,6 +18,32 @@ FROM --platform=${BUILDPLATFORM} crazymax/osxcross:${OSXCROSS_VERSION}-alpine AS
1318
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS gobase
1419
RUN apk add --no-cache findutils build-base git
1520

21+
FROM alpine:${ALPINE_VERSION} AS license-validate
22+
ARG LICENSE_ARGS
23+
COPY --link --from=addlicense /app/addlicense /usr/bin/addlicense
24+
WORKDIR /src
25+
RUN --mount=type=bind,target=.,ro <<EOT
26+
set -eu
27+
echo "== Checking license headers =="
28+
eval "/usr/bin/addlicense -check $LICENSE_ARGS"
29+
EOT
30+
31+
FROM alpine:${ALPINE_VERSION} AS do-license-update
32+
ARG LICENSE_ARGS
33+
COPY --from=addlicense /app/addlicense /usr/bin/addlicense
34+
RUN mkdir -p /generate/out
35+
WORKDIR /src
36+
RUN apk add --no-cache git
37+
RUN --mount=type=bind,target=.,rw <<EOT
38+
set -eu
39+
echo "== Checking license headers =="
40+
eval "/usr/bin/addlicense -v $LICENSE_ARGS"
41+
./scripts/copy-only-diff /generate/out
42+
EOT
43+
44+
FROM scratch AS license-update
45+
COPY --from=do-license-update /generate/out .
46+
1647
FROM gobase AS linux-base
1748
ARG TARGETARCH
1849
ENV GOOS=linux

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,12 @@ help: ## Show this help
132132
@echo Please specify a build target. The choices are:
133133
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(INFO_COLOR)%-30s$(NO_COLOR) %s\n", $$1, $$2}'
134134

135-
.PHONY: run bin format lint proto-lint proto-generate clean help keychain-linux-unit-tests keychain-unit-tests
135+
.PHONY: validate-headers
136+
validate-headers: ## Check license header for all files
137+
@docker buildx build --progress=plain --platform=linux/amd64 --target=license-validate .
138+
139+
.PHONY: update-license-headers
140+
update-license-headers: ## Update license headers for all files
141+
@docker buildx build -o . --progress=plain --platform=linux/amd64 --target=license-update .
142+
143+
.PHONY: run bin format lint proto-lint proto-generate clean help keychain-linux-unit-tests keychain-unit-tests validate-headers

0 commit comments

Comments
 (0)