Skip to content
Merged
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
Comment on lines +15 to +40

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 8 months ago

In general, the fix is to add an explicit permissions block that restricts the GITHUB_TOKEN to the least privileges needed. For a standard Python CI workflow that just checks out code, installs dependencies, and runs lint/tests, read-only access to repository contents is sufficient. This can be done either at the top level of the workflow (applying to all jobs) or inside the build job definition.

The best minimal fix without changing functionality is to add permissions: contents: read at the workflow root, between the on: block and the jobs: block. This ensures all jobs (currently just build) run with a read-only token for repository contents and no additional scopes. Concretely, in .github/workflows/python-package.yml, after line 11 (the last line of the on: block), insert:

permissions:
  contents: read

No imports, methods, or additional definitions are required, as this is purely a YAML configuration change in the workflow file.

Suggested changeset 1
.github/workflows/python-package.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml
--- a/.github/workflows/python-package.yml
+++ b/.github/workflows/python-package.yml
@@ -9,6 +9,9 @@
   pull_request:
     branches: [ "main" ]
 
+permissions:
+  contents: read
+
 jobs:
   build:
 
EOF
@@ -9,6 +9,9 @@
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

Copilot is powered by AI and may make mistakes. Always verify output.
Loading