-
Notifications
You must be signed in to change notification settings - Fork 3
118 lines (95 loc) · 3.06 KB
/
api-unit-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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This workflow will build the golang project, create a Mongo database and test it
name: 🕵️♂️ API Unit Tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
paths:
- API/**
jobs:
api-unit-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./API
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Install gotestsum
run: go install gotest.tools/gotestsum@latest
- name: Install gocov
run: go install github.com/axw/gocov/gocov@latest
- name: Install gocov-xml
run: go install github.com/AlekSi/gocov-xml@latest
- name: Create MongoDB Container
run: cd ../deploy/docker && make test_api
- name: Build
run: make
- name: Test
run: gotestsum --junitfile tests-api.xml -- -coverpkg=./... -coverprofile=coverage_api.out -p 1 ./...
- name: Log Test Coverage
run: go tool cover -func coverage_api.out | grep total
- name: Generate coverage XML report
run: gocov convert coverage_api.out | gocov-xml > coverage_api.xml
- name: Test Report
uses: dorny/test-reporter@v1
if: github.actor != 'dependabot[bot]'
with:
name: API Tests Report # Name of the check run which will be created
path: ./API/tests-api.xml # Path to test results
reporter: java-junit # Format of test results
- uses: actions/upload-artifact@v4
with:
name: coverage
path: ./API/coverage_api.out
- uses: actions/upload-artifact@v4
with:
name: coverage_api_xml
path: ./API/coverage_api.xml
generate-coverage-badge:
needs: api-unit-test
runs-on: ubuntu-latest
permissions:
contents: write
defaults:
run:
working-directory: ./
if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Generate Badge
uses: ./.github/actions/coverage/generate-badge
with:
COVERAGE_REPORT_ARTIFACT: coverage_api_xml
COVERAGE_REPORT_NAME: coverage_api.xml
LABEL: "API coverage"
OUTPUT_FILE: api_coverage_badge.svg
RED_LIMIT: "50"
GREEN_LIMIT: "65"
BADGE_ARTIFACT_NAME: api_coverage_badge
upload-coverage-badge:
needs: generate-coverage-badge
runs-on: ubuntu-latest
permissions:
contents: write
defaults:
run:
working-directory: ./
if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Upload Badge
uses: ./.github/actions/coverage/upload-badge
with:
BADGE_ARTIFACT_NAME: api_coverage_badge
BADGE_FILE_NAME: api_coverage_badge.svg
BRANCH_NAME: coverage_badges
github_token: ${{ secrets.GITHUB_TOKEN }}