Skip to content

Commit

Permalink
Update changelog actions
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed May 13, 2024
1 parent cc898ef commit de1afe1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Generate Changelog

on:
release:
types: [published]
types: [published, created]

jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4

- uses: fregante/setup-git-user@v2
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand Down
24 changes: 8 additions & 16 deletions scripts/changelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Fetch the latest release from GitHub and prepend it to the CHANGELOG.md
* Nothing will happen if the latest release is already in the CHANGELOG.md
*/
import { execa } from "execa";
import { $ } from "execa";
import { readFile, writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
Expand All @@ -17,12 +17,8 @@ const changeLogFilePath = join(

const currentChangeLog = await readFile(changeLogFilePath, "utf-8");

const { stdout } = await execa("gh", [
"release",
"list",
"--exclude-drafts",
"--json=tagName,publishedAt,name,isLatest",
]);
const { stdout } =
await $`gh release list --exclude-drafts --json=tagName,publishedAt,name,isLatest`;

const release = JSON.parse(stdout).find((release) => release.isLatest);

Expand Down Expand Up @@ -51,18 +47,14 @@ const formatDate = (date) => {
};

const { body } = JSON.parse(
(await execa("gh", ["release", "view", release.tagName, "--json=body"]))
.stdout
(await $`gh release view ${release.tagName} --json=body`).stdout
);

const note = `# ${release.tagName} (${formatDate(new Date(release.publishedAt))})\n\n${filteredReleaseNote(body)}\n\n[All changes](https://github.com/quilljs/quill/releases/tag/${release.tagName})\n`;

await writeFile(changeLogFilePath, `${note}\n${currentChangeLog}`);

await execa("git", ["add", changelogFilename]);
await execa("git", [
"commit",
"-m",
`Update ${changelogFilename}: ${release.tagName}`,
]);
await execa("git", ["push", "origin", "main"]);
await $`git add ${changelogFilename}`;
const message = `Update ${changelogFilename}: ${release.tagName}`;
await $`git commit -m ${message}`;
await $`git push origin main`;

0 comments on commit de1afe1

Please sign in to comment.