Skip to content

feat: implement Operation Protocol Improvements (OPI) architecture #20

feat: implement Operation Protocol Improvements (OPI) architecture

feat: implement Operation Protocol Improvements (OPI) architecture #20

Workflow file for this run

# .github/workflows/ci.yml
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
PYTHON_VERSION: '3.11'
POSTGRES_VERSION: '13'
REDIS_VERSION: '6'
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_brc20_indexer
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:6
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install pipenv
run: |
python -m pip install --upgrade pip
pip install pipenv
- name: Cache pipenv dependencies
uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pipenv-
- name: Install dependencies
run: |
pipenv install --dev --python $(which python)
- name: Code quality checks
run: |
pipenv run black --check src tests
pipenv run flake8 src tests
pipenv run mypy src --ignore-missing-imports
- name: Security checks
run: |
pipenv run bandit -r src -f json -o bandit-report.json || true
pipenv run safety check --json --output safety-report.json || true
- name: Run tests
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_brc20_indexer
REDIS_URL: redis://localhost:6379/0
BITCOIN_RPC_URL: http://localhost:8332
BITCOIN_RPC_USER: test
BITCOIN_RPC_PASSWORD: test
run: |
pipenv run pytest tests/ -v --cov=src --cov-report=xml --cov-report=term-missing
- name: Performance tests
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_brc20_indexer
REDIS_URL: redis://localhost:6379/0
run: |
pipenv run pytest tests/integration/test_performance.py -v --tb=short
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
build:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# - name: Log in to Docker Hub
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: The-Universal-BRC-20-Extension/simplicity
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build Docker image (no push)
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: local-build:test
cache-from: type=gha
cache-to: type=gha,mode=max
integration:
needs: build
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: integration_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:6
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build test image
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: universal-brc20-indexer:test
cache-from: type=gha
- name: Run integration tests
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/integration_test
REDIS_URL: redis://localhost:6379/0
run: |
docker run --rm --network host \
-e DATABASE_URL=$DATABASE_URL \
-e REDIS_URL=$REDIS_URL \
universal-brc20-indexer:test \
pipenv run pytest tests/integration/test_integration.py -v
- name: Health check validation
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/integration_test
REDIS_URL: redis://localhost:6380/0
run: |
docker run --rm --network host \
-e DATABASE_URL=$DATABASE_URL \
-e REDIS_URL=$REDIS_URL \
-d --name test-indexer \
universal-brc20-indexer:test
echo "DATABASE_URL: $DATABASE_URL"
echo "REDIS_URL: $REDIS_URL"
echo "Health check URL: http://localhost:8080/v1/indexer/brc20/health"
sleep 6
# Wait up to 6 seconds for the service to be up
for i in {1..60}; do
if curl -f http://localhost:8080/v1/indexer/brc20/health; then
echo "Service is up!"
docker stop test-indexer
exit 0
fi
echo "Waiting for service to start... ($i/60)"
sleep 1
done
echo "Service did not start in time. Printing logs:"
docker logs test-indexer
docker stop test-indexer
exit 1