Skip to content

Commit edd63c2

Browse files
danielkovclaude
andcommitted
feat: add PyPI trusted publishing support
Add `useTrustedPublishing` field to PyPi publishing config to enable OIDC-based trusted publishing instead of token-based authentication. Changes: - Add `UseTrustedPublishing` field to `PyPi` struct - Make `Token` field optional when using trusted publishing - Update `Validate()` to error if both token and trusted publishing are set - Update `IsPublished()` to recognize trusted publishing as valid config - Update JSON schema with new field and descriptions Usage: ```yaml targets: python-sdk: target: python source: my-source publish: pypi: useTrustedPublishing: true ``` Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2adb2f8 commit edd63c2

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

schemas/workflow.schema.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,17 @@
326326
"additionalProperties": false,
327327
"properties": {
328328
"token": {
329+
"description": "PyPI API token for token-based authentication. Not required if using trusted publishing.",
329330
"type": "string"
331+
},
332+
"useTrustedPublishing": {
333+
"description": "Use OIDC trusted publishing instead of token-based authentication. See https://docs.pypi.org/trusted-publishers/",
334+
"type": [
335+
"null",
336+
"boolean"
337+
]
330338
}
331339
},
332-
"required": [
333-
"token"
334-
],
335340
"type": "object"
336341
},
337342
"WorkflowRubyGems": {

workflow/target.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ type NPM struct {
9090
}
9191

9292
type PyPi struct {
93-
_ struct{} `additionalProperties:"false"`
94-
Token string `yaml:"token" required:"true"`
93+
_ struct{} `additionalProperties:"false"`
94+
Token string `yaml:"token,omitempty" description:"PyPI API token for token-based authentication. Not required if using trusted publishing."`
95+
UseTrustedPublishing *bool `yaml:"useTrustedPublishing,omitempty" description:"Use OIDC trusted publishing instead of token-based authentication. See https://docs.pypi.org/trusted-publishers/"`
9596
}
9697

9798
type Packagist struct {
@@ -195,9 +196,15 @@ func (p Publishing) Validate(target string) error {
195196
}
196197
}
197198
case "python":
198-
if p.PyPi != nil && p.PyPi.Token != "" {
199-
if err := validateSecret(p.PyPi.Token); err != nil {
200-
return fmt.Errorf("failed to validate pypi token: %w", err)
199+
if p.PyPi != nil {
200+
usesTrustedPublishing := p.PyPi.UseTrustedPublishing != nil && *p.PyPi.UseTrustedPublishing
201+
if usesTrustedPublishing && p.PyPi.Token != "" {
202+
return fmt.Errorf("pypi token should not be provided when using trusted publishing")
203+
}
204+
if !usesTrustedPublishing && p.PyPi.Token != "" {
205+
if err := validateSecret(p.PyPi.Token); err != nil {
206+
return fmt.Errorf("failed to validate pypi token: %w", err)
207+
}
201208
}
202209
}
203210
case "php":
@@ -262,8 +269,11 @@ func (p Publishing) IsPublished(target string) bool {
262269
return true
263270
}
264271
case "python":
265-
if p.PyPi != nil && p.PyPi.Token != "" {
266-
return true
272+
if p.PyPi != nil {
273+
usesTrustedPublishing := p.PyPi.UseTrustedPublishing != nil && *p.PyPi.UseTrustedPublishing
274+
if usesTrustedPublishing || p.PyPi.Token != "" {
275+
return true
276+
}
267277
}
268278
case "php":
269279
if p.Packagist != nil {

0 commit comments

Comments
 (0)