name: Build, test, publish, deploy on: push: pull_request: workflow_dispatch: env: GO_VERSION: "1.27.1" REGISTRY: nexus.urpi.be IMAGE_NAME: docker-hosted/go-loose jobs: build-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version-file: go.mod cache: true - name: Build and test Go service 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 integration-test: runs-on: ubuntu-latest needs: build-test services: postgres: image: postgres:17-alpine env: POSTGRES_DB: goloose POSTGRES_USER: goloose POSTGRES_PASSWORD: goloose ports: [5432:5432] 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 with: go-version-file: go.mod cache: true - name: Run database-backed tests env: PGPASSWORD: goloose 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 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] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: docker/setup-buildx-action@v3 - uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.NEXUS_USERNAME }} password: ${{ secrets.NEXUS_PASSWORD }} - uses: docker/build-push-action@v6 with: context: . file: Dockerfile push: true tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest deploy-prd: if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') needs: publish runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: azure/setup-helm@v4 with: version: v3.18.6 - uses: azure/setup-kubectl@v4 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 }} run: | set -Eeuo pipefail bash .forgejo/scripts/deploy-prd.sh deploy/helm/go-loose go-loose go-loose "${{ github.sha }}"