Skip to content

Commit 04b014e

Browse files
committed
ci(github): add unit test workflow for backend
1 parent cbeb0d3 commit 04b014e

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/unit-tests.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# LinaPro backend unit test workflow.
2+
# Runs on every push and pull request to main.
3+
name: Unit Tests
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
- develop
10+
- feat/**
11+
- fix/**
12+
13+
pull_request:
14+
branches:
15+
- main
16+
- develop
17+
- feat/**
18+
- fix/**
19+
20+
workflow_dispatch:
21+
inputs:
22+
debug:
23+
type: boolean
24+
description: 'Enable tmate Debug'
25+
required: false
26+
default: false
27+
28+
# Cancel in-progress runs for the same branch/PR to save CI minutes.
29+
concurrency:
30+
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
31+
cancel-in-progress: true
32+
33+
env:
34+
TZ: "Asia/Shanghai"
35+
36+
jobs:
37+
unit-test:
38+
runs-on: ubuntu-latest
39+
40+
services:
41+
mysql:
42+
image: mysql:8.0
43+
env:
44+
MYSQL_ROOT_PASSWORD: 12345678
45+
MYSQL_DATABASE: linapro
46+
ports:
47+
- 3306:3306
48+
options: >-
49+
--health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -p12345678"
50+
--health-interval 10s
51+
--health-timeout 5s
52+
--health-retries 10
53+
54+
steps:
55+
- name: Setup Timezone
56+
uses: szenius/set-timezone@v2.0
57+
with:
58+
timezoneLinux: "Asia/Shanghai"
59+
60+
- name: Checkout Repository
61+
uses: actions/checkout@v5
62+
63+
- name: Setup tmate Session
64+
uses: mxschmitt/action-tmate@v3
65+
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug }}
66+
with:
67+
detached: true
68+
limit-access-to-actor: false
69+
70+
- name: Setup Go
71+
uses: actions/setup-go@v5
72+
with:
73+
go-version: "1.25"
74+
cache-dependency-path: '**/go.sum'
75+
76+
- name: Initialize Database Schema
77+
run: make init confirm=init
78+
79+
- name: Run Unit Tests
80+
run: go test -v ./...

0 commit comments

Comments
 (0)