Merge pull request #3644 from crazy-max/cleanup-ci

ci: cleanup ci workflow
This commit is contained in:
Milos Gajdos 2022-07-21 09:35:39 +01:00 committed by GitHub
commit df14ebe142
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 118 additions and 114 deletions

View file

@ -15,8 +15,37 @@ env:
DOCKERHUB_SLUG: distribution/distribution DOCKERHUB_SLUG: distribution/distribution
jobs: jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go:
- 1.17
- 1.18
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
-
name: Test
run: |
make coverage
-
name: Codecov
uses: codecov/codecov-action@v3
with:
directory: ./
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs:
- test
steps: steps:
- -
name: Checkout name: Checkout

View file

@ -1,56 +0,0 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
strategy:
matrix:
go-version: ["1.17.x", "1.18.x"]
platform: ["ubuntu-latest"]
runs-on: ${{ matrix.platform }}
env:
DOCKER_BUILDTAGS: "include_oss include_gcs"
CGO_ENABLED: 1
GO111MODULE: "auto"
GOPATH: ${{ github.workspace }}
GOOS: linux
COMMIT_RANGE: ${{ github.event_name == 'pull_request' && format('{0}..{1}',github.event.pull_request.base.sha, github.event.pull_request.head.sha) || format('{0}..{1}', github.event.before, github.event.after) }}
steps:
- uses: actions/checkout@v2
with:
path: src/github.com/distribution/distribution
fetch-depth: 50
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Dependencies
run: |
sudo apt-get -q update
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install python2-minimal
cd /tmp && go install github.com/vbatts/git-validation@latest
- name: Build
working-directory: ./src/github.com/distribution/distribution
run: |
DCO_VERBOSITY=-q script/validate/dco
go build -i .
make build
make binaries
if [ "$GOOS" = "linux" ]; then make coverage ; fi
- uses: codecov/codecov-action@v1
with:
directory: ./src/github.com/distribution/distribution

View file

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

View file

@ -1,10 +1,11 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
ARG GO_VERSION=1.18 ARG GO_VERSION=1.18
ARG ALPINE_VERSION=3.16
ARG XX_VERSION=1.1.1 ARG XX_VERSION=1.1.1
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
COPY --from=xx / / COPY --from=xx / /
RUN apk add --no-cache bash coreutils file git RUN apk add --no-cache bash coreutils file git
ENV GO111MODULE=auto ENV GO111MODULE=auto
@ -23,11 +24,11 @@ ARG TARGETPLATFORM
ARG LDFLAGS="-s -w" ARG LDFLAGS="-s -w"
ARG BUILDTAGS="include_oss include_gcs" ARG BUILDTAGS="include_oss include_gcs"
RUN --mount=type=bind,target=/src,rw \ RUN --mount=type=bind,target=/src,rw \
--mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/root/.cache/go-build \
--mount=target=/go/pkg/mod,type=cache \ --mount=target=/go/pkg/mod,type=cache \
--mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \ --mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
set -x ; xx-go build -trimpath -ldflags "$(cat /tmp/.ldflags) ${LDFLAGS}" -o /usr/bin/registry ./cmd/registry \ set -x ; xx-go build -trimpath -ldflags "$(cat /tmp/.ldflags) ${LDFLAGS}" -o /usr/bin/registry ./cmd/registry \
&& xx-verify --static /usr/bin/registry && xx-verify --static /usr/bin/registry
FROM scratch AS binary FROM scratch AS binary
COPY --from=build /usr/bin/registry / COPY --from=build /usr/bin/registry /
@ -38,18 +39,18 @@ ARG TARGETARCH
ARG TARGETVARIANT ARG TARGETVARIANT
WORKDIR /work WORKDIR /work
RUN --mount=from=binary,target=/build \ RUN --mount=from=binary,target=/build \
--mount=type=bind,target=/src \ --mount=type=bind,target=/src \
--mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \ --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \
VERSION=$(cat /tmp/.version) \ VERSION=$(cat /tmp/.version) \
&& mkdir -p /out \ && mkdir -p /out \
&& cp /build/registry /src/README.md /src/LICENSE . \ && cp /build/registry /src/README.md /src/LICENSE . \
&& tar -czvf "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" * \ && tar -czvf "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" * \
&& sha256sum -z "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" | awk '{ print $1 }' > "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz.sha256" && sha256sum -z "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz" | awk '{ print $1 }' > "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.tgz.sha256"
FROM scratch AS artifact FROM scratch AS artifact
COPY --from=releaser /out / COPY --from=releaser /out /
FROM alpine:3.16 FROM alpine:${ALPINE_VERSION}
RUN apk add --no-cache ca-certificates RUN apk add --no-cache ca-certificates
COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml
COPY --from=binary /registry /bin/registry COPY --from=binary /registry /bin/registry

View file

@ -38,7 +38,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS))
TESTFLAGS ?= -v $(TESTFLAGS_RACE) TESTFLAGS ?= -v $(TESTFLAGS_RACE)
TESTFLAGS_PARALLEL ?= 8 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 .DEFAULT: all
all: binaries all: binaries
@ -103,6 +103,9 @@ validate: ## run all validators
lint: ## run all linters lint: ## run all linters
docker buildx bake $@ docker buildx bake $@
validate-git: ## validate git
docker buildx bake $@
validate-vendor: ## validate vendor validate-vendor: ## validate vendor
docker buildx bake $@ docker buildx bake $@

View file

@ -3,7 +3,7 @@ group "default" {
} }
group "validate" { group "validate" {
targets = ["lint", "validate-vendor"] targets = ["lint", "validate-git", "validate-vendor"]
} }
target "lint" { target "lint" {
@ -11,6 +11,19 @@ target "lint" {
output = ["type=cacheonly"] 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" { target "validate-vendor" {
dockerfile = "./dockerfiles/vendor.Dockerfile" dockerfile = "./dockerfiles/vendor.Dockerfile"
target = "validate" 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

View file

@ -1,17 +1,18 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
ARG GO_VERSION=1.18 ARG GO_VERSION=1.18
ARG ALPINE_VERSION=3.16
ARG GOLANGCI_LINT_VERSION=v1.45 ARG GOLANGCI_LINT_VERSION=v1.45
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
FROM golang:${GO_VERSION}-alpine AS base FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
RUN apk add --no-cache gcc musl-dev RUN apk add --no-cache gcc musl-dev
WORKDIR /src WORKDIR /src
FROM base FROM base
ENV GOFLAGS="-buildvcs=false" ENV GOFLAGS="-buildvcs=false"
RUN --mount=type=bind,target=. \ RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/root/.cache \
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \ --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
golangci-lint run golangci-lint run

View file

@ -1,22 +1,23 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
ARG GO_VERSION=1.18 ARG GO_VERSION=1.18
ARG ALPINE_VERSION=3.16
ARG MODOUTDATED_VERSION=v0.8.0 ARG MODOUTDATED_VERSION=v0.8.0
FROM golang:${GO_VERSION}-alpine AS base FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
RUN apk add --no-cache git rsync RUN apk add --no-cache git rsync
WORKDIR /src WORKDIR /src
FROM base AS vendored FROM base AS vendored
RUN --mount=target=/context \ RUN --mount=target=/context \
--mount=target=.,type=tmpfs \ --mount=target=.,type=tmpfs \
--mount=target=/go/pkg/mod,type=cache <<EOT --mount=target=/go/pkg/mod,type=cache <<EOT
set -e set -e
rsync -a /context/. . rsync -a /context/. .
go mod tidy go mod tidy
go mod vendor go mod vendor
mkdir /out mkdir /out
cp -r go.mod go.sum vendor /out cp -r go.mod go.sum vendor /out
EOT EOT
FROM scratch AS update FROM scratch AS update
@ -24,23 +25,23 @@ COPY --from=vendored /out /out
FROM vendored AS validate FROM vendored AS validate
RUN --mount=target=/context \ RUN --mount=target=/context \
--mount=target=.,type=tmpfs <<EOT --mount=target=.,type=tmpfs <<EOT
set -e set -e
rsync -a /context/. . rsync -a /context/. .
git add -A git add -A
rm -rf vendor rm -rf vendor
cp -rf /out/* . cp -rf /out/* .
if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"' echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"'
git status --porcelain -- go.mod go.sum vendor git status --porcelain -- go.mod go.sum vendor
exit 1 exit 1
fi fi
EOT EOT
FROM psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated FROM psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated
FROM base AS outdated FROM base AS outdated
ARG _RANDOM ARG _RANDOM
RUN --mount=target=.,ro \ RUN --mount=target=.,ro \
--mount=target=/go/pkg/mod,type=cache \ --mount=target=/go/pkg/mod,type=cache \
--mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \ --mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \
go list -mod=readonly -u -m -json all | go-mod-outdated -update -direct go list -mod=readonly -u -m -json all | go-mod-outdated -update -direct

View file

@ -1,12 +0,0 @@
#!/usr/bin/env bash
set -eu -o pipefail
if ! command -v git-validation; then
>&2 echo "ERROR: git-validation not found. Install with:"
>&2 echo " go install github.com/vbatts/git-validation@latest"
exit 1
fi
verbosity="${DCO_VERBOSITY--v}"
GIT_CHECK_EXCLUDE="./vendor:./script/validate/template" git-validation "$verbosity" -range "$COMMIT_RANGE" -run DCO,short-subject,dangling-whitespace