Skip to content

chore: explicitly specify Atlas configuration file path for all schem… #15

chore: explicitly specify Atlas configuration file path for all schem…

chore: explicitly specify Atlas configuration file path for all schem… #15

Workflow file for this run

name: Tests
on:
push:
branches: [ main, develop, master ]
paths:
- 'backend/**'
- '.github/workflows/test.yml'
pull_request:
branches: [ main, develop, master ]
paths:
- 'backend/**'
- '.github/workflows/test.yml'
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21', '1.22']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: backend/go.sum
- name: Install dependencies
working-directory: backend
run: go mod download
- name: Build
working-directory: backend
run: |
echo "Building all packages..."
go build -v ./...
echo "✅ Build successful"
- name: Build main binary
working-directory: backend
run: |
echo "Building main binary..."
go build -o bin/server ./cmd/server
echo "✅ Binary created: bin/server"
ls -lh bin/
test:
name: Run Tests
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21', '1.22']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: backend/go.sum
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('backend/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Install dependencies
working-directory: backend
run: go mod download
- name: Run tests
working-directory: backend
run: |
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Show coverage
working-directory: backend
run: |
go tool cover -func=coverage.out | grep total
lint:
name: Code Quality
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.22'
cache-dependency-path: backend/go.sum
- name: Run go vet
working-directory: backend
run: |
echo "Running go vet..."
go vet ./...
echo "✅ go vet passed"
- name: Check code formatting
working-directory: backend
run: |
echo "Checking code format..."
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "❌ Code is not formatted. Please run 'gofmt -s -w .'"
gofmt -s -l .
exit 1
fi
echo "✅ Code is properly formatted"
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Run staticcheck
working-directory: backend
run: |
echo "Running staticcheck..."
staticcheck ./...
echo "✅ staticcheck passed"
test-domains:
name: Test Domain - ${{ matrix.domain }}
runs-on: ubuntu-latest
strategy:
matrix:
domain: ['task']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache-dependency-path: backend/go.sum
- name: Install dependencies
working-directory: backend
run: go mod download
- name: Run domain tests
working-directory: backend
run: |
echo "Testing domain: ${{ matrix.domain }}"
go test -v -race -coverprofile=coverage-${{ matrix.domain }}.out \
./domains/${{ matrix.domain }}/...
- name: Check domain coverage
working-directory: backend
run: |
coverage=$(go tool cover -func=coverage-${{ matrix.domain }}.out | grep total | awk '{print $3}' | sed 's/%//')
echo "Domain '${{ matrix.domain }}' coverage: ${coverage}%"
# 只显示警告,不让构建失败
if (( $(echo "$coverage < 60" | bc -l) )); then
echo "⚠️ Warning: Domain coverage ${coverage}% is below 60%"
else
echo "✅ Domain coverage ${coverage}% is good"
fi
summary:
name: All Checks
runs-on: ubuntu-latest
needs: [build, test, lint, test-domains]
if: always()
steps:
- name: Check results
run: |
echo "📊 Check Results:"
echo " - Build: ${{ needs.build.result }}"
echo " - Tests: ${{ needs.test.result }}"
echo " - Lint: ${{ needs.lint.result }}"
echo " - Domain Tests: ${{ needs.test-domains.result }}"
echo ""
if [[ "${{ needs.build.result }}" == "success" ]] && \
[[ "${{ needs.test.result }}" == "success" ]] && \
[[ "${{ needs.lint.result }}" == "success" ]] && \
[[ "${{ needs.test-domains.result }}" == "success" ]]; then
echo "✅ All checks passed!"
exit 0
else
echo "❌ Some checks failed!"
exit 1
fi