name: CI on: pull_request: push: branches: - main permissions: contents: read concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true env: # Keep writable Go directories outside the runner template's built-in GOPATH. GOPATH: ${{ github.workspace }}/.cache/go GOMODCACHE: ${{ github.workspace }}/.cache/go/pkg/mod GOCACHE: /tmp/go-build-cache GOPRIVATE: github.com/qbox/* # Shared Qiniu S3 cache configuration. Credentials come from repository secrets. RUNNER_S3_BUCKET: las-github-runner-dal RUNNER_S3_ENDPOINT: s3.us-north-1.qiniucs.com RUNNER_S3_REGION: us-north-1 RUNNER_S3_AK: ${{ secrets.RUNNER_S3_AK }} RUNNER_S3_SK: ${{ secrets.RUNNER_S3_SK }} jobs: prepare: if: github.repository == '1024XEngineer/xinfra' name: Prepare CI context runs-on: github-runner-ubuntu-24-04 outputs: ci_go_mod_hash: ${{ steps.context.outputs.ci_go_mod_hash }} steps: - name: Checkout uses: actions/checkout@v6 - name: Calculate Go module cache key id: context shell: bash run: | set -euo pipefail ci_go_mod_hash="$(sha256sum server/go.mod server/go.sum | sha256sum | awk '{print $1}')" echo "ci_go_mod_hash=${ci_go_mod_hash}" >> "${GITHUB_OUTPUT}" echo "CI_GO_MOD_HASH=${ci_go_mod_hash}" go-mod-cache: if: github.repository == '1024XEngineer/xinfra' name: Prepare Go module cache needs: prepare runs-on: github-runner-ubuntu-24-04 env: CI_GO_MOD_HASH: ${{ needs.prepare.outputs.ci_go_mod_hash }} steps: - name: Checkout uses: actions/checkout@v6 - name: Prepare Go environment uses: ./.github/actions/ci-go-prep - name: Download Go modules working-directory: server shell: bash run: | set -euo pipefail go mod download - name: Save Go module cache to S3 if: success() continue-on-error: true shell: bash run: bash "${GITHUB_WORKSPACE}/.github/scripts/ci/save-go-cache.sh" backend-unit: if: github.repository == '1024XEngineer/xinfra' name: Backend unit tests needs: - prepare - go-mod-cache runs-on: github-runner-ubuntu-24-04 env: CI_GO_MOD_HASH: ${{ needs.prepare.outputs.ci_go_mod_hash }} defaults: run: working-directory: server steps: - name: Checkout uses: actions/checkout@v6 - name: Prepare Go environment uses: ./.github/actions/ci-go-prep - 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: if: github.repository == '1024XEngineer/xinfra' name: Frontend typecheck and build runs-on: github-runner-ubuntu-24-04 defaults: run: working-directory: frontend steps: - name: Checkout uses: actions/checkout@v6 - name: Install dependencies run: npm ci - name: Build frontend run: npm run build integration: if: github.repository == '1024XEngineer/xinfra' name: Backend integration smoke test needs: - prepare - go-mod-cache - backend-unit - frontend-validation runs-on: github-runner-ubuntu-24-04 env: CI_GO_MOD_HASH: ${{ needs.prepare.outputs.ci_go_mod_hash }} 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@v6 - name: Prepare Go environment uses: ./.github/actions/ci-go-prep - 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