You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
echo "::error::Token exchange failed with HTTP $STATUS (x-request-id: ${REQUEST_ID:-unknown})"
88
-
cat "$BODY"
89
-
exit 1
90
-
fi
91
-
92
-
HF_TOKEN=$(jq -r .access_token "$BODY")
93
-
echo "::add-mask::$HF_TOKEN"
94
-
# Safe way to write to env
95
-
DELIM="EOF_$(openssl rand -hex 16)"
96
-
{
97
-
echo "HF_TOKEN<<$DELIM"
98
-
echo "$HF_TOKEN"
99
-
echo "$DELIM"
100
-
} >> "$GITHUB_ENV"
101
-
102
-
- name: Upload checkpoint
103
-
run: |
104
-
hf upload acme/awesome-model ./checkpoint . \
105
-
--commit-message "Publish from ${GITHUB_SHA::7}"
65
+
HF_OIDC_RESOURCE: acme/awesome-model
66
+
run: hf upload acme/awesome-model ./checkpoint . --commit-message "Publish from ${GITHUB_SHA::7}"
106
67
```
107
68
108
-
That's it — `huggingface_hub` picks up `HF_TOKEN` from the environment.
69
+
That's it. On GitHub Actions, the `hf` CLI (`huggingface_hub>=1.19.0`) detects the provider, performs the exchange, and uses the resulting token automatically. You only set `HF_OIDC_RESOURCE`.
70
+
71
+
> [!TIP]
72
+
> Publishing to several repos in one run (e.g. a model **and** a dataset)? Set `HF_OIDC_RESOURCE` per step so each token is scoped to the repo that step pushes to.
73
+
74
+
#### Other CI providers
75
+
76
+
The `hf` CLI mints the ID token natively on GitHub Actions only for now. On GitLab, CircleCI, Bitbucket, or any other provider, mint the ID token yourself (see [Supported CI providers](#supported-ci-providers)) and pass it via `HF_OIDC_ID_TOKEN` — the CLI exchanges it directly:
@@ -123,19 +103,22 @@ Both tokens expire after 60 minutes. You need the **Write** role on a Hub repo t
123
103
124
104
### Accessing gated repos from CI
125
105
126
-
If you only need to *read* gated repos (e.g. download a model from a job), configure a publisher on your account under [**Authentication settings → CI/CD Access**](https://huggingface.co/settings/authentication#ci-cd-access) instead of on a specific repo, then pass your **username** as `resource`:
106
+
If you only need to *read* gated repos (e.g. download a model from a job), configure a publisher on your account under [**Authentication settings → CI/CD Access**](https://huggingface.co/settings/authentication#ci-cd-access) instead of on a specific repo, then use your **username** as the resource.
107
+
108
+
On **GitHub Actions**, the `hf` CLI does the exchange for you, just set `HF_OIDC_RESOURCE`:
109
+
110
+
```yaml
111
+
- name: Download a gated model
112
+
env:
113
+
HF_OIDC_RESOURCE: your-hf-username
114
+
run: hf download acme/gated-model
115
+
```
116
+
117
+
On **other providers**, mint the ID token yourself (see [Other CI providers](#other-ci-providers)) and pass it via `HF_OIDC_ID_TOKEN`:
127
118
128
119
```bash
129
-
HF_TOKEN=$(curl -sSf -X POST "https://huggingface.co/oauth/token" \
130
-
-H "Content-Type: application/json" \
131
-
-d "$(jq -n --arg t "$ID_TOKEN" --arg r "your-hf-username" \
The resulting token can read gated repos you have access to and uses your account's rate limits. It **cannot** write anything, and **cannot** read your private repos.
0 commit comments