Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: CI

on:
push:
branches: [ main, "feat/**", "feature/**", "fix/**" ]
pull_request:
branches: [ main ]

env:
GO_VERSION: "1.21"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Run go vet
run: go vet ./...

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest

test:
name: Test
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
POSTGRES_DB: testdb
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
DATABASE_URL: postgres://testuser:testpass@localhost:5432/testdb?sslmode=disable
REDIS_URL: redis://localhost:6379
JWT_SECRET: test-secret-key-minimum-32-characters-long
SERVER_URL: http://localhost:8080

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Run tests
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...

- name: Coverage gate (≥ 60%)
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
echo "Total coverage: ${COVERAGE}%"
awk "BEGIN { exit ($COVERAGE < 60) }" || (echo "Coverage ${COVERAGE}% is below 60%"; exit 1)

- name: Upload coverage
uses: codecov/codecov-action@v4
with:
file: coverage.out
continue-on-error: true

build:
name: Build
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Build binary
run: go build -v -ldflags="-s -w" -o bin/auth-server ./cmd/auth-server/...

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: auth-server
path: bin/auth-server
retention-days: 7

security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Run gosec
run: gosec -exclude-dir=tests ./...
continue-on-error: true
Loading
Loading