From 72f3ced118918cdee8a3f98d82c8718663911916 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 22 Sep 2023 21:09:20 +0200 Subject: [PATCH] Add postgresql service for testing Signed-off-by: William --- .github/workflows/go.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 925866c..88c6d48 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,6 +13,26 @@ jobs: build: runs-on: ubuntu-latest + # Service containers to run with `runner-job` + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + POSTGRES_DB: authserver + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 steps: - uses: actions/checkout@v3 @@ -20,6 +40,16 @@ jobs: uses: actions/setup-go@v4 with: go-version: '1.20' + + - name: Install golang-migrate + run: | + curl -L https://github.com/golang-migrate/migrate/releases/download/v4.16.2/migrate.linux-amd64.tar.gz | tar xvz + sudo mv migrate.linux-amd64 /usr/bin/ + which migrate + + - name: "Run DB migrations" + run: | + migrate -source file://db/migrations -database 'postgres://postgres:postgres@postgres:5432/authserver?sslmode=disable' up - name: Build run: go build -v ./...