ci/cd #5
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: Go API Tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
POSTGRES_DB: librarymanagementsystem_test | |
ports: | |
- 5432:5432 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: "^1.22.2" | |
- name: Install dependencies | |
run: go mod download | |
- name: Start PostgreSQL and wait for connection | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y netcat | |
until nc -z localhost 5432; do | |
echo "Waiting for PostgreSQL..." | |
sleep 3 | |
done | |
- name: Install migrate | |
run: | | |
go install github.com/golang-migrate/migrate/v4/cmd/migrate@latest | |
echo "$GOPATH/bin" >> $GITHUB_PATH | |
- name: Run database migrations | |
run: | | |
# Boş bir Go dosyası oluştur | |
echo "package main\n\nimport _ \"github.com/golang-migrate/migrate/v4/database/postgres\"" > dummy.go | |
# Go mod tidy ile bağımlılıkları düzenle | |
go mod tidy | |
migrate -database "postgres://postgres:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/librarymanagementsystem_test?sslmode=disable" -path migrations/ up | |
- name: Run tests | |
run: go test -v ./... -coverprofile=coverage.txt -covermode=atomic |