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 }} cache: true - name: Cache golangci-lint uses: actions/cache@v4 with: path: /usr/local/bin/golangci-lint key: golangci-lint-${{ env.GOLANGCI_LINT_VERSION }} - name: Install golangci-lint run: | if [ ! -f /usr/local/bin/golangci-lint ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin ${{ env.GOLANGCI_LINT_VERSION }} fi - name: Run golangci-lint run: golangci-lint run --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 }} cache: true - 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 }} cache: true - 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