Skip to content

Commit 242ff1d

Browse files
committed
ci: handle enormous initial changelog
1 parent 0e8f84f commit 242ff1d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

.github/workflows/release-pr.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,22 @@ jobs:
111111
BODY="${BODY}> - Create a \`v${NEXT_VERSION}\` tag and GitHub Release\n"
112112
BODY="${BODY}> - Publish \`npmx-connector@${NEXT_VERSION}\` to npm"
113113
114-
# Write body to file to avoid shell escaping issues
114+
# Write body to file, truncating if needed (GitHub limits PR body to 65536 chars)
115115
echo -e "$BODY" > /tmp/pr-body.md
116+
if [ "$(wc -c < /tmp/pr-body.md)" -gt 60000 ]; then
117+
COMMIT_COUNT=$(git log "$FROM_REF"..origin/main --oneline --no-merges | wc -l)
118+
COMPARE_URL="https://github.com/npmx-dev/npmx.dev/compare/${FROM_REF}...main"
119+
TRUNCATED="This PR will deploy the following changes to production (\`npmx.dev\`).\n\n"
120+
TRUNCATED="${TRUNCATED}**Next version: \`v${NEXT_VERSION}\`** (current: \`v${CURRENT_VERSION}\`)\n\n"
121+
TRUNCATED="${TRUNCATED}> **${COMMIT_COUNT} commits** are included in this release. The full changelog is too large to display here.\n>\n"
122+
TRUNCATED="${TRUNCATED}> [View full diff on GitHub](${COMPARE_URL})\n\n"
123+
TRUNCATED="${TRUNCATED}---\n\n"
124+
TRUNCATED="${TRUNCATED}> Merging this PR will:\n"
125+
TRUNCATED="${TRUNCATED}> - Deploy to \`npmx.dev\` via Vercel\n"
126+
TRUNCATED="${TRUNCATED}> - Create a \`v${NEXT_VERSION}\` tag and GitHub Release\n"
127+
TRUNCATED="${TRUNCATED}> - Publish \`npmx-connector@${NEXT_VERSION}\` to npm"
128+
echo -e "$TRUNCATED" > /tmp/pr-body.md
129+
fi
116130
117131
- name: 🚀 Create or update release PR
118132
if: steps.check.outputs.skip == 'false'

scripts/release-notes.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { $fetch } from 'ofetch'
1515
import { getGitDiff, loadChangelogConfig, parseCommits, generateMarkDown } from 'changelogen'
1616

1717
const REPO = 'npmx-dev/npmx.dev'
18+
const MAX_RELEASE_BODY_LENGTH = 120_000
19+
const MAX_CONTRIBUTOR_LOOKUPS = 100
1820

1921
interface Contributor {
2022
name: string
@@ -29,7 +31,9 @@ async function resolveContributors(
2931
const seenUsernames = new Set<string>()
3032
const token = process.env.GITHUB_TOKEN
3133

34+
let lookups = 0
3235
for (const commit of rawCommits) {
36+
if (lookups >= MAX_CONTRIBUTOR_LOOKUPS) break
3337
if (
3438
seenEmails.has(commit.author.email) ||
3539
commit.author.name.endsWith('[bot]') ||
@@ -38,6 +42,7 @@ async function resolveContributors(
3842
continue
3943
}
4044
seenEmails.add(commit.author.email)
45+
lookups++
4146

4247
try {
4348
const data = await $fetch<{ author: { login: string } | null }>(
@@ -86,10 +91,22 @@ async function main() {
8691

8792
if (contributors.length > 0) {
8893
const lines = contributors.map(c => `- ${c.name} (@${c.username})`).join('\n')
89-
9094
output += `\n\n### ❤️ Contributors\n\n${lines}`
9195
}
9296

97+
// Truncate if too long for GitHub Release body (125K limit)
98+
if (output.length > MAX_RELEASE_BODY_LENGTH) {
99+
const compareUrl = `https://github.com/${REPO}/compare/${from}...${to === 'HEAD' ? 'release' : to}`
100+
output =
101+
`> This release includes ${rawCommits.length} commits. The full changelog is too large to display here.\n>\n` +
102+
`> [View full diff on GitHub](${compareUrl})\n`
103+
104+
if (contributors.length > 0) {
105+
const lines = contributors.map(c => `- ${c.name} (@${c.username})`).join('\n')
106+
output += `\n### ❤️ Contributors\n\n${lines}`
107+
}
108+
}
109+
93110
console.log(output)
94111
}
95112

0 commit comments

Comments
 (0)