Skip to content

fix github actions format and permissions#120

Merged
gmorales96 merged 1 commit into
mainfrom
fix/github-actions-format-and-permissions
Jun 1, 2026
Merged

fix github actions format and permissions#120
gmorales96 merged 1 commit into
mainfrom
fix/github-actions-format-and-permissions

Conversation

@gmorales96
Copy link
Copy Markdown
Contributor

@gmorales96 gmorales96 commented Jun 1, 2026

Summary by CodeRabbit

  • Chores
    • Updated GitHub Actions workflow configurations with explicit security permissions declarations.
    • Updated test workflow Python version matrix configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Walkthrough

This PR adds explicit permissions: contents: read declarations to four GitHub Actions workflows (auto_merge, docs, release, and test) to restrict the GitHub token's access scope. The test workflow also receives a formatting update: the pytest job's Python version matrix is converted to a double-quoted JSON-style list format and the steps block is reflowed, while the test execution logic remains unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding explicit permissions declarations and fixing formatting in GitHub Actions workflows across four files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/github-actions-format-and-permissions

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (46f146d) to head (e230c4f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #120   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines          470       470           
=========================================
  Hits           470       470           
Flag Coverage Δ
unittests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46f146d...e230c4f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/docs.yml:
- Around line 3-4: The workflow currently sets GitHub token permissions to
"permissions: contents: read", which prevents mkdocs gh-deploy --force from
pushing to gh-pages; update the workflow's permissions block so the contents
permission is write (e.g., change "contents: read" to "contents: write") to
allow the deploy step to push commits.

In @.github/workflows/test.yml:
- Around line 26-36: Update the pytest job steps to pin GitHub Actions to
specific commit SHAs and disable checkout credential persistence: replace the
actions/checkout@v4 reference with the corresponding
actions/checkout@<COMMIT_SHA> and replace actions/setup-python@v5 with
actions/setup-python@<COMMIT_SHA>, and in the checkout step add with:
persist-credentials: false; keep the step names ("Set up Python ${{
matrix.python-version }}", "Install dependencies", "Run tests") and matrix usage
unchanged so the job still runs across the python-version matrix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5bc44440-a343-48d5-b6cd-64c975040cd6

📥 Commits

Reviewing files that changed from the base of the PR and between 46f146d and e230c4f.

📒 Files selected for processing (4)
  • .github/workflows/auto_merge.yml
  • .github/workflows/docs.yml
  • .github/workflows/release.yml
  • .github/workflows/test.yml

Comment on lines +3 to +4
permissions:
contents: read
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify docs workflow has a push-style deploy command with read-only permissions.
rg -n '^\s*permissions:|^\s*contents:|mkdocs gh-deploy' .github/workflows/docs.yml

Repository: cuenca-mx/facturapi-python

Length of output: 145


🏁 Script executed:

#!/bin/bash
# Inspect docs workflow for how mkdocs gh-deploy is authenticated/where token comes from.
set -euo pipefail
echo "---- file head/around permissions ----"
nl -ba .github/workflows/docs.yml | sed -n '1,60p'
echo "---- auth/token-related env/steps ----"
rg -n 'GH_TOKEN|GITHUB_TOKEN|token:|secrets\..*TOKEN|deploy key|ssh|persist-credentials|set-url|remote|credentials' .github/workflows/docs.yml

Repository: cuenca-mx/facturapi-python

Length of output: 170


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- permissions section (top of file) ----"
awk '{print NR ":" $0}' .github/workflows/docs.yml | sed -n '1,80p'

echo "---- token/auth-related configuration ----"
rg -n 'GH_TOKEN|GITHUB_TOKEN|token:|secrets\..*TOKEN|deploy key|ssh|persist-credentials|set-url|remote|credentials' .github/workflows/docs.yml || true

echo "---- mkdocs deploy step context ----"
awk '{print NR ":" $0}' .github/workflows/docs.yml | sed -n '15,40p'

Repository: cuenca-mx/facturapi-python

Length of output: 1137


🌐 Web query:

mkdocs gh-deploy GITHUB_TOKEN contents write required

💡 Result:

When using mkdocs gh-deploy within a GitHub Actions workflow, the GITHUB_TOKEN requires write permissions to the repository's contents to successfully push the documentation to the deployment branch (typically gh-pages) [1][2]. By default, some GitHub Actions environments may have restricted permissions (read-only) [2]. To grant the necessary access, you must explicitly define the permissions in your workflow YAML file [2]. To fix "Permission denied" or 403 errors during deployment, add the following permissions block to your job configuration [2]: permissions: contents: write This allows the GITHUB_TOKEN to commit and push changes to the repository, which is required for mkdocs gh-deploy to update the documentation branch [1][2]. Additionally, ensure your repository settings allow GitHub Actions to have write access. You can check this by navigating to your repository's Settings > Actions > General > Workflow permissions and verifying that "Read and write permissions" is selected [3][2]. Relying on specific permissions within the workflow file is considered more secure than granting broad write access to all workflows in the repository settings [2].

Citations:


Docs deployment will fail because contents: read is set while mkdocs gh-deploy pushes to gh-pages.

Your workflow grants the default GITHUB_TOKEN read-only access (permissions: contents: read), but mkdocs gh-deploy --force needs permissions: contents: write to push commits to the deployment branch.

Suggested fix
permissions:
-  contents: read
+  contents: write
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
permissions:
contents: read
permissions:
contents: write
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/docs.yml around lines 3 - 4, The workflow currently sets
GitHub token permissions to "permissions: contents: read", which prevents mkdocs
gh-deploy --force from pushing to gh-pages; update the workflow's permissions
block so the contents permission is write (e.g., change "contents: read" to
"contents: write") to allow the deploy step to push commits.

Comment on lines +26 to +36
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: make install-test
- name: Run tests
run: pytest -x
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: make install-test
- name: Run tests
run: pytest -x
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1) Find non-SHA action refs in this workflow.
python - <<'PY'
import re
f = '.github/workflows/test.yml'
for i, line in enumerate(open(f), 1):
    m = re.search(r'uses:\s*([^@\s]+)@([^\s]+)', line)
    if m and not re.fullmatch(r'[0-9a-f]{40}', m.group(2)):
        print(f"{f}:{i}: unpinned -> {line.strip()}")
PY

# 2) Check whether checkout in pytest job sets persist-credentials.
rg -n -A5 -B3 'pytest:|uses:\s*actions/checkout|persist-credentials' .github/workflows/test.yml

Repository: cuenca-mx/facturapi-python

Length of output: 1545


Pin action SHAs and disable checkout credential persistence in the pytest job (matrix).

  • .github/workflows/test.yml uses actions/checkout@v4 and actions/setup-python@v5 by tag (not SHA).
  • The checkout step in the pytest job does not set with: persist-credentials: false.
Suggested fix
-      - uses: actions/checkout@v4
+      - uses: actions/checkout@<full_commit_sha_for_v4>
+        with:
+          persist-credentials: false
       - name: Set up Python ${{ matrix.python-version }}
-        uses: actions/setup-python@v5
+        uses: actions/setup-python@<full_commit_sha_for_v5>
🧰 Tools
🪛 zizmor (1.25.2)

[warning] 28-28: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)


[error] 28-28: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)


[error] 30-30: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/test.yml around lines 26 - 36, Update the pytest job steps
to pin GitHub Actions to specific commit SHAs and disable checkout credential
persistence: replace the actions/checkout@v4 reference with the corresponding
actions/checkout@<COMMIT_SHA> and replace actions/setup-python@v5 with
actions/setup-python@<COMMIT_SHA>, and in the checkout step add with:
persist-credentials: false; keep the step names ("Set up Python ${{
matrix.python-version }}", "Install dependencies", "Run tests") and matrix usage
unchanged so the job still runs across the python-version matrix.

@gmorales96 gmorales96 merged commit f9f01b5 into main Jun 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants