Skip to content

test

test #115

Workflow file for this run

name: Go
on:
push:
branches:
- main
pull_request:
paths:
- "backend/**"
- "scripts/init_db.sh"
- ".github/workflows/go.yml"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.21"
- name: Enforce formatting
run: gofmt -l ./backend/ | grep ".go$" | xargs -r echo "Files not formatted:"
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.21"
- name: Enforce linting
run: |
cd backend && lint_output=$(go vet ./...)
if [[ -n "$lint_output" ]]; then
echo "$lint_output"
echo "::error::Linting issues found"
exit 1
fi
test:
name: Test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: sac
ports:
- 5432:5432
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.21"
- name: Install Dependencies
run: cd backend && go get ./...
- name: Migrate DB
run: |
cd backend/src && go run main.go --only-migrate
- name: Run Tests with Coverage
run: cd backend && go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Print Coverage
run: cd backend && go tool cover -func=coverage.txt