A minimal demo of publishing to the Hugging Face Hub from GitHub Actions without storing an HF_TOKEN secret, using Trusted Publishers.
- GitHub repo:
coyotte508/publish-to-hf - Target Hub repo:
coyotte508/published-from-github
- On push to
main, thepublish.ymlworkflow runshf uploadwith theHF_OIDC_RESOURCEenvironment variable set to the target repo. - The
hfCLI detects it's running on GitHub Actions, requests a short-lived OIDC ID token from GitHub, and exchanges it athttps://huggingface.co/oauth/tokenfor a short-lived Hub token scoped tocoyotte508/published-from-github— all automatically. - The contents of
model/are uploaded to the Hub repo.
No HF_TOKEN secret is stored anywhere in this repo or in GitHub.
To reproduce this for your own repo:
- Create the target Hub repo, e.g.
your-name/published-from-github. - On that repo's Settings → Trusted Publishers, add a publisher with:
- Provider: GitHub Actions
- Claims:
repository=your-gh-name/publish-to-hfbranch=mainworkflow=publish.yml
- Edit
publish.ymland replacecoyotte508/published-from-githubwith your target repo (in bothHF_OIDC_RESOURCEand thehf uploadcommand). - Push to
main(or trigger the workflow manually) — done.
- Push any change to
main, or - Run the workflow from GitHub's Actions tab via Run workflow (
workflow_dispatch).
.
├── .github/workflows/publish.yml # The CI workflow
├── model/ # What gets uploaded to the Hub
│ └── README.md # Becomes the model card
└── README.md # You are here