Skip to content

Commit 2f2023d

Browse files
Dev Userclaude
andcommitted
fix(ci): use jq for JSON encoding in variable migration
Values with special characters (URLs, spaces) broke raw string interpolation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5f42d4c commit 2f2023d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

.github/workflows/migrate-secrets-to-vars.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,16 @@ jobs:
9292
continue
9393
fi
9494
95+
# Build JSON payloads with jq to handle special characters
96+
PATCH_BODY=$(jq -n --arg v "$VALUE" '{value: $v}')
97+
POST_BODY=$(jq -n --arg n "$VAR_NAME" --arg v "$VALUE" '{name: $n, value: $v}')
98+
9599
# Try update first (PATCH), fall back to create (POST)
96100
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH \
97101
"https://api.github.com/repos/${REPO}/actions/variables/${VAR_NAME}" \
98102
-H "Authorization: Bearer ${GH_TOKEN}" \
99103
-H "Accept: application/vnd.github+json" \
100-
-d "{\"value\":\"${VALUE}\"}")
104+
-d "$PATCH_BODY")
101105
102106
if [ "$HTTP_CODE" = "204" ]; then
103107
echo "UPDATED: $VAR_NAME"
@@ -107,7 +111,7 @@ jobs:
107111
"https://api.github.com/repos/${REPO}/actions/variables" \
108112
-H "Authorization: Bearer ${GH_TOKEN}" \
109113
-H "Accept: application/vnd.github+json" \
110-
-d "{\"name\":\"${VAR_NAME}\",\"value\":\"${VALUE}\"}")
114+
-d "$POST_BODY")
111115
112116
if [ "$HTTP_CODE" = "201" ]; then
113117
echo "CREATED: $VAR_NAME"

0 commit comments

Comments
 (0)