-
Notifications
You must be signed in to change notification settings - Fork 121
chore: add HF_TOKEN for authentication #1202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jakelorocco
merged 2 commits into
generative-computing:main
from
jakelorocco:chore/update-hf-token
Jun 5, 2026
+44
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 }} | ||
|
|
@@ -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: | ||
|
|
@@ -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' | ||
| 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"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing: if
uv runitself fails to start (corrupt venv, transient error), the step exits non-zero underbash -eo pipefailand blocks CI before tests even run — worse than the anonymous state this step is guarding against. One||makes it truly advisory:There was a problem hiding this comment.
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.