Merge pull request #124 from Gmaker689/ci/github-actions
Ci/GitHub actions
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
backend-unit:
|
||||
name: Backend unit tests
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: server
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: server/go.mod
|
||||
cache: true
|
||||
cache-dependency-path: server/go.sum
|
||||
|
||||
- name: Download Go modules
|
||||
run: go mod download
|
||||
|
||||
- name: Go vet
|
||||
run: go vet ./...
|
||||
|
||||
- name: Run Go unit tests
|
||||
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...
|
||||
|
||||
- name: Upload Go coverage
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: backend-coverage
|
||||
path: server/coverage.out
|
||||
if-no-files-found: ignore
|
||||
|
||||
frontend-validation:
|
||||
name: Frontend typecheck and build
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: frontend
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: npm
|
||||
cache-dependency-path: frontend/package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build frontend
|
||||
run: npm run build
|
||||
|
||||
integration:
|
||||
name: Backend integration smoke test
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- backend-unit
|
||||
- frontend-validation
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0.46
|
||||
env:
|
||||
MYSQL_ROOT_PASSWORD: root123456
|
||||
MYSQL_DATABASE: authserver
|
||||
MYSQL_USER: auth
|
||||
MYSQL_PASSWORD: auth
|
||||
TZ: Asia/Shanghai
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: >-
|
||||
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot123456"
|
||||
--health-interval=10s
|
||||
--health-timeout=5s
|
||||
--health-retries=12
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: server/go.mod
|
||||
cache: true
|
||||
cache-dependency-path: server/go.sum
|
||||
|
||||
- name: Download Go modules
|
||||
working-directory: server
|
||||
run: go mod download
|
||||
|
||||
- name: Run integration smoke test
|
||||
working-directory: server
|
||||
env:
|
||||
APP_ENV: test
|
||||
HTTP_ADDR: 127.0.0.1:8080
|
||||
MYSQL_DSN: "auth:auth@tcp(127.0.0.1:3306)/authserver?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
AUTO_MIGRATE: true
|
||||
SSO_ENABLED: false
|
||||
JWT_SECRET: ci-only-secret
|
||||
DELIVERY_SCHEDULER_ENABLED: false
|
||||
WAYNE_API_BASE_URL: ""
|
||||
SINA_BASE_URL: ""
|
||||
run: ../scripts/ci/integration.sh
|
||||
@@ -39,8 +39,8 @@ run:
|
||||
test: test-frontend test-server
|
||||
|
||||
test-frontend:
|
||||
@echo "Running frontend tests..."
|
||||
cd frontend && npm run test
|
||||
@echo "Running frontend typecheck and build validation..."
|
||||
cd frontend && npm run build
|
||||
|
||||
test-server:
|
||||
@echo "Running server tests..."
|
||||
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
server_log="${RUNNER_TEMP:-${TMPDIR:-/tmp}}/xinfra-server.log"
|
||||
server_pid=""
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "${server_pid}" ]] && kill -0 "${server_pid}" 2>/dev/null; then
|
||||
kill "${server_pid}" 2>/dev/null || true
|
||||
wait "${server_pid}" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "Starting backend; log: ${server_log}"
|
||||
go run ./cmd/server >"${server_log}" 2>&1 &
|
||||
server_pid=$!
|
||||
|
||||
ready=false
|
||||
for attempt in $(seq 1 30); do
|
||||
if curl --fail --silent --show-error http://127.0.0.1:8080/readyz >/tmp/xinfra-readyz.json; then
|
||||
echo "Backend is ready after ${attempt} attempt(s)."
|
||||
ready=true
|
||||
break
|
||||
fi
|
||||
|
||||
if ! kill -0 "${server_pid}" 2>/dev/null; then
|
||||
echo "Backend exited before becoming ready."
|
||||
cat "${server_log}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
|
||||
done
|
||||
|
||||
if [[ "${ready}" != true ]]; then
|
||||
echo "Backend did not become ready within the timeout."
|
||||
cat "${server_log}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! curl --fail --silent --show-error http://127.0.0.1:8080/readyz | grep -q '"status":"ok"'; then
|
||||
echo "Backend readiness check did not return status=ok."
|
||||
cat /tmp/xinfra-readyz.json || true
|
||||
cat "${server_log}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
curl --fail --silent --show-error http://127.0.0.1:8080/healthz | grep -q '"status":"ok"'
|
||||
curl --fail --silent --show-error http://127.0.0.1:8080/api/v1/ping | grep -q '"code":0'
|
||||
|
||||
echo "Backend integration smoke test passed."
|
||||
Reference in New Issue
Block a user