From 5e25d92d7739755b432e0e57fd41f80585d26794 Mon Sep 17 00:00:00 2001 From: guoyonghao <1711322114@qq.com> Date: Wed, 29 Jul 2026 11:53:27 +0800 Subject: [PATCH 1/2] ci: add GitHub Actions test workflow --- .github/workflows/ci.yml | 128 ++++++++++++++++++++++++++++++++++++++ Makefile | 4 +- scripts/ci/integration.sh | 53 ++++++++++++++++ 3 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100755 scripts/ci/integration.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ae8d709 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,128 @@ +name: CI + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + workflow_dispatch: + +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 diff --git a/Makefile b/Makefile index 9009f5f..d340aa4 100644 --- a/Makefile +++ b/Makefile @@ -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..." diff --git a/scripts/ci/integration.sh b/scripts/ci/integration.sh new file mode 100755 index 0000000..b40189f --- /dev/null +++ b/scripts/ci/integration.sh @@ -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." From 68325aca4296e70c189f886a52c8de46d63a70f6 Mon Sep 17 00:00:00 2001 From: guoyonghao <1711322114@qq.com> Date: Wed, 29 Jul 2026 13:45:32 +0800 Subject: [PATCH 2/2] ci: run checks only after main updates --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae8d709..dcc47ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,6 @@ on: push: branches: - main - - master - pull_request: - branches: - - main - - master - workflow_dispatch: permissions: contents: read