diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 754bcc8c..86cc916f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -30,13 +30,24 @@ jobs: uses: actions/checkout@v4 - name: Setup bun uses: oven-sh/setup-bun@v2 + - name: Read changelog + id: changelog + run: echo "::set-output name=changelog::$(bun changelog)" - name: Release - uses: go-semantic-release/action@v1 - id: semrel + id: create_release + if: steps.changelog.outputs.changelog != '' + uses: actions/create-release@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token with: - github-token: ${{ secrets.GITHUB_TOKEN }} + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + # body: the changelog + body: ${{ steps.changelog.outputs.changelog }} + draft: false + prerelease: false - name: Publish to NPM - if: steps.semrel.outputs.version != '' + if: steps.create_release.outputs.id env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: bun publish diff --git a/package.json b/package.json index 671d5463..2688c8fb 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "posttest:browser": "bun scripts/video.ts", "posttest:snapshots": "bun scripts/video.ts", "test:all": "bun run test:browser && bun run test:coverage", + "changelog": "bun scripts/changelog.ts", "all": "bun clean && bun forlint && bun schema && bun format && bun run test:all && bun run build && bun archive && bun docs" }, "pre-commit": [ diff --git a/scripts/changelog.ts b/scripts/changelog.ts new file mode 100644 index 00000000..c248afd7 --- /dev/null +++ b/scripts/changelog.ts @@ -0,0 +1,32 @@ +/* +Read the changelog file +and output the current tag's changes +*/ +import { readFileSync } from 'fs'; +import { resolve } from 'path'; + +const packageJson = JSON.parse(readFileSync(resolve('package.json'), 'utf-8')); + +const changelog = readFileSync(resolve('CHANGELOG.md'), 'utf-8'); + +const tag = packageJson.version; + +const lines = changelog.split('\n'); + +let found = false; +let changes = ''; +for (const line of lines) { + if (line.startsWith(`## v${tag}`)) { + found = true; + } else if (line.startsWith('## ')) { + break; + } else if (found) { + changes += line + '\n'; + } +} + +const output = changes.trim(); +if (output === '') { + throw new Error(`No changes found for tag v${tag}`); +} +console.log(output);