Added migration setup to populate cicd test db #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22.4 | |
- name: Build | |
run: go build -v ./... | |
test: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: bookreviewapp_test | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22.4 | |
- name: Install golang-migrate | |
run: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest | |
# Run migrations before the tests | |
- name: Run Migrations | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
run: | | |
migrate -path ./migrations -database $DATABASE_URL up | |
- name: Run unit tests | |
run: go test -v -tags=unit ./... | |
- name: Run integration tests | |
env: | |
ENVIRONMENT: test | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
run: go test -v -tags=integration ./... |