Skip to content

Commit

Permalink
Merge pull request #177 from crazy-max/test-coverage
Browse files Browse the repository at this point in the history
test with coverage and send to codecov
  • Loading branch information
tonistiigi authored Feb 8, 2024
2 parents d68510a + 5bc2346 commit 6f63746
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
42 changes: 34 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DESTDIR: ./bin

on:
schedule:
- cron: '0 8 */6 * *' # every 6 days
push:
branches:
- master
- gh_test_ci
pull_request:
branches:
- master

jobs:
validate:
Expand Down Expand Up @@ -61,11 +61,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go_version:
go:
- "1.19"
- "1.20"
mode:
- "root"
- "noroot"
env:
GO_VERSION: ${{ matrix.go_version }}
GO_VERSION: ${{ matrix.go }}
steps:
-
name: Checkout
Expand All @@ -77,7 +80,13 @@ jobs:
name: Test
uses: docker/bake-action@v3
with:
targets: test
targets: test-${{ matrix.mode }}
-
name: Upload coverage
uses: codecov/codecov-action@v4
with:
directory: ${{ env.DESTDIR }}/coverage
flags: unit,${{ matrix.mode }},go-${{ matrix.go }}

test-os:
runs-on: ${{ matrix.os }}
Expand All @@ -102,7 +111,16 @@ jobs:
-
name: Test
run: |
go test ./...
go test -coverprofile=coverage.txt -covermode=atomic ./...
go tool cover -func=coverage.txt
-
name: Upload coverage
if: always()
uses: codecov/codecov-action@v4
with:
file: ./coverage.txt
env_vars: RUNNER_OS
flags: unit,go-${{ matrix.go }}

test-freebsd-amd64:
runs-on: macos-13
Expand Down Expand Up @@ -147,4 +165,12 @@ jobs:
timeout_minutes: 20
max_attempts: 5
command: |
vagrant ssh -- "cd /vagrant; go test -buildvcs=false ./..."
vagrant ssh -- "cd /vagrant; go test -buildvcs=false -coverprofile=coverage.txt -covermode=atomic ./..."
vagrant ssh -c "sudo cat /vagrant/coverage.txt" > coverage.txt
-
name: Upload coverage
if: always()
uses: codecov/codecov-action@v4
with:
file: ./coverage.txt
flags: unit,freebsd
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# if you want to ignore files created by your editor/tools, consider using a
# global .gitignore or .git/info/exclude see https://help.github.com/articles/ignoring-files
.*
!.github
!.gitignore
!.travis.yml
*.prof
bin/
# support running go modules in vendor mode for local development
vendor/
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ FROM base AS test
ARG TESTFLAGS
RUN --mount=target=. --mount=target=/go/pkg/mod,type=cache \
--mount=target=/root/.cache,type=cache \
CGO_ENABLED=0 xx-go test -test.v ${TESTFLAGS} ./...
CGO_ENABLED=0 xx-go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ${TESTFLAGS} ./...

FROM base AS test-noroot
RUN mkdir /go/pkg && chmod 0777 /go/pkg
USER 1000:1000
RUN --mount=target=. \
--mount=target=/tmp/.cache,type=cache \
CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -test.v ./...
CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./...

FROM scratch AS test-coverage
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 build
10 changes: 8 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ variable "GO_VERSION" {
default = "1.20"
}

variable "DESTDIR" {
default = "./bin"
}

group "default" {
targets = ["build"]
}
Expand All @@ -18,12 +22,14 @@ group "test" {

target "test-root" {
inherits = ["build"]
target = "test"
target = "test-coverage"
output = ["${DESTDIR}/coverage"]
}

target "test-noroot" {
inherits = ["build"]
target = "test-noroot"
target = "test-noroot-coverage"
output = ["${DESTDIR}/coverage"]
}

target "lint" {
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square&logo=go&logoColor=white)](https://pkg.go.dev/github.com/tonistiigi/fsutil)
[![CI Status](https://img.shields.io/github/actions/workflow/status/tonistiigi/fsutil/ci.yml?label=ci&logo=github&style=flat-square)](https://github.com/tonistiigi/fsutil/actions?query=workflow%3Aci)
[![Go Report Card](https://goreportcard.com/badge/github.com/tonistiigi/fsutil?style=flat-square)](https://goreportcard.com/report/github.com/tonistiigi/fsutil)
[![Codecov](https://img.shields.io/codecov/c/github/tonistiigi/fsutil?logo=codecov&style=flat-square)](https://codecov.io/gh/tonistiigi/fsutil)

Incremental file directory sync tools in golang.

```
Expand Down

0 comments on commit 6f63746

Please sign in to comment.