-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (67 loc) · 2.31 KB
/
go-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Go Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch: # Allows manual trigger
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Secrets
run: |
if [ -z "${{ secrets.DYNAMIC_GIST_ACTION }}" ]; then
echo "Error: GIST_SECRET is not set"
exit 1
fi
if [ -z "${{ secrets.DYNA_GIST_ID }}" ]; then
echo "Error: DYNA_GIST_ID is not set"
exit 1
fi
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run Tests and Count
run: |
cd go-app
# Run tests and store the pass/fail status
go test -v ./... 2>&1 | tee test_output.txt
TEST_COUNT=$(grep -c "^=== RUN" test_output.txt)
echo "TEST_COUNT=$TEST_COUNT" >> $GITHUB_ENV
- name: Generate Coverage
run: |
cd go-app
go test -race -coverprofile=coverage.out -covermode=atomic ./...
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%')
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
go-app/test_output.txt
go-app/coverage.out
- name: Create Test Count Badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.DYNAMIC_GIST_ACTION }}
gistID: ${{ secrets.DYNA_GIST_ID }}
filename: minion-testresults.json
label: Tests
message: ${{ env.TEST_COUNT }} ${{ job.status == 'success' && 'passed' || 'failed' }}
color: ${{ job.status == 'success' && 'green' || 'red' }}
if: always()
- name: Create Coverage Badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.DYNAMIC_GIST_ACTION }}
gistID: ${{ secrets.DYNA_GIST_ID }}
filename: minion-coverage.json
label: Coverage
message: ${{ env.COVERAGE }}%
color: ${{ env.COVERAGE >= 80 && 'green' || env.COVERAGE >= 60 && 'yellow' || 'red' }}
if: always()