CLI Release creation needs to auto-truncate (or have an option to auto-truncate) automatically generated notes #63414
-
Select Topic AreaGeneral BodyWhen working with the Github CLI to create a release, there is an option to automatically generate release notes using the The Github GUI auto-truncates when generating release notes correctly, and manually editing release notes (or setting your own) works via CLI/API as well, but automated workflows are blocked from using auto-generated notes if the changeset is too big because there's no option to force the API to truncate. I'd like to get a discussion started about what it would take to update the relevant API endpoint to include an option to auto-truncate the generated notes. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
In case anyone else has this question, I resolved this problem by using the github api to generate the full release notes. I then trim the notes (by section) so that the entire note will fit in the 125,000 character limit. I then feed those notes into the Github CLI to create the release. // ./tools/scripts/generate-release-notes.js
const github = require('@actions/github');
/**
* Generates the release notes for a github release.
*
* Arguments:
* 1 - github_token
* 2 - new version
*/
const token = process.argv[2];
const version = process.argv[3];
async function main() {
const client = github.getOctokit(token);
const latestReleaseResponse = await client.request(
'GET /repos/{owner}/{repo}/releases/latest',
{
owner: 'my-org',
repo: 'my-repo',
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
}
);
const previousTag = latestReleaseResponse.data?.tag_name;
const response = await client.request(
'POST /repos/{owner}/{repo}/releases/generate-notes',
{
owner: 'my-org',
repo: 'my-repo',
tag_name: version,
previous_tag_name: previousTag,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
}
);
const noteSections = response.data.body?.split('\n\n');
const trimmedSections = [];
const githubNotesMaxCharLength = 125000;
const maxSectionLength = githubNotesMaxCharLength / noteSections.length;
for (let i = 0; i < noteSections.length; i++) {
if (noteSections[i].length > githubNotesMaxCharLength) {
const lastLineIndex =
noteSections[i].substring(0, maxSectionLength).split('\n').length - 1;
const trimmed =
noteSections[i]
.split('\n')
.slice(0, lastLineIndex - 1)
.join('\n') +
`\n... (+${
noteSections[i].split('\n').length - (lastLineIndex + 1)
} others)`;
trimmedSections.push(trimmed);
continue;
}
trimmedSections.push(noteSections[i]);
}
console.log(trimmedSections.join('\n\n'));
}
main().catch((e) => {
console.error(`Failed generating release notes with error: ${e}`);
process.exit(0);
});// release.yml
tag-branch:
name: Tag Branch
runs-on: [ubuntu-latest]
steps:
# Recover workspace
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install node modules
run: npm ci
# Start job-specific steps
- name: Save Build Number and Component Version
id: build_info
run: node tools/scripts/set_version_num.js // external script where I determine what the version number is
- name: Delete Existing Tag
uses: dev-drprasad/[email protected]
with:
delete_release: true
tag_name: '${{ steps.build_info.outputs.version }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag Branch with Build Number
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag "${{ steps.build_info.outputs.version }}"
git push origin --tags
- name: Generate Release Notes
id: generate-release-notes
run: |
node tools/scripts/generate-release-notes.js '${{ secrets.GITHUB_TOKEN }}' '${{ github.event.inputs.version }}' > notes.txt
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create "${{ steps.build_info.outputs.version }}" --repo "${{ github.repository }}" --title "${{ steps.build_info.outputs.version }}" --notes-file notes.txt |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
In case anyone else has this question, I resolved this problem by using the github api to generate the full release notes. I then trim the notes (by section) so that the entire note will fit in the 125,000 character limit. I then feed those notes into the Github CLI to create the release.