Skip to content

Commit

Permalink
ci: git validation target
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jul 20, 2022
1 parent 8b2c54b commit 1a905ab
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ on:
tags:
- 'v*'
pull_request:
branches:
- '*'

jobs:
validate:
Expand All @@ -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') }}
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $@

Expand Down
15 changes: 14 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ group "default" {
}

group "validate" {
targets = ["lint", "validate-vendor"]
targets = ["lint", "validate-git", "validate-vendor"]
}

target "lint" {
dockerfile = "./dockerfiles/lint.Dockerfile"
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"
Expand Down
23 changes: 23 additions & 0 deletions dockerfiles/git.Dockerfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1a905ab

Please sign in to comment.