Skip to content

Commit e5695df

Browse files
committed
vendor update and validation
Signed-off-by: CrazyMax <[email protected]>
1 parent 6627597 commit e5695df

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

.github/workflows/build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ env:
1414
GO_VERSION: 1.16.7
1515

1616
jobs:
17+
validate:
18+
runs-on: ubuntu-20.04
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
target:
23+
- validate-vendor
24+
steps:
25+
-
26+
name: Checkout
27+
uses: actions/checkout@v3
28+
-
29+
name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v2
31+
-
32+
name: Run
33+
run: |
34+
make ${{ matrix.target }}
35+
1736
test:
1837
runs-on: ${{ matrix.os }}
1938
strategy:

Dockerfile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,40 @@ FROM crazymax/osxcross:${OSXCROSS_VERSION} AS osxcross
1414

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

22+
FROM gobase AS vendored
23+
RUN --mount=target=/context \
24+
--mount=target=.,type=tmpfs \
25+
--mount=target=/go/pkg/mod,type=cache <<EOT
26+
set -e
27+
rsync -a /context/. .
28+
go mod tidy
29+
go mod vendor
30+
mkdir /out
31+
cp -r go.mod go.sum vendor /out
32+
EOT
33+
34+
FROM scratch AS vendor-update
35+
COPY --from=vendored /out /
36+
37+
FROM vendored AS vendor-validate
38+
RUN --mount=type=bind,target=.,rw <<EOT
39+
set -e
40+
rsync -a /context/. .
41+
git add -A
42+
rm -rf vendor
43+
cp -rf /out/* .
44+
if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then
45+
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"'
46+
git status --porcelain -- go.mod go.sum vendor
47+
exit 1
48+
fi
49+
EOT
50+
2251
FROM gobase AS version
2352
ARG PKG
2453
RUN --mount=target=. \

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,15 @@ deb:
8383
.
8484
docker run --rm --net=none $(BUILDIMG) tar cf - /release | tar xf -
8585
docker rmi $(BUILDIMG)
86+
87+
.PHONY: vendor
88+
vendor:
89+
$(eval $@_TMP_OUT := $(shell mktemp -d -t docker-output.XXXXXXXXXX))
90+
docker buildx bake --set "*.output=type=local,dest=$($@_TMP_OUT)" vendor
91+
rm -rf ./vendor
92+
cp -R "$($@_TMP_OUT)"/* .
93+
rm -rf "$($@_TMP_OUT)"
94+
95+
.PHONY: validate-vendor
96+
validate-vendor:
97+
docker buildx bake vendor-validate

docker-bake.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ group "default" {
2121
targets = ["binaries"]
2222
}
2323

24+
group "validate" {
25+
targets = ["vendor-validate"]
26+
}
27+
28+
target "vendor-validate" {
29+
target = "vendor-validate"
30+
output = ["type=cacheonly"]
31+
}
32+
33+
target "vendor" {
34+
target = "vendor-update"
35+
output = ["."]
36+
}
37+
2438
target "test" {
2539
inherits = ["_common"]
2640
target = "test-coverage"

0 commit comments

Comments
 (0)