From 30a894a78f0ca31f180ff782c240b57b4f0cf073 Mon Sep 17 00:00:00 2001 From: Cosmo Date: Thu, 26 Mar 2026 18:33:43 +0000 Subject: [PATCH] ci: add lint, coverage check and proper deploy workflow --- .gitea/workflows/ci.yml | 24 +++++++++++++++++------- .gitea/workflows/deploy-prod.yml | 25 ++++++++++++++++--------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 26cf36e..2014b42 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -2,10 +2,12 @@ name: CI on: push: - branches: [dev] + branches-ignore: [main] + pull_request: + branches: [main] jobs: - ci: + lint-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -17,11 +19,19 @@ jobs: - name: Tidy run: go mod tidy - - name: Vet - run: go vet ./... + - name: Lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest - name: Test - run: go test ./... -v + run: go test ./... -coverprofile=coverage.out -covermode=atomic - - name: Build - run: CGO_ENABLED=0 go build -o main ./cmd/api + - name: Coverage Check + run: | + COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%') + echo "Coverage: ${COVERAGE}%" + if (( $(echo "$COVERAGE < 85" | bc -l) )); then + echo "::error::Coverage ${COVERAGE}% is below 85%" + exit 1 + fi diff --git a/.gitea/workflows/deploy-prod.yml b/.gitea/workflows/deploy-prod.yml index 8c17f1d..3002337 100644 --- a/.gitea/workflows/deploy-prod.yml +++ b/.gitea/workflows/deploy-prod.yml @@ -1,4 +1,4 @@ -name: Deploy Production +name: Deploy on: push: @@ -8,11 +8,18 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-go@v5 - with: - go-version: '1.22' - - - name: Build - run: CGO_ENABLED=0 go build -o main ./cmd/api + - name: Deploy pulse-api + run: | + cd /opt/digital-home/homelab-api + docker compose pull + docker compose up -d --build + echo "Waiting for healthcheck..." + sleep 5 + STATUS=$(docker inspect --format='{{.State.Health.Status}}' homelab-api 2>/dev/null || echo "no-healthcheck") + echo "Container status: $STATUS" + if [ "$STATUS" = "unhealthy" ]; then + echo "::error::Container is unhealthy after deploy" + docker logs homelab-api --tail=20 + exit 1 + fi + echo "Deploy successful!"