Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 || '' }}

Expand Down
17 changes: 16 additions & 1 deletion pkg/testcoverage/badgestorer/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
Loading