Conversation
WalkthroughThe project migrates Python packaging from setup.py to pyproject.toml, restructures the CI/CD pipeline with multi-stage jobs and artifact sharing, adds Python 3.14 support, marks Python 3.15 as experimental, and upgrades Codecov to v5. Changes
Sequence Diagram(s)sequenceDiagram
actor Developer
participant GitHub as GitHub Actions
participant Lint as Lint Job
participant Tests as Tests Job<br/>(Matrix)
participant Build as Build Job
participant TestPyPI as Publish to<br/>Test PyPI
participant PyPI as Publish to<br/>PyPI
participant Artifacts as Artifact<br/>Storage
Developer->>GitHub: Push code
GitHub->>Lint: Start (checks out code)
GitHub->>Tests: Start (multiple Python variants)
Lint->>Lint: Run pre-commit checks
Tests->>Tests: Run test suite
Lint-->>GitHub: ✓ Pass/Fail
Tests-->>GitHub: ✓ Pass/Fail
alt Lint & Tests Pass
GitHub->>Build: Start (needs: [lint, tests])
Build->>Build: Build sdist & wheel
Build->>Artifacts: Upload distributions
Artifacts-->>Build: Stored
alt Test Build
GitHub->>TestPyPI: Start (needs: build)
TestPyPI->>Artifacts: Download artifacts
Artifacts-->>TestPyPI: Retrieved
TestPyPI->>TestPyPI: Publish to Test PyPI
end
alt Production Build
GitHub->>PyPI: Start (needs: build)
PyPI->>Artifacts: Download artifacts
Artifacts-->>PyPI: Retrieved
PyPI->>PyPI: Publish to PyPI
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| @@ -48,8 +81,8 @@ jobs: | |||
| - name: Install dependencies | |||
| shell: bash | |||
| env: | |||
| PIPENV_NOSPIN: "1" | |||
| PIPENV_VENV_IN_PROJECT: "1" | |||
| PIPENV_NOSPIN: '1' | |||
| PIPENV_VENV_IN_PROJECT: '1' | |||
| run: | | |||
| if [ "${{ runner.os }}" = "Windows" ]; then | |||
| export PIPENV_PYTHON="${pythonLocation}\\python.exe" | |||
| @@ -58,87 +91,90 @@ jobs: | |||
| fi | |||
| pipenv install --dev | |||
|
|
|||
| - name: Display Python version | |||
| - name: Run tests | |||
| if: ${{ !(matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13') }} | |||
| env: | |||
| PIPENV_NOSPIN: "1" | |||
| PIPENV_VENV_IN_PROJECT: "1" | |||
| run: pipenv run python -V | |||
|
|
|||
| - name: Run tests (with coverage on Linux CPython 3.12) | |||
| if: ${{ runner.os == 'Linux' && matrix.python-version == '3.12' }} | |||
| env: | |||
| PIPENV_NOSPIN: "1" | |||
| PIPENV_VENV_IN_PROJECT: "1" | |||
| run: pipenv run pytest -ra --cov=persiantools --cov-report xml:coverage.xml tests/ | |||
| PIPENV_NOSPIN: '1' | |||
| PIPENV_VENV_IN_PROJECT: '1' | |||
| run: pipenv run pytest -ra tests/ | |||
|
|
|||
| - name: Run tests (no coverage) | |||
| if: ${{ !(runner.os == 'Linux' && matrix.python-version == '3.12') }} | |||
| - name: Run tests with coverage | |||
| if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13' | |||
| env: | |||
| PIPENV_NOSPIN: "1" | |||
| PIPENV_VENV_IN_PROJECT: "1" | |||
| run: pipenv run pytest -ra tests/ | |||
| PIPENV_NOSPIN: '1' | |||
| PIPENV_VENV_IN_PROJECT: '1' | |||
| run: pipenv run pytest -ra --cov=persiantools --cov-report=xml tests/ | |||
|
|
|||
| - name: Upload coverage to Codecov | |||
| if: ${{ runner.os == 'Linux' && matrix.python-version == '3.12' }} | |||
| uses: codecov/codecov-action@v4 | |||
| if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13' | |||
| uses: codecov/codecov-action@v5 | |||
| with: | |||
| fail_ci_if_error: true | |||
| files: coverage.xml | |||
| fail_ci_if_error: true | |||
| token: ${{ secrets.CODECOV_TOKEN }} | |||
|
|
|||
| lint: | |||
| name: Lint | |||
| build: | |||
| name: Build | |||
| runs-on: ubuntu-latest | |||
| needs: [lint, tests] | |||
| steps: | |||
| - uses: actions/checkout@v4 | |||
| with: | |||
| fetch-depth: 0 | |||
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 days ago
In general, this issue is fixed by explicitly setting a minimal permissions block either at the workflow root (applies to all jobs) or at the individual job level. Since the publish-test-pypi and publish-pypi jobs already specify the extra id-token: write permission they need, the cleanest approach is to set a restrictive default at the workflow root (e.g., contents: read) and then rely on existing job-level permissions for the publishing jobs.
The single best fix here without changing functionality is:
- Add a workflow-level
permissionsblock near the top of.github/workflows/ci.yml, right after theon:block and beforeconcurrency:. - Set
contents: readas the default, which is sufficient foractions/checkout@v4and all the current jobs’ behavior (lint,tests,build). The publishing jobs already definepermissions: id-token: write, which will override the workflow default for those jobs and keep them functioning as before.
Concretely:
-
Edit
.github/workflows/ci.yml. -
After line 10 (
workflow_dispatch:) insert:permissions: contents: read
-
No other imports, methods, or definitions are required; this is purely a workflow YAML change.
| @@ -8,6 +8,9 @@ | ||
| branches: ["**"] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true |
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
| python-version: '3.13' | ||
| cache: 'pip' | ||
| - name: Install pre-commit | ||
| run: pip install pre-commit | ||
| - name: Cache pre-commit | ||
| uses: actions/cache@v4 | ||
|
|
||
| - name: Install build dependencies | ||
| run: python -m pip install --upgrade pip build | ||
|
|
||
| - name: Build sdist and wheel | ||
| run: python -m build | ||
|
|
||
| - name: Upload build artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| path: ~/.cache/pre-commit | ||
| key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} | ||
| - name: Run pre-commit | ||
| run: pre-commit run --all-files | ||
| name: dist | ||
| path: dist/ | ||
| if-no-files-found: error | ||
|
|
||
| build-and-publish: | ||
| publish-test-pypi: | ||
| name: Publish to Test PyPI | ||
| if: github.repository == 'majiidd/persiantools' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | ||
| runs-on: ubuntu-latest | ||
| needs: [build] | ||
| environment: test-pypi | ||
| permissions: | ||
| id-token: write |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 10 days ago
In general, you should explicitly specify permissions for the workflow (or per job) so the GITHUB_TOKEN is restricted to the least privileges necessary. For build and test jobs that only read the repository and interact with external services via their own tokens (like Codecov or PyPI OIDC), contents: read is usually sufficient, and sometimes even contents: none if actions/checkout is not used.
For this workflow, the cleanest and least-disruptive fix is:
- Add a
permissionsblock at the workflow root that applies to all jobs by default, settingcontents: read. This coverslint,tests, andbuild, which only need to read the repo and do not appear to need write access to anything in GitHub. - Keep the existing per-job
permissionsblocks forpublish-test-pypiandpublish-pypi(they already requestid-token: write), letting GitHub merge the defaults with job-specific overrides. They do not needcontentswrite access either, so the rootcontents: readworks fine.
Concretely:
-
In
.github/workflows/ci.yml, add:permissions: contents: read
after the
on:block and before theconcurrency:block (around line 11). -
No other changes to steps or jobs are required.
This adds explicit minimal permissions without changing existing functionality.
| @@ -8,6 +8,9 @@ | ||
| branches: ["**"] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #60 +/- ##
=======================================
Coverage 93.24% 93.24%
=======================================
Files 5 5
Lines 1021 1021
=======================================
Hits 952 952
Misses 69 69 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
setup.pytopyproject.toml(PEP 621).Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.