Skip to content

Commit 6f53f73

Browse files
committed
fix: enhance error handling and output parsing in deploy workflow for KV namespace management
1 parent e00b392 commit 6f53f73

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

.github/workflows/deploy.yml

+15-5
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,26 @@ jobs:
3030
run: |
3131
KV_NAMESPACE="SUBLINK_KV"
3232
echo "Checking for KV namespace: $KV_NAMESPACE"
33-
LIST_OUTPUT=$(wrangler kv namespace list)
34-
echo "KV namespace list output: $LIST_OUTPUT"
33+
if ! LIST_OUTPUT=$(wrangler kv namespace list 2>&1); then
34+
echo "Error getting KV namespace list: $LIST_OUTPUT"
35+
exit 1
36+
fi
37+
38+
LIST_OUTPUT=$(echo "$LIST_OUTPUT" | grep -v "Cloudflare collects" | grep -v "telemetry")
39+
echo "Cleaned KV namespace list output: $LIST_OUTPUT"
40+
41+
if ! echo "$LIST_OUTPUT" | jq empty; then
42+
echo "Invalid JSON output from wrangler"
43+
exit 1
44+
fi
3545
3646
KV_ID=$(echo "$LIST_OUTPUT" | jq -r '.[] | select(.title == "sublink-worker-'$KV_NAMESPACE'") | .id')
3747
3848
if [ -z "$KV_ID" ]; then
3949
echo "KV namespace $KV_NAMESPACE does not exist. Creating..."
40-
CREATE_OUTPUT=$(wrangler kv namespace create "$KV_NAMESPACE")
50+
CREATE_OUTPUT=$(wrangler kv namespace create "$KV_NAMESPACE" 2>&1)
4151
echo "Create KV namespace output: $CREATE_OUTPUT"
42-
KV_ID=$(echo "$CREATE_OUTPUT" | grep -oP 'id = "\K[^"]+')
52+
KV_ID=$(echo "$CREATE_OUTPUT" | grep -o '[0-9a-f]\{32\}')
4353
4454
if [ -z "$KV_ID" ]; then
4555
echo "Failed to extract KV ID. Full output: $CREATE_OUTPUT"
@@ -48,7 +58,7 @@ jobs:
4858
4959
echo "KV namespace $KV_NAMESPACE created successfully with ID: $KV_ID"
5060
else
51-
echo "KV namespace $KV_NAMESPACE already exists with ID: $KV_ID"
61+
echo "KV namespace $KV_NAMESPACE already exists with ID: $KV_ID"
5262
fi
5363
echo "KV_ID=$KV_ID" >> $GITHUB_ENV
5464

0 commit comments

Comments
 (0)