Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Fixes #10068.

This PR adds a --secrets-file parameter to the wrangler versions upload command, enabling users to upload secrets alongside their Worker code in a single atomic operation.

Key Changes

Command Interface:

  • Added --secrets-file parameter that accepts a path to a JSON or .env file
  • File format matches what's used by wrangler versions secret bulk command

Implementation:

  • Reuses existing parseBulkInputToObject function for file parsing
  • Creates rawBindings array with secret_text type bindings from parsed secrets
  • Sets keepSecrets: false and keepBindings: ["secret_key", "secret_text"] when secrets file is provided to inherit non-provided secrets

Usage Examples:

wrangler versions upload --secrets-file .env.production
wrangler versions upload --secrets-file secrets.json

Critical Review Areas

⚠️ Secret Inheritance Logic: The combination of keepSecrets: false + keepBindings: ["secret_key", "secret_text"] is critical - please verify this correctly inherits existing secrets not in the file while uploading new ones.

⚠️ API Contract: Confirm that using rawBindings with secret_text type is the correct way to upload secrets via the versions API.

⚠️ Test Accuracy: Tests mock API responses based on my understanding - please verify expectations match real API behavior.

Testing

  • Comprehensive unit tests covering JSON and .env file formats
  • Tests for secret inheritance behavior with and without secrets file
  • Error handling tests for missing/invalid files
  • All existing tests continue to pass

Link to Devin run: https://app.devin.ai/sessions/589ac34811cb43258f0107ed00840ed7
Requested by: @petebacondarwin


  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this is a new CLI parameter that will be documented via CLI help text and changeset
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: this is a new feature, not a patch fix

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link

changeset-bot bot commented Oct 7, 2025

🦋 Changeset detected

Latest commit: 3f78336

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Oct 7, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10896

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10896

miniflare

npm i https://pkg.pr.new/miniflare@10896

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10896

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10896

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10896

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10896

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10896

wrangler

npm i https://pkg.pr.new/wrangler@10896

commit: 3f78336

@devin-ai-integration devin-ai-integration bot marked this pull request as ready for review October 7, 2025 12:57
@devin-ai-integration devin-ai-integration bot requested a review from a team as a code owner October 7, 2025 12:57
}
: undefined,
logpush: undefined, // both logpush and observability are not supported in versions upload
logpush: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

no reason to remove this comment

Copy link
Contributor Author

Fixed! I've restored the comment in commit 710a08c.

The comment is now back on line 753:

logpush: undefined, // both logpush and observability are not supported in versions upload

All local tests pass. There are 2 macOS test failures in CI, but they appear to be unrelated flaky tests since my change only restored a comment.

Comment on lines 730 to 733
keepSecrets: props.secretsFile ? false : true,
keepBindings: props.secretsFile
? ["secret_key", "secret_text"]
: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this change is quite right. They cancel each other out.

When keepSecrets is true (i.e. here secretsFile is falsy) we automatically add secret_key and secret_text to the keep_bindings field in createWorkerUploadForm().

And here if secretsFile is truthy, then we are explicitly adding secret_key and secret_text.

If we are saying that secretsFile is the full source of truth for secrets then we should be setting keepSecrets to false and not setting keepBindings at all.

If we are saying that secretsFiles is additive to the current secrets in the dashboard then keepSecrets should always be true and keepBindings should not be defined.

From looking at how wrangler versions secret bulk works, we should not be treating the secetsFile as a source of truth but only additive. I think we should follow that here too.

So I think this should be:

Suggested change
keepSecrets: props.secretsFile ? false : true,
keepBindings: props.secretsFile
? ["secret_key", "secret_text"]
: undefined,
// we never delete secret bindings when uploading, even if we are setting secrets from a file
// so inherit all unchanged secrets from the previous Worker Version
keepSecrets: true,

- Set keepSecrets: true unconditionally (regardless of secretsFile)
- Remove keepBindings assignment when secretsFile is provided
- createWorkerUploadForm() automatically adds keep_bindings when keepSecrets is true
- Secrets from file are now additive to existing secrets (matching versions secret bulk behavior)
- Update tests to expect correct keep_bindings order: ['secret_text', 'secret_key']

Co-Authored-By: [email protected] <[email protected]>
Copy link
Contributor Author

Fixed! I've updated the logic to always set keepSecrets: true and removed the keepBindings assignment. The secrets file is now additive - secrets from the file are added/updated while existing secrets are inherited from the previous version, matching the behavior of wrangler versions secret bulk.

Changes in commit 93e74d6:

  • keepSecrets is now always true (line 731 in upload.ts)
  • Removed the conditional logic and keepBindings assignment
  • createWorkerUploadForm() automatically adds ["secret_text", "secret_key"] to keep_bindings when keepSecrets: true
  • Updated test expectations to match the correct binding order

This ensures that secrets not included in the file will be inherited from the previous version, making the secrets file truly additive.

devin-ai-integration bot and others added 2 commits October 7, 2025 19:04
- Add --secrets-file argument to deploy command options
- Parse secrets file and add to rawBindings in deploy implementation
- Set keepSecrets: true to inherit existing secrets (additive behavior)
- Add comprehensive unit tests for deploy with secrets file
- Update changeset to document both deploy and versions upload commands

Co-Authored-By: [email protected] <[email protected]>
- Set keepSecrets based on keepVars OR secretsFile (not unconditional)
- Remove incorrect test that expected keepSecrets=true by default
- Preserves backward compatibility while enabling --secrets-file feature

Co-Authored-By: [email protected] <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

Support Environment Variables/Secrets in wrangler versions upload
1 participant