Skip to content
Merged
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
251 changes: 130 additions & 121 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,128 +1,137 @@
name: CI

on:
pull_request:
branches:
- "*"
push:
branches:
- prod
- main
- master
- dev
pull_request:
branches:
- "*"
push:
branches:
- prod
- main
- master
- dev

env:
GO_VERSION: "1.24.x"
NODE_VERSION: "24"
GO_VERSION: "1.25.0"
NODE_VERSION: "24"

jobs:
go-server:
name: Go Server CI
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./apps/server

services:
postgres:
image: postgres:18
env:
POSTGRES_USER: coderz-space
POSTGRES_PASSWORD: coderz-space
POSTGRES_DB: coderz
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: apps/server/go.sum

- name: Install dependencies
run: go mod download

- name: Verify dependencies
run: go mod verify

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

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...

- name: Install golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: apps/server
args: --timeout=5m

- name: Setup test environment
run: |
cp .env .env.test
echo "DB_URL=postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" >> .env.test
echo "DB_DSN=postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" >> .env.test

- name: Run migrations
run: |
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
migrate -path ./db/migrations -database "postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" up

- name: Run tests
env:
DB_URL: postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...

- name: Upload coverage
uses: codecov/codecov-action@v5
with:
files: ./apps/server/coverage.out
flags: go-server
fail_ci_if_error: false

- name: Build binary
run: go build -v -o bin/main ./cmd/main.go

- name: Install swag
run: go install github.com/swaggo/swag/cmd/swag@latest

- name: Generate Swagger docs
run: swag init -o ./swagger --parseDependency --parseInternal -g cmd/main.go

- name: Verify Swagger docs
run: test -f swagger/swagger.json && test -f swagger/swagger.yaml

docker-build:
name: Docker Build
runs-on: ubuntu-latest
needs: go-server

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: ./apps/server
file: ./apps/server/dockerfile
push: false
tags: coderz-space-server:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
go-server:
name: Go Server CI
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./apps/server

services:
postgres:
image: postgres:18
env:
POSTGRES_USER: coderz-space
POSTGRES_PASSWORD: coderz-space
POSTGRES_DB: coderz
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v4

# ✅ Go setup (aligned with go.mod)
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: apps/server/go.sum

- name: Install dependencies
run: go mod download

- name: Verify dependencies
run: go mod verify

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

# ✅ staticcheck built with correct Go version
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...

# ✅ golangci-lint (compatible with Go 1.25)
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: apps/server
args: --timeout=5m

# ✅ Test env
- name: Setup test environment
run: |
cp .env .env.test
echo "DB_URL=postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" >> .env.test
echo "DB_DSN=postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" >> .env.test

# ✅ DB migrations
- name: Run migrations
run: |
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
migrate -path ./db/migrations -database "postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" up

# ✅ Tests
- name: Run tests
env:
DB_URL: postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...

# ✅ Coverage upload
- name: Upload coverage
uses: codecov/codecov-action@v5
with:
files: ./apps/server/coverage.out
flags: go-server
fail_ci_if_error: false

# ✅ Build
- name: Build binary
run: go build -v -o bin/main ./cmd/main.go

# ✅ Swagger
- name: Install swag
run: go install github.com/swaggo/swag/cmd/swag@latest

- name: Generate Swagger docs
run: swag init -o ./swagger --parseDependency --parseInternal -g cmd/main.go

- name: Verify Swagger docs
run: test -f swagger/swagger.json && test -f swagger/swagger.yaml

docker-build:
name: Docker Build
runs-on: ubuntu-latest
needs: go-server

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: ./apps/server
file: ./apps/server/dockerfile
push: false
tags: coderz-space-server:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
78 changes: 40 additions & 38 deletions apps/server/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
run:
timeout: 5m
tests: true
modules-download-mode: readonly
linters-settings:
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
check-type-assertions: false
# Report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
check-blank: false
# List of functions to exclude from checking.
exclude-functions:
- (*database/sql.Tx).Rollback
- (*github.com/jackc/pgx/v5.Tx).Rollback

gosec:
excludes:
- G101 # Potential hardcoded credentials - false positive for constant names
- G115 # Integer overflow conversion - acceptable for pagination limits

gocritic:
# All checks are enabled by default, no need to disable specific ones

govet:
disable:
- fieldalignment # Micro-optimization, not critical

linters:
enable:
- errcheck
- gosimple
- gosec
- gocritic
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- gofmt
- goimports
- misspell
- unconvert
- unparam
- gosec
- gocritic

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true

govet:
enable-all: true
disable:
- shadow

gofmt:
simplify: true

gosec:
excludes:
- G404 # Use of weak random number generator (math/rand instead of crypto/rand)

gocritic:
enabled-tags:
- diagnostic
- style
- performance

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- errcheck
- gosec
- path: cmd/main\.go
linters:
- errcheck
- gocritic
- govet

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

exclude-dirs:
- vendor
- swagger

run:
timeout: 5m
tests: true
4 changes: 2 additions & 2 deletions apps/server/CI-CD.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The CI pipeline runs on:
**Steps:**

1. Checkout code
2. Setup Go 1.25.x with dependency caching
2. Setup Go 1.24.x with dependency caching
3. Install and verify dependencies
4. Run `go vet` for static analysis
5. Run `staticcheck` for additional linting
Expand Down Expand Up @@ -72,7 +72,7 @@ The CI pipeline runs on:

**Build Strategy:** Multi-stage build

- **Stage 1 (builder):** Go 1.25-alpine with build tools
- **Stage 1 (builder):** Go 1.24-alpine with build tools
- **Stage 2 (runtime):** Minimal Alpine with only the binary

**Features:**
Expand Down
6 changes: 3 additions & 3 deletions apps/server/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Coderz.space Server

[![CI](https://github.com/DSAwithGautam/Coderz.space/actions/workflows/ci.yaml/badge.svg)](https://github.com/DSAwithGautam/Coderz.space/actions/workflows/ci.yaml)
[![CI](https://github.com/coderz-space/coderz.space/actions/workflows/ci.yaml/badge.svg)](https://github.com/coderz-space/coderz.space/actions/workflows/ci.yaml)

Go-based backend server for the Coderz.space bootcamp management platform.

Expand All @@ -11,7 +11,7 @@ Go-based backend server for the Coderz.space bootcamp management platform.

## Tech Stack

- Go 1.25+
- Go 1.24+
- Echo v5 (Web Framework)
- PostgreSQL 18
- SQLC (Type-safe SQL)
Expand All @@ -22,7 +22,7 @@ Go-based backend server for the Coderz.space bootcamp management platform.

### Prerequisites

- Go 1.25+
- Go 1.24+
- PostgreSQL 18
- Docker & Docker Compose (optional)
- Make
Expand Down
Loading
Loading