-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eacb4ae
commit 29df332
Showing
6 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,3 @@ jobs: | |
path: ~/.cache/ms-playwright | ||
- run: pnpm playwright install chromium | ||
- run: pnpm ci | ||
- uses: ArnaudBarre/[email protected] | ||
if: ${{ contains(github.event.head_commit.message, '[publish]') && github.ref == 'refs/heads/main' }} | ||
with: | ||
working-directory: dist | ||
npm-token: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Publish changelog | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v*" | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ArnaudBarre/github-release@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env tnode | ||
import { readFileSync, writeFileSync } from "node:fs"; | ||
import { | ||
execSync, | ||
ExecSyncOptionsWithBufferEncoding, | ||
} from "node:child_process"; | ||
import { stdin, stdout } from "node:process"; | ||
import { createInterface } from "node:readline"; | ||
import * as colors from "picocolors"; | ||
|
||
async function main(): Promise<void> { | ||
run("pnpm i --loglevel error"); | ||
const packageJSON = JSON.parse(readFileSync("package.json", "utf-8")) as { | ||
version: string; | ||
}; | ||
const changelog = readFileSync("CHANGELOG.md", "utf-8"); | ||
if (!changelog.includes("## Unreleased")) { | ||
throw new Error("Can't find '## Unreleased' section in CHANGELOG.md"); | ||
} | ||
|
||
console.log(colors.cyan("Changelog:")); | ||
const index = changelog.indexOf("## Unreleased") + 13; | ||
console.log( | ||
colors.dim(changelog.slice(index, changelog.indexOf("## ", index)).trim()), | ||
); | ||
|
||
console.log( | ||
colors.cyan("Current version: ") + colors.magenta(packageJSON.version), | ||
); | ||
const newVersion = (await ask(colors.cyan(`New version: `))).trim(); | ||
if (!newVersion) throw new Error("No version provided"); | ||
|
||
console.log(colors.dim("Write package.json & CHANGELOG.md")); | ||
packageJSON.version = newVersion; | ||
writeFileSync("package.json", JSON.stringify(packageJSON, null, 2) + "\n"); | ||
writeFileSync( | ||
"CHANGELOG.md", | ||
changelog.replace("## Unreleased", `## Unreleased\n\n## ${newVersion}`), | ||
); | ||
|
||
run(`git commit -am "release: v${newVersion}"`); | ||
run(`git tag v${newVersion}`); | ||
run("pnpm build"); | ||
run("npm publish", { cwd: "dist" }); | ||
run("git push --tags"); | ||
} | ||
|
||
const ask = (question: string) => | ||
new Promise<string>((res) => | ||
createInterface({ input: stdin, output: stdout }).question(question, res), | ||
); | ||
|
||
const run = (cmd: string, opts?: ExecSyncOptionsWithBufferEncoding) => { | ||
console.log(colors.dim(`$ ${cmd}`)); | ||
execSync(cmd, { stdio: "inherit", ...opts }); | ||
}; | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |