Skip to content

Commit 5049269

Browse files
authored
Refactor release preparation workflow and add automated changelog update script (#102)
1 parent ac14948 commit 5049269

2 files changed

Lines changed: 63 additions & 60 deletions

File tree

.github/workflows/prepare-release.yaml

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -147,42 +147,7 @@ jobs:
147147
NEW_VERSION="${{ steps.calc-version.outputs.new_version }}"
148148
CHANGELOG_FILE="${{ steps.changelog-diff.outputs.changelog_file }}"
149149
RELEASE_DATE=$(date +%Y-%m-%d)
150-
151-
# Read the changelog content
152-
CHANGELOG_CONTENT=$(cat "$CHANGELOG_FILE")
153-
154-
# Create new changelog section
155-
NEW_SECTION="## v${NEW_VERSION} (${RELEASE_DATE})
156-
157-
### Changes
158-
159-
${CHANGELOG_CONTENT}
160-
"
161-
162-
# Insert new section after "## Upcoming" section
163-
node -e "
164-
const fs = require('fs');
165-
let content = fs.readFileSync('CHANGELOG.md', 'utf8');
166-
167-
const newSection = \`$NEW_SECTION\`;
168-
169-
// Find the Upcoming section and insert after it
170-
const upcomingMatch = content.match(/## Upcoming[\s\S]*?(?=\n## v|$)/);
171-
if (upcomingMatch) {
172-
const upcomingEnd = content.indexOf(upcomingMatch[0]) + upcomingMatch[0].length;
173-
content = content.slice(0, upcomingEnd) + '\n' + newSection + content.slice(upcomingEnd);
174-
} else {
175-
// No Upcoming section, prepend
176-
content = '## Upcoming\n\n' + newSection + content;
177-
}
178-
179-
// Reset the Upcoming section to empty
180-
content = content.replace(/## Upcoming[\s\S]*?(?=\n## v)/, '## Upcoming\n\n### New\n\n### Fixes\n\n');
181-
182-
fs.writeFileSync('CHANGELOG.md', content);
183-
"
184-
185-
echo "Updated CHANGELOG.md"
150+
node scripts/update-changelog.js "$NEW_VERSION" "$RELEASE_DATE" "$CHANGELOG_FILE"
186151
187152
- name: Create release branch and commit
188153
id: create-branch
@@ -215,36 +180,37 @@ ${CHANGELOG_CONTENT}
215180
- name: Create Pull Request
216181
env:
217182
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
183+
NEW_VERSION: ${{ steps.calc-version.outputs.new_version }}
184+
BRANCH_NAME: ${{ steps.create-branch.outputs.branch_name }}
185+
CHANGELOG_FILE: ${{ steps.changelog-diff.outputs.changelog_file }}
218186
run: |
219-
NEW_VERSION="${{ steps.calc-version.outputs.new_version }}"
220-
BRANCH_NAME="${{ steps.create-branch.outputs.branch_name }}"
221-
CHANGELOG_FILE="${{ steps.changelog-diff.outputs.changelog_file }}"
222-
223187
CHANGELOG_CONTENT=$(cat "$CHANGELOG_FILE")
224188
225-
PR_BODY="## Release v${NEW_VERSION}
226-
227-
This PR prepares the release of version **${NEW_VERSION}** for all packages.
228-
229-
### Packages Updated
230-
- \`@microsoft/durabletask-js@${NEW_VERSION}\`
231-
- \`@microsoft/durabletask-js-azuremanaged@${NEW_VERSION}\`
232-
233-
### Changes Since Last Release
234-
${CHANGELOG_CONTENT}
235-
236-
### Release Checklist
237-
- [ ] Review version bumps in package.json files
238-
- [ ] Review CHANGELOG.md updates
239-
- [ ] Verify CI passes
240-
- [ ] Merge this PR
241-
- [ ] After merge, the official build pipeline will produce signed artifacts
242-
- [ ] Download artifacts and publish to npm with appropriate tag
243-
"
189+
# Write PR body to a temp file to avoid YAML escaping issues
190+
cat > /tmp/pr_body.md << EOF
191+
## Release v${NEW_VERSION}
192+
193+
This PR prepares the release of version **${NEW_VERSION}** for all packages.
194+
195+
**Packages Updated:**
196+
- @microsoft/durabletask-js@${NEW_VERSION}
197+
- @microsoft/durabletask-js-azuremanaged@${NEW_VERSION}
198+
199+
**Changes Since Last Release:**
200+
${CHANGELOG_CONTENT}
201+
202+
**Release Checklist:**
203+
- [ ] Review version bumps in package.json files
204+
- [ ] Review CHANGELOG.md updates
205+
- [ ] Verify CI passes
206+
- [ ] Merge this PR
207+
- [ ] After merge, the official build pipeline will produce signed artifacts
208+
- [ ] Download artifacts and publish to npm with appropriate tag
209+
EOF
244210
245211
gh pr create \
246212
--title "Release v${NEW_VERSION}" \
247-
--body "$PR_BODY" \
213+
--body-file /tmp/pr_body.md \
248214
--base main \
249215
--head "$BRANCH_NAME" \
250216
--label "release"

scripts/update-changelog.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env node
2+
// This script updates CHANGELOG.md with a new release section
3+
// Usage: node update-changelog.js <version> <date> <changelog-file>
4+
5+
const fs = require('fs');
6+
7+
const [,, version, releaseDate, changelogFile] = process.argv;
8+
9+
if (!version || !releaseDate || !changelogFile) {
10+
console.error('Usage: node update-changelog.js <version> <date> <changelog-file>');
11+
process.exit(1);
12+
}
13+
14+
const changelogContent = fs.readFileSync(changelogFile, 'utf8').trim();
15+
let content = fs.readFileSync('CHANGELOG.md', 'utf8');
16+
17+
const newSection = `## v${version} (${releaseDate})
18+
19+
### Changes
20+
21+
${changelogContent}
22+
`;
23+
24+
// Find the Upcoming section and insert after it
25+
const upcomingMatch = content.match(/## Upcoming[\s\S]*?(?=\n## v|$)/);
26+
if (upcomingMatch) {
27+
const upcomingEnd = content.indexOf(upcomingMatch[0]) + upcomingMatch[0].length;
28+
content = content.slice(0, upcomingEnd) + '\n' + newSection + content.slice(upcomingEnd);
29+
} else {
30+
content = '## Upcoming\n\n' + newSection + content;
31+
}
32+
33+
// Reset the Upcoming section to empty
34+
content = content.replace(/## Upcoming[\s\S]*?(?=\n## v)/, '## Upcoming\n\n### New\n\n### Fixes\n\n');
35+
36+
fs.writeFileSync('CHANGELOG.md', content);
37+
console.log('Updated CHANGELOG.md');

0 commit comments

Comments
 (0)