Skip to content

finalized the document and test case. #1

finalized the document and test case.

finalized the document and test case. #1

Workflow file for this run

name: CI
on:
push:
branches: [ master, main, develop ]
pull_request:
branches: [ master, main, develop ]
jobs:
# Python Tests
test-python:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11', '3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
cd python
pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
cd python
flake8 app/ tests/ --max-line-length=120 --exclude=__pycache__
- name: Type check with mypy
run: |
cd python
mypy app/ --ignore-missing-imports
- name: Run unit tests
run: |
cd python
pytest tests/ -v --cov=app --cov-report=xml --cov-report=term -m "not integration"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: python/coverage.xml
flags: python
name: python-coverage
# Go Tests
test-go:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21', '1.22']
steps:
- uses: actions/checkout@v3
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
run: |
cd go
go mod download
- name: Lint
run: |
cd go
go fmt ./...
go vet ./...
- name: Run tests
run: |
cd go
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: go/coverage.out
flags: go
name: go-coverage
# Integration Tests
integration-test:
runs-on: ubuntu-latest
needs: [test-python, test-go]
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: ironsys
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Python dependencies
run: |
cd python
pip install --upgrade pip
pip install -r requirements.txt
- name: Start Kafka and Zookeeper
run: |
docker-compose -f docker-compose.yml up -d zookeeper kafka
sleep 20
- name: Run database migrations
run: |
PGPASSWORD=dev psql -h localhost -U dev -d ironsys -f db/migrations/001_init_schema.sql || true
- name: Start Python services
run: |
cd python
python -m app.api.main &
APP_PID=$!
echo "API_PID=$APP_PID" >> $GITHUB_ENV
sleep 5
- name: Run integration tests
run: |
cd python
pytest tests/integration/ -v -m integration
- name: Stop services
if: always()
run: |
kill ${{ env.API_PID }} || true
docker-compose -f docker-compose.yml down
# Build Docker Images
build-docker:
runs-on: ubuntu-latest
needs: [test-python, test-go]
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Python API image
run: |
cd python
docker build -f Dockerfile.api -t ironsys-python-api:${{ github.sha }} .
- name: Build Python Worker image
run: |
cd python
docker build -f Dockerfile.worker -t ironsys-python-worker:${{ github.sha }} .
- name: Build Go API image
run: |
cd go
docker build -f Dockerfile.api -t ironsys-go-api:${{ github.sha }} .
- name: Build Go Worker image
run: |
cd go
docker build -f Dockerfile.worker -t ironsys-go-worker:${{ github.sha }} .
# Security Scan
security-scan:
runs-on: ubuntu-latest
needs: [test-python, test-go]
steps:
- uses: actions/checkout@v3
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'