Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(release): hand the release notes to the release as a file

Yudhi Armyndharis6f12e9697b6d
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b7bf657ef..5b48cd346 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -428,12 +428,7 @@ jobs:
if [ -z "$NOTES" ]; then
NOTES="Release v${VERSION}"
fi
- # Use EOF delimiter for multi-line output
- {
- echo "NOTES<<EOF"
- echo "$NOTES"
- echo "EOF"
- } >> "$GITHUB_OUTPUT"
+ printf '%s\n' "$NOTES" > "$RUNNER_TEMP/release-notes.md"
- name: Create GitHub Release
uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3
@@ -445,7 +440,7 @@ jobs:
token: ${{ secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }}
tag_name: ${{ github.ref_name }}
name: v${{ steps.version.outputs.VERSION }}
- body: ${{ steps.changelog.outputs.NOTES }}
+ body_path: ${{ runner.temp }}/release-notes.md
draft: false
# Same rule as the image channels below: any tag with a '-' suffix is a prerelease, so a
# tag kept off X.Y and latest can never become GitHub's "Latest" release either.
diff --git a/src/common/release-notes.spec.ts b/src/common/release-notes.spec.ts
new file mode 100644
index 000000000..2cd3471f2
--- /dev/null
+++ b/src/common/release-notes.spec.ts
@@ -0,0 +1,55 @@
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { load } from 'js-yaml';
+
+type Step = { name?: string; run?: string; with?: { body_path?: string } };
+type Workflow = { jobs: Record<string, { steps?: Step[] }> };
+
+describe('Release note extraction', () => {
+ const workflow = load(
+ readFileSync(join(__dirname, '..', '..', '.github', 'workflows', 'release.yml'), 'utf8'),
+ ) as Workflow;
+ const steps = Object.values(workflow.jobs).flatMap(job => job.steps ?? []);
+ const extract = steps.find(step => step.name === 'Extract release notes from CHANGELOG')!;
+ const publish = steps.find(step => step.name === 'Create GitHub Release')!;
+
+ it.each([
+ ['normal', '### Fixed\n\n- Preserve message order.'],
+ ['heredoc', '```sh\ncat <<EOF\nhello\nEOF\n```'],
+ ['repeated delimiter', 'EOF\nEOF\nNOTES=unexpected\nstill notes'],
+ ['literal text', '-n\n\\n stays literal\n${HOME} and $(false) are text'],
+ ['empty', ''],
+ ])('preserves %s notes without interpreting their content', (_name, notes) => {
+ const directory = mkdtempSync(join(tmpdir(), 'openwa-release-notes-'));
+ try {
+ const output = join(directory, 'outputs');
+ writeFileSync(output, '');
+ writeFileSync(
+ join(directory, 'CHANGELOG.md'),
+ `# Changelog\n\n## [0.26.0]\n${notes}\n## [0.25.0]\nolder section\n`,
+ );
+ const result = spawnSync('/bin/bash', ['-e', '-o', 'pipefail', '-c', extract.run!], {
+ cwd: directory,
+ encoding: 'utf8',
+ timeout: 5000,
+ maxBuffer: 65536,
+ env: {
+ PATH: process.env.PATH,
+ VERSION: '0.26.0',
+ GITHUB_OUTPUT: output,
+ RUNNER_TEMP: directory,
+ },
+ });
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe('');
+ expect(publish.with?.body_path).toBe('${{ runner.temp }}/release-notes.md');
+ const body = readFileSync(join(directory, 'release-notes.md'), 'utf8');
+ expect(body).toBe(`${notes || 'Release v0.26.0'}\n`);
+ expect(readFileSync(output, 'utf8')).toBe('');
+ } finally {
+ rmSync(directory, { recursive: true, force: true });
+ }
+ });
+});