-
Notifications
You must be signed in to change notification settings - Fork 9
46 lines (44 loc) · 1.56 KB
/
go-tests.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
name: GO Tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.19
- name: Checkout
uses: actions/checkout@v4
- name: Download Dependencies
run: go mod download
- name: Install ginkgo
run: go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo@latest
- name: Run Unit Tests
run: |
ginkgo -r --randomize-all --randomize-suites --fail-on-pending --cover --trace --v --coverprofile=coverage.out ./...
- name: Upload Coverage Report to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.out
flag: unittests
- name: Generate Coverage Comment
id: generate-comment
run: |
COVERAGE_PERCENT=$(go tool cover -func=coverage.out | grep total | awk '{print $NF}')
COMMENT_MESSAGE="Code coverage: $COVERAGE_PERCENT"
echo "::set-output name=comment::$COMMENT_MESSAGE"
- name: Comment on Pull Request
run: |
COMMENT_BODY="${{ steps.generate-comment.outputs.comment }}"
curl \
-X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"body\":\"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"