ci: git validation target

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-07-20 14:18:18 +02:00
parent 8b2c54bf57
commit 1a905ab966
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
4 changed files with 45 additions and 5 deletions

View file

@ -8,8 +8,6 @@ on:
tags:
- 'v*'
pull_request:
branches:
- '*'
jobs:
validate:
@ -20,11 +18,14 @@ jobs:
target:
- lint
- validate-vendor
- validate-git
steps:
-
name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
-
name: Run
run: |
make ${{ matrix.target }}
env:
COMMIT_RANGE: ${{ format('{0}..{1}', github.sha, 'HEAD') }}

View file

@ -38,7 +38,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS))
TESTFLAGS ?= -v $(TESTFLAGS_RACE)
TESTFLAGS_PARALLEL ?= 8
.PHONY: all build binaries clean test test-race test-full integration coverage validate lint validate-vendor vendor mod-outdated
.PHONY: all build binaries clean test test-race test-full integration coverage validate lint validate-git validate-vendor vendor mod-outdated
.DEFAULT: all
all: binaries
@ -103,6 +103,9 @@ validate: ## run all validators
lint: ## run all linters
docker buildx bake $@
validate-git: ## validate git
docker buildx bake $@
validate-vendor: ## validate vendor
docker buildx bake $@

View file

@ -3,7 +3,7 @@ group "default" {
}
group "validate" {
targets = ["lint", "validate-vendor"]
targets = ["lint", "validate-git", "validate-vendor"]
}
target "lint" {
@ -11,6 +11,19 @@ target "lint" {
output = ["type=cacheonly"]
}
variable "COMMIT_RANGE" {
default = ""
}
target "validate-git" {
dockerfile = "./dockerfiles/git.Dockerfile"
target = "validate"
args = {
COMMIT_RANGE = COMMIT_RANGE
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
}
output = ["type=cacheonly"]
}
target "validate-vendor" {
dockerfile = "./dockerfiles/vendor.Dockerfile"
target = "validate"

View file

@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.18
ARG ALPINE_VERSION=3.16
FROM alpine:${ALPINE_VERSION} AS base
RUN apk add --no-cache git gpg
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS gitvalidation
ARG GIT_VALIDATION_VERSION=v1.1.0
RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
GOBIN=/out go install "github.com/vbatts/git-validation@${GIT_VALIDATION_VERSION}"
FROM base AS validate
ARG COMMIT_RANGE
RUN if [ -z "$COMMIT_RANGE" ]; then echo "COMMIT_RANGE required" && exit 1; fi
ENV GIT_CHECK_EXCLUDE="./vendor"
WORKDIR /src
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \
--mount=from=gitvalidation,source=/out/git-validation,target=/usr/bin/git-validation \
git-validation -q -range "$COMMIT_RANGE" -run short-subject,dangling-whitespace