@@ -75,30 +75,53 @@ runs:
7575 echo "GitHub Release $TAG is published and immutable with the expected assets; nothing to upload or publish"
7676 fi
7777 printf 'immutable=%s\n' "$immutable" >>"$GITHUB_OUTPUT"
78+ - name : 👋 Credit new contributors
79+ shell : bash
80+ env :
81+ GH_REPO : ${{ github.repository }}
82+ TAG : ${{ inputs.tag }}
83+ COMMIT : ${{ inputs.commit }}
84+ NOTES_FILE : ${{ inputs.notes-file }}
85+ run : |
86+ set -euo pipefail
87+ if jq -e '.[0].draft == false' "$RUNNER_TEMP/release-existing.json" >/dev/null; then
88+ echo "New Contributors skipped: GitHub Release $TAG is already published"
89+ cp "$NOTES_FILE" "$RUNNER_TEMP/release-body.md"
90+ exit 0
91+ fi
92+ # The comparison link that release-creator renders names the previous tag GitHub should count from.
93+ previous=$(grep -oP "/compare/\K[^)]+(?=\.\.\.\Q$TAG\E\))" "$NOTES_FILE" | head -n 1 || true)
94+ request=(-f "tag_name=$TAG" -f "target_commitish=$COMMIT")
95+ if [[ -n "$previous" ]]; then
96+ request+=(-f "previous_tag_name=$previous")
97+ fi
98+ echo "Generated notes range: ${previous:-first release}...$TAG"
99+ gh api -X POST "repos/$GH_REPO/releases/generate-notes" "${request[@]}" --jq .body >"$RUNNER_TEMP/generated-notes.md"
100+ python3 "$GITHUB_ACTION_PATH/../tools/new_contributors.py" \
101+ "$NOTES_FILE" "$RUNNER_TEMP/generated-notes.md" "$RUNNER_TEMP/release-body.md"
78102 - name : 🚀 Create or update the draft
79103 shell : bash
80104 env :
81105 GH_REPO : ${{ github.repository }}
82106 TAG : ${{ inputs.tag }}
83107 COMMIT : ${{ inputs.commit }}
84108 TITLE : ${{ inputs.title }}
85- NOTES_FILE : ${{ inputs.notes-file }}
86109 PRERELEASE : ${{ inputs.prerelease }}
87110 run : |
88111 set -euo pipefail
89112 if jq -e 'length == 0' "$RUNNER_TEMP/release-existing.json" >/dev/null; then
90113 jq -n --arg tag "$TAG" --arg commit "$COMMIT" --arg title "$TITLE" \
91- --rawfile body "$NOTES_FILE " --argjson prerelease "$PRERELEASE" \
114+ --rawfile body "$RUNNER_TEMP/release-body.md " --argjson prerelease "$PRERELEASE" \
92115 '{tag_name: $tag, target_commitish: $commit, name: $title, body: $body,
93116 draft: true, prerelease: $prerelease}' >"$RUNNER_TEMP/release-request.json"
94117 gh api -X POST "repos/$GH_REPO/releases" --input "$RUNNER_TEMP/release-request.json" \
95118 >"$RUNNER_TEMP/release-created.json"
96119 jq -er '.id | select(type == "number")' "$RUNNER_TEMP/release-created.json" >"$RUNNER_TEMP/release-id"
97120 echo "GitHub Release $TAG: created draft $(<"$RUNNER_TEMP/release-id") for $COMMIT (prerelease $PRERELEASE)"
98- elif jq -e --arg title "$TITLE" --rawfile body "$NOTES_FILE " --argjson prerelease "$PRERELEASE" \
121+ elif jq -e --arg title "$TITLE" --rawfile body "$RUNNER_TEMP/release-body.md " --argjson prerelease "$PRERELEASE" \
99122 '.[0].draft and (.[0].name != $title or .[0].body != $body or .[0].prerelease != $prerelease)' \
100123 "$RUNNER_TEMP/release-existing.json" >/dev/null; then
101- jq -n --arg title "$TITLE" --rawfile body "$NOTES_FILE " --argjson prerelease "$PRERELEASE" \
124+ jq -n --arg title "$TITLE" --rawfile body "$RUNNER_TEMP/release-body.md " --argjson prerelease "$PRERELEASE" \
102125 '{name: $title, body: $body, prerelease: $prerelease}' >"$RUNNER_TEMP/release-update.json"
103126 gh api -X PATCH "repos/$GH_REPO/releases/$(<"$RUNNER_TEMP/release-id")" \
104127 --input "$RUNNER_TEMP/release-update.json" \
0 commit comments