-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (127 loc) · 4.81 KB
/
lint-test-build-golang.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Lint🌸, Test🧪 and Build🏗️ golang
on:
pull_request:
branches: ["develop"]
paths: [
"occupi-backend/cmd/**",
"occupi-backend/configs/**",
"occupi-backend/pkg/**",
"occupi-backend/.golangci.yml",
"occupi-backend/tests/**",
".github/workflows/lint-test-build-golang.yml"
]
workflow_dispatch:
defaults:
run:
working-directory: occupi-backend
jobs:
lint:
name: 🌸 Lint
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout code
uses: actions/checkout@v4
- name: 🏗 Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21' # Specify the Go version you are using
- name: 📦 Install golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: 🌸 Run golangci-lint
run: |
golangci-lint run
test:
name: 🧪 Test
runs-on: ubuntu-latest
services:
mongo:
image: mongo:latest
ports:
- 27017:27017
options: >-
--health-cmd "mongosh --eval 'db.adminCommand({ping: 1})'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: ⬇️ Checkout code
uses: actions/checkout@v4
- name: 📦 Install mongosh
run: |
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
- name: ⌛ Wait for MongoDB to be ready
run: |
for i in {1..30}; do
if mongosh --eval 'db.adminCommand({ping: 1})' ${{ secrets.MONGO_DB_TEST_URL }}; then
echo "MongoDB is up"
break
fi
echo "Waiting for MongoDB to be ready..."
sleep 2
done
- name: 🏗 Create MongoDB User
env:
MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGO_DB_TEST_USERNAME }}
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_DB_TEST_PASSWORD }}
MONGO_INITDB_DATABASE: ${{ secrets.MONGO_DB_TEST_DB }}
run: |
mongosh ${{ secrets.MONGO_DB_TEST_URL }}/admin --eval "
db.createUser({
user: '${MONGO_INITDB_ROOT_USERNAME}',
pwd: '${MONGO_INITDB_ROOT_PASSWORD}',
roles: [
{ role: 'readWrite', db: '${MONGO_INITDB_DATABASE}' }
]
});
"
- name: 🏗 Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21' # Specify the Go version you are using
- name: 🔓 Decrypt default variables
run: |
echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --quiet --batch --yes --decrypt --passphrase-fd 0 configs/config.yaml.gpg > configs/config.yaml
- name: 🔓 Decrypt test variables
run: |
echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --quiet --batch --yes --decrypt --passphrase-fd 0 configs/test.yaml.gpg > configs/test.yaml
- name: 📦 Install gotestsum
run: |
go install gotest.tools/gotestsum@latest
- name: 📂 Make tmptest-result dir
run: |
mkdir -p tmp/test-results
- name: 🧪 Run tests
run: |
gotestsum --format testname --junitfile tmp/test-results/gotestsum-report.xml -- -v -coverpkg=github.com/COS301-SE-2024/occupi/occupi-backend/pkg/analytics,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/authenticator,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/cache,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/database,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/middleware,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils ./tests/... -coverprofile=coverage.out
- name: 📋 Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
- name: 📋 Upload test results to BuildPulse for flaky test detection 🚩
uses: buildpulse/buildpulse-action@main
with:
account: ${{ secrets.BUILDPULSE_ACCOUNT_ID }}
repository: ${{ secrets.BUILDPULSE_REPOSITORY_ID }}
path: |
tmp/test-results/gotestsum-report.xml
key: ${{ secrets.BUILDPULSE_ACCESS_KEY_ID }}
secret: ${{ secrets.BUILDPULSE_SECRET_ACCESS_KEY }}
build:
name: 🏗️ Build
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout code
uses: actions/checkout@v4
- name: 🏗 Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21' # Specify the Go version you are using
- name: 🚀 Build the code
run: |
go build -v cmd/occupi-backend/main.go