go-loose/.forgejo/workflows/ci-cd.yaml

114 lines
3.8 KiB
YAML
Raw Normal View History

name: Build, test, publish, deploy
2026-10-07 21:56:56 +02:00
on:
push:
pull_request:
workflow_dispatch:
2026-10-07 21:56:56 +02:00
env:
GO_VERSION: "1.27.1"
REGISTRY: nexus.urpi.be
2026-10-07 21:56:56 +02:00
IMAGE_NAME: docker-hosted/go-loose
jobs:
build-test:
2026-10-07 21:56:56 +02:00
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
2026-10-07 21:56:56 +02:00
with:
go-version-file: go.mod
2026-10-07 21:56:56 +02:00
cache: true
- name: Build and test Go service
2026-10-07 21:56:56 +02:00
run: |
go mod download
go vet ./...
go test -race ./... -count=1
go build ./...
- uses: azure/setup-helm@v4
with:
version: v3.18.6
- name: Validate production chart
run: |
helm dependency build deploy/helm/go-loose
helm lint deploy/helm/go-loose -f deploy/helm/go-loose/values-prd.yaml
2026-10-07 21:56:56 +02:00
integration-test:
runs-on: ubuntu-latest
needs: build-test
2026-10-07 21:56:56 +02:00
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_DB: goloose
POSTGRES_USER: goloose
POSTGRES_PASSWORD: goloose
ports: [5432:5432]
2026-10-07 21:56:56 +02:00
options: >-
--health-cmd="pg_isready -U goloose -d goloose"
--health-interval=5s
--health-timeout=3s
--health-retries=10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
2026-10-07 21:56:56 +02:00
with:
go-version-file: go.mod
2026-10-07 21:56:56 +02:00
cache: true
- name: Run database-backed tests
2026-10-07 21:56:56 +02:00
env:
PGPASSWORD: goloose
2026-10-07 21:56:56 +02:00
GO_LOOSE_TEST_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_test?sslmode=disable
GO_LOOSE_TEST_SERVER_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_server_test?sslmode=disable
GO_LOOSE_BEHAVIOUR_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_behaviour_test?sslmode=disable
run: |
sleep 5
createdb -h localhost -U goloose goloose_test || true
createdb -h localhost -U goloose goloose_server_test || true
createdb -h localhost -U goloose goloose_behaviour_test || true
2026-10-07 21:56:56 +02:00
go test -race ./internal/store/ ./internal/server/ -count=1
GO_LOOSE_BEHAVIOUR=1 go test ./internal/behaviour/ -count=1 -v
publish:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
needs: [build-test, integration-test]
2026-10-07 21:56:56 +02:00
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
2026-10-07 21:56:56 +02:00
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.NEXUS_USERNAME }}
password: ${{ secrets.NEXUS_PASSWORD }}
- uses: docker/build-push-action@v6
2026-10-07 21:56:56 +02:00
with:
context: .
file: Dockerfile
2026-10-07 21:56:56 +02:00
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
2026-10-07 21:56:56 +02:00
deploy-prd:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
needs: publish
2026-10-07 21:56:56 +02:00
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/setup-helm@v4
2026-10-07 21:56:56 +02:00
with:
version: v3.18.6
- uses: azure/setup-kubectl@v4
2026-10-07 21:56:56 +02:00
with:
version: v1.32.2
- name: Bootstrap resources and deploy go-loose
env:
KUBECONFIG_PRD: ${{ secrets.KUBECONFIG_PRD }}
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
2026-10-07 21:56:56 +02:00
run: |
set -Eeuo pipefail
bash .forgejo/scripts/deploy-prd.sh deploy/helm/go-loose go-loose go-loose "${{ github.sha }}" \
--set-string ingress.className=nginx