Adding service DB in Github action
This is so useful for testing purposes, plus it’s getting easier to do so. Let’s take a look for PostgreSQL and MySQL. Adding PostgreSQL in Github action name: Build on: push jobs: build: runs-on: ubuntu-latest services: # Label used to access the service container postgres: # Docker Hub image image: postgres:13 # Provide the password for postgres env: POSTGRES_USER: root POSTGRES_PASSWORD: test POSTGRES_DB: sqljson # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 steps: - uses: actions/checkout@v2 - name: Setup go uses: actions/setup-go@v2 with: go-version: ^1.17 - name: Install go migrate run: | curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.1/migrate.linux-amd64.tar.gz | tar xvz; sudo mv migrate /usr/bin/migrate - name: Run migration run: migrate -path db/migration -database "postgresql://root:test@localhost:5432/sqljson?sslmode=disable" -verbose up - run: go test -v ./... Adding MySQL in Github action I wanted to do the exact same for MySQL but it’s even simpler because mysql is already present, you just need to start it. ...