From 8a7bfc011f5e63279240263cc5bd4187260a390a Mon Sep 17 00:00:00 2001 From: huayitang Date: Mon, 22 Sep 2025 00:49:30 +0200 Subject: [PATCH] after review --- .github/workflows/go.yml | 91 +++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5de7dd1..8f22367 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,16 +1,12 @@ -# This workflow will build a golang project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go - name: Go on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: - build: runs-on: ubuntu-latest services: @@ -23,55 +19,54 @@ jobs: ports: - 5432:5432 options: >- - --health-cmd="pg_isready -U app -d productdb" - --health-interval=10s - --health-timeout=5s + --health-cmd="pg_isready -U app -d productdb" + --health-interval=10s + --health-timeout=5s --health-retries=5 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.24.x' - check-latest: true - cache: true + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.x' + check-latest: true + cache: true - - name: Tidy modules - run: go mod tidy + - name: Tidy modules + run: go mod tidy - - name: Install psql client - run: | - sudo apt-get update - sudo apt-get install -y postgresql-client + - name: Install psql client + run: | + sudo apt-get update + sudo apt-get install -y postgresql-client - - name: Wait for Postgres - env: - PGPASSWORD: app_password - run: | - for i in {1..30}; do - if pg_isready -h localhost -p 5432 -U app -d productdb; then - echo "Postgres is ready"; break; fi; sleep 2; done - pg_isready -h localhost -p 5432 -U app -d productdb - - - name: Apply migrations (psql) - env: - PGPASSWORD: app_password - run: | - psql -v ON_ERROR_STOP=1 -h localhost -p 5432 -U app -d productdb -f apps/product-query-svc/adapters/outbound/postgres/migrations/000001_init.up.sql - psql -v ON_ERROR_STOP=1 -h localhost -p 5432 -U app -d productdb -f apps/product-query-svc/adapters/outbound/postgres/migrations/000002_seed_test_data.up.sql + - name: Wait for Postgres + env: + PGPASSWORD: app_password + run: | + for i in {1..30}; do + if pg_isready -h localhost -p 5432 -U app -d productdb; then + echo "Postgres is ready"; break; fi; sleep 2; done + pg_isready -h localhost -p 5432 -U app -d productdb - - name: Test (integration: Postgres endpoints) - env: - DATABASE_URL: postgres://app:app_password@localhost:5432/productdb?sslmode=disable - run: | - go test -v ./test/... -run Postgres + - name: Apply migrations (psql) + env: + PGPASSWORD: app_password + run: | + psql -v ON_ERROR_STOP=1 -h localhost -p 5432 -U app -d productdb -f apps/product-query-svc/adapters/outbound/postgres/migrations/000001_init.up.sql + psql -v ON_ERROR_STOP=1 -h localhost -p 5432 -U app -d productdb -f apps/product-query-svc/adapters/outbound/postgres/migrations/000002_seed_test_data.up.sql + - name: Test (integration: Postgres endpoints) + env: + DATABASE_URL: postgres://app:app_password@localhost:5432/productdb?sslmode=disable + run: | + go test -v ./test/... -run Postgres - - name: Build - run: go build -v ./... + - name: Build + run: go build -v ./... - - name: Test (all) - env: - DATABASE_URL: postgres://app:app_password@localhost:5432/productdb?sslmode=disable - run: go test -v ./... + - name: Test (all) + env: + DATABASE_URL: postgres://app:app_password@localhost:5432/productdb?sslmode=disable + run: go test -v ./... \ No newline at end of file