Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor validation #230

Merged
merged 1 commit into from Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -14,6 +14,25 @@ env:
GO_VERSION: 1.16.7

jobs:
validate:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
target:
- validate-vendor
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Run
run: |
make ${{ matrix.target }}

test:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
31 changes: 30 additions & 1 deletion Dockerfile
Expand Up @@ -14,11 +14,40 @@ FROM crazymax/osxcross:${OSXCROSS_VERSION} AS osxcross

FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS gobase
COPY --from=xx / /
RUN apk add --no-cache clang file git lld llvm pkgconf
RUN apk add --no-cache clang file git lld llvm pkgconf rsync
ENV GOFLAGS="-mod=vendor"
ENV CGO_ENABLED="1"
WORKDIR /src

FROM gobase AS vendored
RUN --mount=target=/context \
--mount=target=.,type=tmpfs \
--mount=target=/go/pkg/mod,type=cache <<EOT
set -e
rsync -a /context/. .
go mod tidy
go mod vendor
mkdir /out
cp -r go.mod go.sum vendor /out
EOT

FROM scratch AS vendor-update
COPY --from=vendored /out /

FROM vendored AS vendor-validate
RUN --mount=type=bind,target=.,rw <<EOT
set -e
rsync -a /context/. .
git add -A
rm -rf vendor
cp -rf /out/* .
if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"'
git status --porcelain -- go.mod go.sum vendor
exit 1
fi
EOT

FROM gobase AS version
ARG PKG
RUN --mount=target=. \
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Expand Up @@ -83,3 +83,15 @@ deb:
.
docker run --rm --net=none $(BUILDIMG) tar cf - /release | tar xf -
docker rmi $(BUILDIMG)

.PHONY: vendor
vendor:
$(eval $@_TMP_OUT := $(shell mktemp -d -t docker-output.XXXXXXXXXX))
docker buildx bake --set "*.output=type=local,dest=$($@_TMP_OUT)" vendor
rm -rf ./vendor
cp -R "$($@_TMP_OUT)"/* .
rm -rf "$($@_TMP_OUT)"

.PHONY: validate-vendor
validate-vendor:
docker buildx bake vendor-validate
14 changes: 14 additions & 0 deletions docker-bake.hcl
Expand Up @@ -21,6 +21,20 @@ group "default" {
targets = ["binaries"]
}

group "validate" {
targets = ["vendor-validate"]
}

target "vendor-validate" {
target = "vendor-validate"
output = ["type=cacheonly"]
}

target "vendor" {
target = "vendor-update"
output = ["."]
}

target "test" {
inherits = ["_common"]
target = "test-coverage"
Expand Down