114 lines
2.8 KiB
YAML
114 lines
2.8 KiB
YAML
name: GoLoom CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
env:
|
|
GO_VERSION: '1.26'
|
|
GOPROXY: 'https://goproxy.cn,direct'
|
|
GOLANGCI_LINT_VERSION: 'v1.57.2'
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: backend
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: false
|
|
|
|
- name: Install golangci-lint
|
|
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin ${{ env.GOLANGCI_LINT_VERSION }}
|
|
|
|
- name: Run golangci-lint
|
|
run: golangci-lint run --timeout=5m --issues-exit-code=0
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: backend
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: false
|
|
|
|
- name: Run tests
|
|
run: |
|
|
test_files=$(find . -name "*_test.go" -type f)
|
|
if [ -z "$test_files" ]; then
|
|
echo "No test files found, skipping tests"
|
|
exit 0
|
|
fi
|
|
go test -v -race -coverprofile=coverage.out ./...
|
|
|
|
- name: Upload coverage
|
|
if: success() && hashFiles('coverage.out') != ''
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: coverage-report
|
|
path: backend/coverage.out
|
|
|
|
build:
|
|
name: Build
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test]
|
|
defaults:
|
|
run:
|
|
working-directory: backend
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: false
|
|
|
|
- name: Build binary
|
|
run: |
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
|
go build -ldflags="-s -w" -o goloom-server ./cmd/server
|
|
|
|
- name: Upload binary
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: goloom-server
|
|
path: backend/goloom-server
|
|
|
|
# TODO: 添加 Dockerfile 后启用
|
|
# docker:
|
|
# name: Docker Build
|
|
# runs-on: ubuntu-latest
|
|
# needs: [build]
|
|
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
# steps:
|
|
# - name: Checkout code
|
|
# uses: actions/checkout@v4
|
|
# - name: Download binary
|
|
# uses: actions/download-artifact@v3
|
|
# with:
|
|
# name: goloom-server
|
|
# - name: Build Docker image
|
|
# run: |
|
|
# chmod +x goloom-server
|
|
# docker build -t goloom:latest -t goloom:${{ github.sha }} .
|