Skip to content

Commit 825dd80

Browse files
committed
fix(ci): handle string encoding in cleanup workflow
Set result-encoding to string for action output and strip surrounding quotes from JSON values before jq parsing to handle stringified JSON responses.
1 parent a2b83c1 commit 825dd80

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

.github/workflows/cleanup-ghcr-images.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ jobs:
183183
DRY_RUN: ${{ env.DRY_RUN }}
184184
DELETED_VERSION_IDS: ${{ steps.cleanup_by_age.outputs.result }}
185185
with:
186+
result-encoding: string
186187
script: |
187188
const owner = context.repo.owner;
188189
const packageType = 'container';
@@ -317,10 +318,10 @@ jobs:
317318
echo "" >> $GITHUB_STEP_SUMMARY
318319
319320
if [ -n "$SHA_ONLY_RESULT" ] && [ "$SHA_ONLY_RESULT" != "null" ]; then
320-
AGE_DELETED=$(echo "$AGE_BASED_RESULT" | jq -r 'if type == "array" then length elif type == "object" then .ageBasedDeleted // 0 else 0 end')
321-
SHA_DELETED=$(echo "$SHA_ONLY_RESULT" | jq '.shaOnlyDeleted // 0')
322-
TOTAL_BEFORE=$(echo "$SHA_ONLY_RESULT" | jq '.totalBefore // 0')
323-
REMAINING=$(echo "$SHA_ONLY_RESULT" | jq '.remaining // 0')
321+
AGE_DELETED=$(echo "$AGE_BASED_RESULT" | sed 's/^"//;s/"$//' | jq -r 'if type == "array" then length elif type == "object" then .ageBasedDeleted // 0 else 0 end')
322+
SHA_DELETED=$(echo "$SHA_ONLY_RESULT" | sed 's/^"//;s/"$//' | jq '.shaOnlyDeleted // 0')
323+
TOTAL_BEFORE=$(echo "$SHA_ONLY_RESULT" | sed 's/^"//;s/"$//' | jq '.totalBefore // 0')
324+
REMAINING=$(echo "$SHA_ONLY_RESULT" | sed 's/^"//;s/"$//' | jq '.remaining // 0')
324325
325326
echo "### Summary" >> $GITHUB_STEP_SUMMARY
326327
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
@@ -330,7 +331,7 @@ jobs:
330331
echo "| SHA-only deletions | ${SHA_DELETED} |" >> $GITHUB_STEP_SUMMARY
331332
echo "| **Remaining versions** | **${REMAINING}** |" >> $GITHUB_STEP_SUMMARY
332333
elif [ -n "$AGE_BASED_RESULT" ] && [ "$AGE_BASED_RESULT" != "null" ]; then
333-
AGE_DELETED=$(echo "$AGE_BASED_RESULT" | jq -r 'if type == "array" then length else 0 end')
334+
AGE_DELETED=$(echo "$AGE_BASED_RESULT" | sed 's/^"//;s/"$//' | jq -r 'if type == "array" then length else 0 end')
334335
echo "### Summary" >> $GITHUB_STEP_SUMMARY
335336
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
336337
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)