hack: add license headers tool

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-31 03:33:48 +01:00
parent e218647127
commit 152b37e0f7
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 46 additions and 1 deletions

View File

@ -7,7 +7,7 @@ group "pre-checkin" {
}
group "validate" {
targets = ["lint", "vendor-validate"]
targets = ["lint", "vendor-validate", "license-validate"]
}
target "build" {
@ -69,3 +69,15 @@ target "publish" {
output = ["type=cacheonly"]
secret = ["id=NODE_AUTH_TOKEN,env=NODE_AUTH_TOKEN"]
}
target "license-validate" {
dockerfile = "./hack/dockerfiles/license.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
target "license-update" {
dockerfile = "./hack/dockerfiles/license.Dockerfile"
target = "update"
output = ["."]
}

View File

@ -0,0 +1,33 @@
# syntax=docker/dockerfile:1
ARG LICENSE_HOLDER="actions-toolkit authors"
ARG LICENSE_TYPE="apache"
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.js\|\.ts\|\.hcl\|\.sh\)"
ARG ADDLICENSE_VERSION="v1.0.0"
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
FROM alpine:3.17 AS base
WORKDIR /src
RUN apk add --no-cache cpio findutils git
FROM base AS set
ARG LICENSE_HOLDER
ARG LICENSE_TYPE
ARG LICENSE_FILES
RUN --mount=type=bind,target=.,rw \
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | xargs addlicense -c "$LICENSE_HOLDER" -l "$LICENSE_TYPE" && \
mkdir /out && \
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | cpio -pdm /out
FROM scratch AS update
COPY --from=set /out /
FROM base AS validate
ARG LICENSE_HOLDER
ARG LICENSE_TYPE
ARG LICENSE_FILES
RUN --mount=type=bind,target=. \
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | xargs addlicense -check -c "$LICENSE_HOLDER" -l "$LICENSE_TYPE"