Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
68d7665
test: trigger CI workflow
shiningflash Nov 8, 2025
7ec325e
include path
shiningflash Nov 8, 2025
dcdf4aa
change allure path
shiningflash Nov 8, 2025
ff0ef6b
first generate the Allure report
shiningflash Nov 8, 2025
ba9b14a
Update ci.yml
shiningflash Nov 8, 2025
4e76868
Update ci.yml
shiningflash Nov 8, 2025
576d8d2
allure url message
shiningflash Nov 8, 2025
e255acf
message update
shiningflash Nov 8, 2025
7ce26da
Update ci.yml
shiningflash Nov 8, 2025
35fd8e5
wrong test
shiningflash Nov 8, 2025
8fa2fae
Update ci.yml
shiningflash Nov 8, 2025
6d5abb8
run always
shiningflash Nov 8, 2025
9547244
Update ci.yml
shiningflash Nov 8, 2025
1b830db
Update ci.yml
shiningflash Nov 8, 2025
74f655f
Update ci.yml
shiningflash Nov 8, 2025
d870555
Update ci.yml
shiningflash Nov 8, 2025
c3bb3a3
Update ci.yml
shiningflash Nov 9, 2025
9eb0dcf
Update ci.yml
shiningflash Nov 9, 2025
2fd4008
Update ci.yml
shiningflash Nov 9, 2025
fadf5de
Update ci.yml
shiningflash Nov 9, 2025
36ca6be
more error
shiningflash Nov 9, 2025
bd5c597
Update test_contacts_integration.py
shiningflash Nov 9, 2025
d0fa379
Update Allure report build info and fix test assertion
shiningflash Nov 9, 2025
043b55a
Update test_contacts_e2e.py
shiningflash Nov 9, 2025
600e588
Update ci.yml
shiningflash Nov 9, 2025
0a8d26b
Update test_contacts_e2e.py
shiningflash Nov 9, 2025
db54f8e
Update ci.yml
shiningflash Nov 9, 2025
297fe20
Update ci.yml
shiningflash Nov 9, 2025
6f3069e
Update test_contacts_e2e.py
shiningflash Nov 9, 2025
49920ec
Update ci.yml
shiningflash Nov 9, 2025
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
123 changes: 103 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: CI - Code Testing Workflow

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- develop
- main
Expand All @@ -10,52 +11,134 @@ on:
paths:
- "src/**"
- "tests/**"

permissions:
contents: write
pull-requests: write
checks: write
- ".github/workflows/**"
push:
branches:
- develop
- main
paths:
- "src/**"
- "tests/**"
- ".github/workflows/**"

jobs:
test:
name: Run Tests and Post Coverage
concurrency:
group: allure-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest

env: # Load environment variables from repository secrets
permissions:
contents: write
pull-requests: write
env:
BASE_URL: ${{ secrets.BASE_URL }}
API_KEY: ${{ secrets.API_KEY }}
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}

steps:
# Step 1: Checkout the repository code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

# Step 3: Install dependencies
- name: Set up Node (for Allure CLI)
uses: actions/setup-node@v4
with:
node-version: "18"

- name: Install dependencies
run: |
python -m venv venv # Create a virtual environment
source venv/bin/activate # Activate the virtual environment
pip install --upgrade pip # Upgrade pip
pip install pytest pytest-cov # Install coverage tools
pip install -r requirements.txt # Install project dependencies

# Step 4: Run tests with coverage
- name: Run tests with coverage
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install pytest pytest-cov allure-pytest
pip install -r requirements.txt
npm install -g allure-commandline

- name: Run tests (coverage + allure results)
id: run_tests
run: |
source venv/bin/activate
pytest --cov=src --cov-report=xml --cov-report=term > coverage.txt
pytest --cov=src --cov-report=xml --cov-report=term \
--alluredir=allure-results --tb=short > coverage.txt 2>&1 || echo "TESTS_FAILED=true" >> $GITHUB_ENV
pytest --junitxml=pytest.xml
continue-on-error: true

# Step 5: Post coverage summary to the pull request
- name: Pytest coverage comment
if: github.event_name == 'pull_request' && always()
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./coverage.txt
junitxml-path: ./pytest.xml

- name: Pull previous Allure history (if exists)
if: always()
run: |
git fetch origin allure-report || true
if git ls-remote --exit-code origin allure-report; then
git checkout origin/allure-report -- history || true
if [ -d history ]; then
mkdir -p allure-results/history
cp -r history/* allure-results/history/ || true
fi
fi

- name: Generate Allure Report
if: always()
run: |
allure generate allure-results -o allure-report --clean || echo "No allure-results to generate"
echo "<!-- build: run-${{ github.run_number }} -->" >> allure-report/index.html
touch allure-report/.nojekyll

- name: Deploy Allure Report to GitHub Pages branch
if: always()
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: allure-report
publish_dir: ./allure-report
keep_files: true
force_orphan: false
commit_message: "docs(allure): update report for ${{ github.sha }} (run ${{ github.run_number }})"

- name: Comment PR with Allure Report URL
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const bust = `${context.runNumber}`;
const reportUrl = `https://${owner}.github.io/${repo}/?run=${bust}`;

// Determine test result color and icon
const testsFailed = process.env.TESTS_FAILED === 'true';
const badgeColor = testsFailed ? 'E63946' : '2EA44F'; // red : green
const testStatus = testsFailed ? '⚠️ (Some tests failed)' : '✅ All tests passed';

const body = `## 📊 Test Report ${testStatus}

Coverage trends • Module breakdown • Failure analysis • Execution timeline

[![View Allure Dashboard](https://img.shields.io/badge/View%20Dashboard-${badgeColor}?style=for-the-badge&logo=google-chrome&logoColor=white)](${reportUrl})

⚠️ NB: If the dashboard doesn't update immediately, try a hard reload (Cmd + Shift + R on Mac) or open in incognito mode.`;

const { data: comments } = await github.rest.issues.listComments({
owner, repo, issue_number: context.issue.number
});
const marker = '📊 Test Report';
const existing = comments.find(c => c.user.type === 'Bot' && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ owner, repo, issue_number: context.issue.number, body });
}

- name: Fail job if tests failed
if: env.TESTS_FAILED == 'true'
run: exit 1
2 changes: 1 addition & 1 deletion tests/e2e/test_contacts_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_create_and_retrieve_contact(mock_api_client, contacts):

# Ensure API calls were made as expected
mock_api_client.request.assert_any_call("POST", "/contacts", json=contact_payload)
mock_api_client.request.assert_any_call("GET", "/contacts/contact123")
mock_api_client.request.assert_any_call("GET", "/contacts/contact12")


@pytest.mark.e2e
Expand Down
Loading