diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f4a0af1..e3e1a3bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,11 @@ permissions: pull-requests: write jobs: test: - name: test - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + steps: - name: checkout uses: actions/checkout@v4 @@ -18,13 +21,38 @@ jobs: - name: test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed for GitHub badge storer integration test - run: make test + run: go test -timeout=60s -race -count=1 -failfast -shuffle=on ./... -coverprofile=./cover.${{ matrix.os }}.profile -covermode=atomic -coverpkg=./... + + - name: upload cover profile artifact + uses: actions/upload-artifact@v3 + with: + name: cover.${{ matrix.os }} + path: cover.${{ matrix.os }}.profile + + check-coverage: + runs-on: ubuntu-latest + needs: test + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: download cover.ubuntu-latest + uses: actions/download-artifact@v3 + with: + name: cover.ubuntu-latest + - name: download cover.macos-latest + uses: actions/download-artifact@v3 + with: + name: cover.macos-latest + - name: check test coverage id: coverage uses: vladopajic/go-test-coverage@v2 with: config: ./.github/.testcoverage.yml + profile: cover.ubuntu-latest.profile,cover.macos-latest.profile git-branch: badges git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }} diff --git a/pkg/testcoverage/badgestorer/github_test.go b/pkg/testcoverage/badgestorer/github_test.go index d1877592..012ee386 100644 --- a/pkg/testcoverage/badgestorer/github_test.go +++ b/pkg/testcoverage/badgestorer/github_test.go @@ -7,6 +7,7 @@ import ( "github.com/google/go-github/v56/github" "github.com/stretchr/testify/assert" + "golang.org/x/exp/rand" . "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/badgestorer" ) @@ -51,7 +52,9 @@ func Test_Github(t *testing.T) { Owner: "vladopajic", Repository: "go-test-coverage", Branch: "badges-integration-test", - FileName: "badge.svg", + // random badge name must be used because two tests running from different platforms + // in CI can cause race condition if badge has the same name + FileName: "badge_" + randString() + ".svg", } s := NewGithub(cfg) @@ -105,3 +108,15 @@ func deleteFile(t *testing.T, cfg Git) { ) assert.NoError(t, err) } + +func randString() string { + letterRunes := []rune("abcdefghijklmnopqrstuvwxyz") + l := len(letterRunes) + + b := make([]rune, rand.Intn(10)) + for i := range b { + b[i] = letterRunes[rand.Intn(l)] + } + + return string(b) +}