diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index fc981457..1e9dc4aa 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,4 @@ -name: Go CI +xiname: Go CI on: push: @@ -7,10 +7,26 @@ on: branches: [ master ] jobs: - test: + build: runs-on: ubuntu-latest + services: + postgres: + image: postgres:13 + ports: + - 5432:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres # Default database + + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: Checkout code uses: actions/checkout@v2 @@ -20,12 +36,29 @@ jobs: with: go-version: '1.22' # Adjust this to your Go version + - name: Wait for PostgreSQL + run: | + until pg_isready -h localhost -p 5432; do + echo "Waiting for PostgreSQL to be ready..." + sleep 1 + done + + - name: Create the database + run: | + psql postgresql://postgres:postgres@localhost:5432/postgres -c "CREATE DATABASE zettelkasten;" + - name: Install dependencies run: | cd go-backend go mod download - name: Run tests + env: + DB_HOST: localhost + DB_PORT: 5432 + DB_USER: postgres + DB_PASSWORD: postgres + DB_NAME: zettelkasten run: | cd go-backend go test ./...