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
154 changes: 154 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: CI

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

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

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

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

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true

- name: Install dependencies
run: |
go mod download
go mod tidy

- name: Run go fmt
run: |
unformatted=$(gofmt -s -l $(find . -name '*.go' -not -path './vendor/*' -not -path './.git/*' 2>/dev/null))
if [ -n "$unformatted" ]; then
echo "Please run 'go fmt ./...'"
echo "$unformatted"
exit 1
fi

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

- name: Run tests
env:
POSTGRES_DSN: "postgres://postgres:postgres@localhost:5432/linkkeeper_test?sslmode=disable"
run: |
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false

lint:
name: Lint
runs-on: ubuntu-latest

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

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout=5m

build:
name: Build
runs-on: ubuntu-latest
needs: [test, lint]

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

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true

- name: Build api-service
run: go build -v -o bin/api-service ./cmd/api-service

- name: Build user-service
run: go build -v -o bin/user-service ./cmd/user-service

- name: Build bot-service
run: go build -v -o bin/bot-service ./cmd/bot-service

docker:
name: Docker Build
runs-on: ubuntu-latest
needs: [test, lint]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

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

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

- name: Build api-service image
uses: docker/build-push-action@v5
with:
context: .
file: ./build/api-service/Dockerfile
push: false
tags: linkkeeper-api-service:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build user-service image
uses: docker/build-push-action@v5
with:
context: .
file: ./build/user-service/Dockerfile
push: false
tags: linkkeeper-user-service:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build bot-service image
uses: docker/build-push-action@v5
with:
context: .
file: ./build/bot-service/Dockerfile
push: false
tags: linkkeeper-bot-service:latest
cache-from: type=gha
cache-to: type=gha,mode=max
65 changes: 65 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
linters-settings:
govet:
enable:
- shadow
gocyclo:
min-complexity: 20
dupl:
threshold: 150
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US
lll:
line-length: 140
gocritic:
enabled-tags:
- diagnostic
- performance
disabled-checks:
- hugeParam
- ifElseChain

linters:
disable-all: true
enable:
- bodyclose
- errcheck
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- noctx
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- whitespace

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gocyclo
- path: cmd/
linters:
- errcheck
- path: internal/.*/repository\.go
linters:
- dupl
- path: internal/.*/usecase\.go
linters:
- dupl

run:
timeout: 5m
tests: false
skip-dirs:
- vendor
- frontend
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: check-case-conflict
- id: detect-private-key

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
- id: go-vet
- id: go-mod-tidy
- id: go-unit-tests
args: [-timeout=30s, -short]

- repo: local
hooks:
- id: go-test
name: go test
entry: go test -v -race -short ./...
language: system
pass_filenames: false
always_run: true
Loading
Loading