Skip to content

Commit

Permalink
ci: add bench
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Nov 3, 2024
1 parent daab4c1 commit c10ea96
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ jobs:
flags: unit,${{ matrix.mode }},go-${{ matrix.go }}
token: ${{ secrets.CODECOV_TOKEN }}

bench:
runs-on: ubuntu-latest
strategy:
matrix:
go:
- "1.23"
- "1.22"
- "1.21"
mode:
- "root"
- "noroot"
env:
GO_VERSION: ${{ matrix.go }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Test
uses: docker/bake-action@v5
with:
targets: bench-${{ matrix.mode }}

test-os:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ COPY --from=test /tmp/coverage.txt /coverage-root.txt
FROM scratch AS test-noroot-coverage
COPY --from=test-noroot /tmp/coverage.txt /coverage-noroot.txt

FROM base AS bench
ARG BENCH_FILE_SIZE
RUN --mount=target=. \
--mount=target=/go/pkg/mod,type=cache \
--mount=target=/root/.cache,type=cache \
CGO_ENABLED=0 xx-go test -benchmem -bench=. -run=^$ ./... && \
cd bench && CGO_ENABLED=0 xx-go test -benchmem -bench=. -run=^$ ./...

FROM base AS bench-noroot
RUN mkdir /go/pkg && chmod 0777 /go/pkg
USER 1000:1000
ARG BENCH_FILE_SIZE
RUN --mount=target=. \
--mount=target=/go/pkg/mod,type=cache \
--mount=target=/tmp/.cache,type=cache \
CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -bench=. -benchmem -run=^$ ./... && \
cd bench && CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -bench=. -benchmem -run=^$ ./...

FROM build
26 changes: 26 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ variable "DESTDIR" {
default = "./bin"
}

variable "BENCH_FILE_SIZE" {
default = null
}

group "default" {
targets = ["build"]
}
Expand All @@ -32,6 +36,28 @@ target "test-noroot" {
output = ["${DESTDIR}/coverage"]
}

group "bench" {
targets = ["test-root", "test-noroot"]
}

target "bench-root" {
inherits = ["build"]
target = "bench"
output = ["type=cacheonly"]
args = {
BENCH_FILE_SIZE = BENCH_FILE_SIZE
}
}

target "bench-noroot" {
inherits = ["build"]
target = "bench-noroot"
output = ["type=cacheonly"]
args = {
BENCH_FILE_SIZE = BENCH_FILE_SIZE
}
}

target "lint" {
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
output = ["type=cacheonly"]
Expand Down

0 comments on commit c10ea96

Please sign in to comment.