Skip to content

Commit f48c192

Browse files
authored
ci: add multiplatform tests (#117)
1 parent 2c3e299 commit f48c192

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ permissions:
55
pull-requests: write
66
jobs:
77
test:
8-
name: test
9-
runs-on: ubuntu-latest
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest, macos-latest]
12+
1013
steps:
1114
- name: checkout
1215
uses: actions/checkout@v4
@@ -18,13 +21,38 @@ jobs:
1821
- name: test
1922
env:
2023
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed for GitHub badge storer integration test
21-
run: make test
24+
run: go test -timeout=60s -race -count=1 -failfast -shuffle=on ./... -coverprofile=./cover.${{ matrix.os }}.profile -covermode=atomic -coverpkg=./...
25+
26+
- name: upload cover profile artifact
27+
uses: actions/upload-artifact@v3
28+
with:
29+
name: cover.${{ matrix.os }}
30+
path: cover.${{ matrix.os }}.profile
31+
32+
check-coverage:
33+
runs-on: ubuntu-latest
34+
needs: test
35+
36+
steps:
37+
- name: checkout
38+
uses: actions/checkout@v4
39+
40+
- name: download cover.ubuntu-latest
41+
uses: actions/download-artifact@v3
42+
with:
43+
name: cover.ubuntu-latest
2244

45+
- name: download cover.macos-latest
46+
uses: actions/download-artifact@v3
47+
with:
48+
name: cover.macos-latest
49+
2350
- name: check test coverage
2451
id: coverage
2552
uses: vladopajic/go-test-coverage@v2
2653
with:
2754
config: ./.github/.testcoverage.yml
55+
profile: cover.ubuntu-latest.profile,cover.macos-latest.profile
2856
git-branch: badges
2957
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
3058

pkg/testcoverage/badgestorer/github_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/google/go-github/v56/github"
99
"github.com/stretchr/testify/assert"
10+
"golang.org/x/exp/rand"
1011

1112
. "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/badgestorer"
1213
)
@@ -51,7 +52,9 @@ func Test_Github(t *testing.T) {
5152
Owner: "vladopajic",
5253
Repository: "go-test-coverage",
5354
Branch: "badges-integration-test",
54-
FileName: "badge.svg",
55+
// random badge name must be used because two tests running from different platforms
56+
// in CI can cause race condition if badge has the same name
57+
FileName: "badge_" + randString() + ".svg",
5558
}
5659
s := NewGithub(cfg)
5760

@@ -105,3 +108,15 @@ func deleteFile(t *testing.T, cfg Git) {
105108
)
106109
assert.NoError(t, err)
107110
}
111+
112+
func randString() string {
113+
letterRunes := []rune("abcdefghijklmnopqrstuvwxyz")
114+
l := len(letterRunes)
115+
116+
b := make([]rune, rand.Intn(10))
117+
for i := range b {
118+
b[i] = letterRunes[rand.Intn(l)]
119+
}
120+
121+
return string(b)
122+
}

0 commit comments

Comments
 (0)