name: Build and Deploy Mimir
on:
push:
branches:
- main
- 'release/**'
pull_request:
branches: [main]
release:
types: [published]
env:
ACR_NAME: acrmimir
ACR_LOGIN_SERVER: acrmimir.azurecr.io
IMAGE_NAME: mimir
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.14'
cache: 'pip'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-cov pytest-html
- name: Run database migrations
run: |
python manage.py migrate --noinput
- name: Run tests with coverage
run: |
pytest tests/ -v \
--ignore=tests/integration/test_mcp_server_acceptance.py \
--ignore=tests/unit/test_activity_graph_service.py \
--cov=. \
--cov-report=html \
--cov-report=term \
--cov-report=xml \
--html=report.html \
--self-contained-html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: github.event_name != 'pull_request'
with:
files: ./coverage.xml
flags: unittests
name: codecov-mimir
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: |
report.html
htmlcov/
- name: Comment PR with test results
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Read test results (simplified - you can parse actual results)
const testStatus = '${{ job.status }}';
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const comment = `## ๐งช Test Results
**Status:** ${testStatus === 'success' ? 'โ
All tests passed' : 'โ Tests failed'}
[View full test report](${runUrl})
**Coverage report** is available in the artifacts.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
build-and-push:
name: Build and Push Docker Image
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'release'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Azure Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.ACR_LOGIN_SERVER }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=match,pattern=release/(.*),group=1
type=sha,prefix={{branch}}-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=release-latest,enable=${{ startsWith(github.ref, 'refs/heads/release/') }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- name: Image digest
run: echo ${{ steps.meta.outputs.digest }}
- name: Create deployment summary
run: |
echo "## ๐ Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** \`${{ env.ACR_LOGIN_SERVER }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Pull Command:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY