diff --git a/action.yml b/action.yml index 0e82e33..b4a9315 100644 --- a/action.yml +++ b/action.yml @@ -62,7 +62,6 @@ runs: INPUT_FAIL_ON_FAILURES: ${{ inputs.fail_on_failures }} INPUT_COMMENT_PR: ${{ inputs.comment_pr }} INPUT_STEP_SUMMARY: ${{ inputs.step_summary }} - GITHUB_TOKEN: ${{ github.token }} outputs: json_path: diff --git a/entrypoint.sh b/entrypoint.sh index 79fafbe..cca8a26 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -71,21 +71,32 @@ if [ "${STEP_SUMMARY_ARG}" = "true" ] && [ -n "${GITHUB_STEP_SUMMARY:-}" ] && [ fi # Post PR comment if this is a PR and requested -if [ "${COMMENT_PR_ARG}" = "true" ] && [ -n "${MD_OUT_ARG}" ] && [ -f "${MD_OUT_ARG}" ]; then - PR_NUMBER="" - if [ -n "${GITHUB_EVENT_PATH:-}" ] && command -v jq >/dev/null 2>&1; then - PR_NUMBER="$(jq -r '.pull_request.number // empty' "$GITHUB_EVENT_PATH" || true)" - fi - if [ -n "${PR_NUMBER}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_TOKEN:-}" ]; then - BODY_CONTENT="$(cat "${MD_OUT_ARG}")" - curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -X POST "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \ - -d "$(printf '{"body": %s}' "$(jq -Rs . </dev/null 2>&1; then + PR_NUMBER="$(jq -r '.pull_request.number // empty' "$GITHUB_EVENT_PATH" || true)" + fi + if [ -z "${PR_NUMBER}" ]; then + echo "[slinky] Not a pull_request event or PR number not found; skipping PR comment." + elif [ -z "${GITHUB_TOKEN:-}" ]; then + echo "[slinky] GITHUB_TOKEN not available; ensure the workflow grants permissions and passes the token as env. Skipping PR comment." + elif [ -z "${GITHUB_REPOSITORY:-}" ]; then + echo "[slinky] GITHUB_REPOSITORY not set; skipping PR comment." + else + BODY_CONTENT="$(cat "${MD_OUT_ARG}")" + curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -X POST "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \ + -d "$(printf '{"body": %s}' "$(jq -Rs . </dev/null || true + echo "[slinky] Posted PR comment to #${PR_NUMBER}." + fi fi fi