go-loose/.forgejo/workflows/ci-cd.yaml
Daniel Noulet abb207d608
Some checks failed
CI/CD / Build and Test (push) Has been cancelled
CI/CD / Integration Tests (push) Has been cancelled
CI/CD / Build and Push Docker Image (push) Has been cancelled
CI/CD / Deploy to PRD (push) Has been cancelled
chore: testing build
2026-10-07 21:56:56 +02:00

210 lines
No EOL
5.8 KiB
YAML

name: CI/CD
on:
push:
branches: [main, develop]
tags: ['v*']
pull_request:
branches: [main, develop]
env:
REGISTRY: nexus-registry.urpi.be
IMAGE_NAME: docker-hosted/go-loose
GO_VERSION: '1.27.1'
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Download dependencies
run: go mod download
- name: Build
run: go build ./...
- name: Run unit tests
run: go test -race ./... -count=1
- name: Run vet
run: go vet ./...
- name: Check formatting
run: |
if [ "$(gofmt -l . | grep -v vendor | grep -v dist | wc -l)" -gt 0 ]; then
echo "Code is not formatted:"
gofmt -l . | grep -v vendor | grep -v dist
exit 1
fi
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
needs: build-and-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:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Download dependencies
run: go mod download
- name: Create test databases
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
- name: Run integration tests
env:
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: |
go test -race ./internal/store/ ./internal/server/ -count=1
GO_LOOSE_BEHAVIOUR=1 go test ./internal/behaviour/ -count=1 -v
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [build-and-test, integration-test]
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Nexus Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.NEXUS_USERNAME }}
password: ${{ secrets.NEXUS_PASSWORD }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# deploy-tst:
# name: Deploy to TST
# runs-on: ubuntu-latest
# needs: docker
# if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
# permissions:
# contents: read
# id-token: write
# environment: tst
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Set up Helm
# uses: azure/setup-helm@v4
# with:
# version: 'v3.14.0'
#
# - name: Set up kubectl
# uses: azure/k8s-set-context@v4
# with:
# kubeconfig: ${{ secrets.KUBECONFIG_TST }}
#
# - name: Deploy to TST with Helm
# run: |
# helm upgrade --install go-loose ./deploy/helm/go-loose \
# --namespace go-loose \
# --create-namespace \
# --set image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
# --set image.tag=${{ github.sha }} \
# --set image.pullSecrets[0].name=nexus-registry \
# --wait --timeout 5m
deploy-prd:
name: Deploy to PRD
runs-on: ubuntu-latest
needs: docker
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
id-token: write
environment: prd
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: 'v3.14.0'
- name: Set up kubectl
uses: azure/k8s-set-context@v4
with:
kubeconfig: ${{ secrets.KUBECONFIG_PRD }}
- name: Deploy to PRD with Helm
run: |
helm upgrade --install go-loose ./deploy/helm/go-loose \
--namespace go-loose \
--create-namespace \
--values ./deploy/helm/go-loose/values-prd.yaml \
--set image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
--set image.tag=${{ github.ref_name }} \
--wait --timeout 5m