This repository was archived by the owner on Apr 23, 2025. It is now read-only.
forked from raizamartin/gemini-code
-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (100 loc) · 3.7 KB
/
python-ci.yml
File metadata and controls
119 lines (100 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Python CI
on:
push:
branches: [ "main" ]
tags: [ "v*" ] # Trigger on tags starting with v
pull_request:
branches: [ "main" ]
permissions:
contents: read # Allow checkout
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"] # Match requires-python in pyproject.toml
steps:
- uses: actions/checkout@v4
with:
# SonarCloud needs the full history to assign issues properly
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff # Install ruff separately first
# Ensure pytest-cov is installed via [dev] extras
pip install -e .[dev]
# Explicitly install pytest-cov to ensure it's available
pip install pytest-cov
# - name: Debug Python Path
# run: python -c "import sys; print(sys.path)"
- name: Lint with Ruff (check)
run: |
ruff check --fix --verbose --preview .
- name: Lint with Ruff (format)
run: |
ruff format . # Remove --check to auto-format files
- name: Test with pytest and Generate Coverage
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
PYTHONPATH: ${{ github.workspace }}/src
# Ensure API key exists for tests that might need it, but allow skipping
run: |
# List available test files to debug
echo "Available test files:"
ls -la test_dir/
# Run pytest with more comprehensive coverage
# Generate both XML and HTML reports
python -m pytest --cov=cli_code --cov-report=term --cov-report=xml --cov-report=html --verbose test_dir/
# Display the overall coverage percentage
echo "Overall coverage percentage:"
python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(f\"Coverage: {float(root.attrib['line-rate'])*100:.2f}%\")"
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master # Or use a specific version like @v2.1
env:
# GITHUB_TOKEN: {{ secrets.GITHUB_TOKEN }} # Needed to decorate PRs with analysis results
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Required: Store your SonarCloud token as a GitHub secret
with:
args: >
# Tell scanner where the coverage report is
-Dsonar.python.coverage.reportPaths=coverage.xml
# Add organization and project key if not using sonar-project.properties
# -Dsonar.organization=your-org-key
# -Dsonar.projectKey=your-project-key
- name: Build package
run: python -m build
- name: Store built packages
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
- name: Upload coverage reports as artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: |
coverage.xml
coverage_html/
retention-days: 7
publish:
name: Publish to PyPI
needs: build-and-test
# Only publish when a tag is pushed
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment: publish
permissions:
id-token: write # Required for PyPI publishing with trusted publishing
steps:
- name: Download built packages
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1