ci: add lint, coverage check and proper deploy workflow
This commit is contained in:
@@ -2,10 +2,12 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [dev]
|
branches-ignore: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
lint-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -17,11 +19,19 @@ jobs:
|
|||||||
- name: Tidy
|
- name: Tidy
|
||||||
run: go mod tidy
|
run: go mod tidy
|
||||||
|
|
||||||
- name: Vet
|
- name: Lint
|
||||||
run: go vet ./...
|
uses: golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./... -v
|
run: go test ./... -coverprofile=coverage.out -covermode=atomic
|
||||||
|
|
||||||
- name: Build
|
- name: Coverage Check
|
||||||
run: CGO_ENABLED=0 go build -o main ./cmd/api
|
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
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Deploy Production
|
name: Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -8,11 +8,18 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Deploy pulse-api
|
||||||
|
run: |
|
||||||
- uses: actions/setup-go@v5
|
cd /opt/digital-home/homelab-api
|
||||||
with:
|
docker compose pull
|
||||||
go-version: '1.22'
|
docker compose up -d --build
|
||||||
|
echo "Waiting for healthcheck..."
|
||||||
- name: Build
|
sleep 5
|
||||||
run: CGO_ENABLED=0 go build -o main ./cmd/api
|
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!"
|
||||||
|
|||||||
Reference in New Issue
Block a user