Skip to content

Commit

Permalink
Update release script
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jan 13, 2024
1 parent 1010292 commit 1a44658
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 41 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
scripts/
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

# on:
# workflow_dispatch:
# inputs:
# version:
# description: 'npm version. E.g. "2.0.0"'
# required: true
on:
push:
branches: [zh-release]

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- run: npm ci
# - run: ./scripts/release.js ${{ github.event.inputs.version }}
- run: ./scripts/release.js 2.0.0-beta.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "https://github.com/quilljs/quill"
"url": "git+https://github.com/quilljs/quill.git"
},
"bugs": {
"url": "https://github.com/quilljs/quill/issues"
Expand Down
2 changes: 1 addition & 1 deletion packages/quill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "https://github.com/quilljs/quill",
"url": "git+https://github.com/quilljs/quill.git",
"directory": "packages/quill"
},
"bugs": {
Expand Down
102 changes: 102 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env node

const exec = require("node:child_process").execSync;
const fs = require("node:fs");
const path = require("node:path");

const exitWithError = (message) => {
console.error(message);
process.exit(1);
};

if (!process.env.CI) {
exitWithError("The script should only be run in CI");
}

exec('git config --global user.name "Zihua Li"');
exec('git config --global user.email "635902+luin@users.noreply.github.com"');

/*
* Check that the git working directory is clean
*/
if (exec("git status --porcelain").length) {
exitWithError(
"Make sure the git working directory is clean before releasing"
);
}

/*
* Check that the version is valid. Also extract the dist-tag from the version.
*/
const [version, distTag] = (() => {
const [, , v] = process.argv;
const match = v.match(
/^(?:[0-9]+\.){2}(?:[0-9]+)(?:-(dev|alpha|beta|rc)\.[0-9]+)?$/
);
if (!match) {
exitWithError(`Invalid version: ${v || "<empty>"}`);
}

return [v, match[1] || "latest"];
})();

/*
* Get the current version
*/
const currentVersion = JSON.parse(
fs.readFileSync("package.json", "utf-8")
).version;
console.log(
`Releasing with version: ${currentVersion} -> ${version} and dist-tag: ${distTag}`
);

/*
* Update version in CHANGELOG.md
*/
console.log("Updating CHANGELOG.md and bumping versions");
const UNRELEASED_PLACEHOLDER = "[Unreleased]";
fs.writeFileSync(
"CHANGELOG.md",
fs
.readFileSync("CHANGELOG.md", "utf8")
.replace(
`# ${UNRELEASED_PLACEHOLDER}`,
`# ${UNRELEASED_PLACEHOLDER}\n\n# ${version}`
)
);

/*
* Bump npm versions
*/
exec("git add CHANGELOG.md");
exec(`npm version ${version} --workspaces --force`);
exec("git add **/package.json");
exec(`npm version ${version} --include-workspace-root --force`);
exec("git push --tags");

/*
* Build Quill package
*/
console.log("Building Quill");
exec("npm run build:quill");

/*
* Publish Quill package
*/
console.log("Publishing Quill");
const distFolder = "packages/quill/dist";
if (
JSON.parse(fs.readFileSync(path.join(distFolder, "package.json"), "utf-8"))
.version !== version
) {
exitWithError("Version mismatch between package.json and dist/package.json");
}
exec(`npm publish --tag ${distTag} --dry-run`, { cwd: distFolder });

/*
* Create GitHub release
*/
const prereleaseFlag = distTag === "latest" ? "--latest" : " --prerelease";
exec(
`gh release create v${version} ${prereleaseFlag} -t "Version ${version}" --draft`
);
39 changes: 0 additions & 39 deletions scripts/release.sh

This file was deleted.

0 comments on commit 1a44658

Please sign in to comment.