Updated linting errors and workflow file #9
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: | |
lint: | |
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: Cache Go modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: latest | |
build: | |
needs: lint | |
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: Cache Go modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Build | |
run: go build -v ./... | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: app-binary | |
path: ./your-app-binary-name | |
test: | |
needs: build | |
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: Cache Go modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Download build artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: app-binary | |
- name: Install golang-migrate | |
run: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest | |
- name: Run Migrations | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/bookreviewapp_test?sslmode=disable | |
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: postgres://postgres:postgres@localhost:5432/bookreviewapp_test?sslmode=disable | |
run: go test -v -tags=integration ./... |