Skip to content

Commit fd8988e

Browse files
etchalonclaude
andcommitted
fix: Use wrangler secret put instead of bulk for idempotent updates
wrangler secret bulk fails if a secret already exists. Using individual wrangler secret put calls handles both create and update. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3b81200 commit fd8988e

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

action.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -438,26 +438,18 @@ runs:
438438
')
439439
fi
440440
441-
# Filter out secrets that conflict with vars
442-
FILTERED=$(echo "$SECRETS_JSON" | VAR_NAMES="$VAR_NAMES" node --eval '
441+
# Filter out secrets that conflict with vars, then upload each individually
442+
echo "$SECRETS_JSON" | VAR_NAMES="$VAR_NAMES" node --eval '
443443
const secrets = JSON.parse(require("fs").readFileSync("/dev/stdin", "utf8"));
444444
const varNames = new Set(JSON.parse(process.env.VAR_NAMES));
445-
const filtered = {};
446445
for (const [k, v] of Object.entries(secrets)) {
447446
if (varNames.has(k)) {
448447
console.error(`Skipping secret "${k}" - already defined as a var in wrangler config`);
449448
} else {
450-
filtered[k] = v;
449+
console.log(`${k}\t${v}`);
451450
}
452451
}
453-
console.log(JSON.stringify(filtered));
454-
')
455-
456-
if [ "$FILTERED" == "{}" ]; then
457-
echo "No secrets to upload (all filtered as var conflicts)"
458-
exit 0
459-
fi
460-
461-
echo "$FILTERED" > /tmp/worker-secrets.json
462-
npx wrangler secret bulk /tmp/worker-secrets.json --name "${{ inputs.worker-name }}"
463-
rm -f /tmp/worker-secrets.json
452+
' | while IFS=$'\t' read -r KEY VALUE; do
453+
echo "Uploading secret: $KEY"
454+
echo "$VALUE" | npx wrangler secret put "$KEY" --name "${{ inputs.worker-name }}"
455+
done

0 commit comments

Comments
 (0)