Skip to content

Commit 37bc7b5

Browse files
committed
try 10: shieh
1 parent e572584 commit 37bc7b5

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

.github/workflows/circleci-failure-summary-comment.yml

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,39 +162,34 @@ jobs:
162162
- name: Post comment with helper link
163163
env:
164164
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165-
GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
166-
github_repository: ${{ github.repository }}
167-
pr_number: ${{ github.event.pull_request.number }}
168-
pr_sha: ${{ github.event.pull_request.head.sha }}
165+
GITHUB_REPOSITORY: ${{ github.repository }}
166+
PR_NUMBER: ${{ github.event.pull_request.number }}
167+
PR_SHA: ${{ github.event.pull_request.head.sha }}
169168
run: |
170-
if [ ! -f outputs/failure_summary.json ]; then
169+
COMMIT_SHORT="${PR_SHA:0:12}"
170+
SUMMARY_FILE="pr-${PR_NUMBER}/sha-${COMMIT_SHORT}/failure_summary.json"
171+
172+
if [ ! -f "$SUMMARY_FILE" ]; then
171173
echo "failure_summary.json missing, skipping comment."
172174
exit 0
173175
fi
174-
failures=$(python -c "import json; print(len(json.load(open('outputs/failure_summary.json'))['failures']))")
176+
177+
failures=$(jq '.failures | length' "$SUMMARY_FILE")
175178
if [ "$failures" -eq 0 ]; then
176179
echo "No failures detected, skipping PR comment."
177180
exit 0
178181
fi
179-
SPACE_SLUG="transformers-community/circleci-test-collection-helper"
180-
SPACE_BASE="https://huggingface.co/spaces/${SPACE_SLUG}"
181-
repo_enc=$(jq -rn --arg v "${github_repository}" '$v|@uri')
182-
pr_enc=$(jq -rn --arg v "${pr_number}" '$v|@uri')
183-
sha_enc=$(jq -rn --arg v "${pr_sha}" '$v|@uri')
184-
parts=()
185-
[ -n "${repo_enc}" ] && parts+=("repo=${repo_enc}")
186-
[ -n "${pr_enc}" ] && parts+=("pr=${pr_enc}")
187-
[ -n "${sha_enc}" ] && parts+=("sha=${sha_enc}")
188-
QUERY=$(IFS="&"; echo "${parts[*]}")
189-
if [ -n "$QUERY" ]; then
190-
SPACE_URL="${SPACE_BASE}?${QUERY}"
191-
else
192-
SPACE_URL="${SPACE_BASE}"
193-
fi
194-
body="View the CircleCI test collection helper for this PR:\n\n${SPACE_URL}"
182+
183+
# Build Space URL with encoded parameters
184+
repo_enc=$(jq -rn --arg v "$GITHUB_REPOSITORY" '$v|@uri')
185+
pr_enc=$(jq -rn --arg v "$PR_NUMBER" '$v|@uri')
186+
sha_enc=$(jq -rn --arg v "$PR_SHA" '$v|@uri')
187+
SPACE_URL="https://huggingface.co/spaces/transformers-community/circleci-test-collection-helper?repo=${repo_enc}&pr=${pr_enc}&sha=${sha_enc}"
188+
189+
# Post comment (using printf for proper newlines)
195190
gh api \
196191
--method POST \
197192
-H "Accept: application/vnd.github+json" \
198193
-H "X-GitHub-Api-Version: 2022-11-28" \
199-
"repos/${github_repository}/issues/${pr_number}/comments" \
200-
-f body="$body"
194+
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
195+
-f body="$(printf "View the CircleCI test collection helper for this PR:\n\n%s" "$SPACE_URL")"

0 commit comments

Comments
 (0)