4c8f3022f0
- Create PasswordHasher interface in domain layer - Implement BcryptHasher in infrastructure layer - Update RegisterUserHandler and LoginUserHandler to use interface - Remove bcrypt dependency from application layer - Update main.go and integration tests with dependency injection - Enhance CI/CD workflow with test and lint jobs - Add code coverage check (minimum 50%) - Add go vet and gofmt validation - Configure build job to depend on test and lint passing - Update GitHub Actions to latest versions (v4→v5) This achieves 100% SOLID compliance (DIP) and ensures Clean Architecture by removing external library dependencies from application/domain layers.
93 lines
2.0 KiB
YAML
93 lines
2.0 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
tags: [ 'v*' ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.21'
|
|
|
|
- name: Run tests
|
|
run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic
|
|
|
|
- name: Check code coverage
|
|
run: |
|
|
total=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}' | sed 's/%//')
|
|
echo "Total coverage: $total%"
|
|
if (( $(echo "$total < 50" | bc -l) )); then
|
|
echo "Error: Code coverage is below 50%"
|
|
exit 1
|
|
fi
|
|
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.21'
|
|
|
|
- name: Run go vet
|
|
run: go vet ./...
|
|
|
|
- name: Run go fmt
|
|
run: |
|
|
if [ -n "$(gofmt -s -l .)" ]; then
|
|
echo "Go code is not formatted:"
|
|
gofmt -s -d .
|
|
exit 1
|
|
fi
|
|
|
|
build:
|
|
name: Build and Push Docker Image
|
|
runs-on: ubuntu-latest
|
|
needs: [test, lint]
|
|
if: github.event_name == 'push'
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=tag
|
|
type=sha
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|