Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ jobs:
permissions:
contents: read
uses: ./.github/workflows/quality.yml
secrets:
HF_TOKEN_READ_PUBLIC_ONLY: ${{ secrets.HF_TOKEN_READ_PUBLIC_ONLY }}

2 changes: 2 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
permissions:
contents: read
uses: ./.github/workflows/quality.yml
secrets:
HF_TOKEN_READ_PUBLIC_ONLY: ${{ secrets.HF_TOKEN_READ_PUBLIC_ONLY }}
pre-release-check:
permissions:
contents: read
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Verify Code Quality

on:
workflow_call:
secrets:
HF_TOKEN_READ_PUBLIC_ONLY:
description: "Hugging Face Hub READ-ONLY token (public repos only) for authenticated model/dataset access during tests."
required: false

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref_name }}
Expand Down Expand Up @@ -29,6 +33,12 @@ jobs:
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
# The GitHub secret HF_TOKEN_READ_PUBLIC_ONLY must be a READ-ONLY token on public
# repositories: same-repo PR runs have access to this secret, so a write-scope
# token could be exfiltrated by a malicious workflow change. It is exposed as the
# env var HF_TOKEN (the name huggingface_hub picks up automatically) only on the
# specific steps that need it, to limit exposure to unrelated steps like the
# Ollama installer. Rotate via repo Settings -> Secrets and variables.
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
Expand All @@ -48,6 +58,33 @@ jobs:
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml', 'uv.lock') }}
- name: Install dependencies
run: uv sync --frozen --all-extras --group dev
- name: Check HF_TOKEN
continue-on-error: true
env:
# read-only public-repo HF token; environment gating not warranted
HF_TOKEN: ${{ secrets.HF_TOKEN_READ_PUBLIC_ONLY }} # zizmor: ignore[secrets-outside-env]
run: |
if [ -z "${HF_TOKEN:-}" ]; then
echo "::warning::HF_TOKEN is NOT set — Hugging Face Hub calls will be anonymous."
exit 0
fi
echo "HF_TOKEN is set; verifying with the Hugging Face Hub API..."
{
uv run python - <<'PY'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small thing: if uv run itself fails to start (corrupt venv, transient error), the step exits non-zero under bash -eo pipefail and blocks CI before tests even run — worse than the anonymous state this step is guarding against. One || makes it truly advisory:

Suggested change
uv run python - <<'PY'
uv run python - <<'PY' || echo "::warning::HF_TOKEN verification step could not run."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I had to modify the syntax to use an enclosure but have added it. I also added a flag to the step as well.

import os, sys
try:
from huggingface_hub import HfApi
except ImportError:
print("::warning::huggingface_hub not installed in this env; skipping HF_TOKEN verification.")
sys.exit(0)
try:
info = HfApi().whoami(token=os.environ["HF_TOKEN"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you probably know this, but just sharing that whoami does not eat into the rate limit

name = info.get("name") or info.get("fullname") or "<unknown>"
print(f"::notice::HF_TOKEN is valid (user: {name}).")
except Exception as e:
print(f"::warning::HF_TOKEN is set but verification failed — token may be invalid or expired: {e}")
PY
} || echo "::warning::HF_TOKEN verification step could not run."
- name: Check style and run tests
id: precommit
run: uv run pre-commit run --all-files
Expand All @@ -65,6 +102,9 @@ jobs:
ollama pull granite4.1:3b
- name: Run Tests
id: tests
env:
# read-only public-repo HF token; environment gating not warranted
HF_TOKEN: ${{ secrets.HF_TOKEN_READ_PUBLIC_ONLY }} # zizmor: ignore[secrets-outside-env]
run: uv run -m pytest -v --junit-xml=/tmp/pytest-results.xml test
- name: Send failure message tests
if: failure() # This step will only run if a previous step failed
Expand Down
Loading