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 7875ff7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Generate Changelog

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

jobs:
changelog:
Expand Down
26 changes: 10 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,16 @@ 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 config --global user.name "Zihua Li"`;
await $`git config --global user.email "635902+luin@users.noreply.github.com"`;
await $`git add ${changelogFilename}`;
const message = `Update ${changelogFilename}: ${release.tagName}`;
await $`git commit -m ${message}`;
await $`git push origin main`;

0 comments on commit 7875ff7

Please sign in to comment.