Files
GoLoom/.gitea/workflows/go-loom.yaml

121 lines
2.8 KiB
YAML

name: GoLoom CI
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
GO_VERSION: '1.26'
GOLANGCI_LINT_VERSION: 'v1.57.2'
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Download dependencies
run: go mod download
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: --timeout=5m --issues-exit-code=0
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Download dependencies
run: go mod download
- 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: coverage.out
build:
name: Build
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Download dependencies
run: go mod download
- 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: goloom-server
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: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: |
goloom:latest
goloom:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max