Add release scripts
This commit is contained in:
parent
ba30de75e5
commit
118ba096f5
@ -1 +1,2 @@
|
||||
dist/
|
||||
scripts/
|
||||
|
||||
31
.github/workflows/release.yml
vendored
Normal file
31
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'npm version. E.g. "2.0.0"'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
uses: ./.github/workflows/_test.yml
|
||||
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
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 }}
|
||||
121
scripts/release.js
Executable file
121
scripts/release.js
Executable file
@ -0,0 +1,121 @@
|
||||
#!/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 changelog = fs.readFileSync("CHANGELOG.md", "utf8");
|
||||
const UNRELEASED_PLACEHOLDER = "# [Unreleased]";
|
||||
|
||||
const index = changelog.indexOf(UNRELEASED_PLACEHOLDER);
|
||||
if (index === -1) {
|
||||
exitWithError(`Could not find "${UNRELEASED_PLACEHOLDER}" in CHANGELOG.md`);
|
||||
}
|
||||
let nextVersionIndex = changelog.indexOf("\n# v", index);
|
||||
if (nextVersionIndex === -1) {
|
||||
nextVersionIndex = change.length - 1;
|
||||
}
|
||||
|
||||
const releaseNots = changelog
|
||||
.substring(index + UNRELEASED_PLACEHOLDER.length, nextVersionIndex)
|
||||
.trim();
|
||||
|
||||
fs.writeFileSync(
|
||||
"CHANGELOG.md",
|
||||
changelog.replace(
|
||||
UNRELEASED_PLACEHOLDER,
|
||||
`${UNRELEASED_PLACEHOLDER}\n\n# v${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 filename = `release-note-${version}-${(Math.random() * 1000) | 0}.txt`;
|
||||
fs.writeFileSync(filename, releaseNots);
|
||||
try {
|
||||
const prereleaseFlag = distTag === "latest" ? "--latest" : " --prerelease";
|
||||
exec(
|
||||
`gh release create v${version} ${prereleaseFlag} -t "Version ${version}" --notes-file "${filename}" --draft`
|
||||
);
|
||||
} finally {
|
||||
fs.unlinkSync(filename);
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION="$1"
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Version required."
|
||||
exit
|
||||
else
|
||||
echo "Releasing $VERSION"
|
||||
fi
|
||||
|
||||
rm -r .release
|
||||
rm -r dist
|
||||
mkdir .release
|
||||
mkdir .release/quill
|
||||
|
||||
npm run build
|
||||
npx webpack --env minimize
|
||||
cp dist/quill.core.css dist/quill.bubble.css dist/quill.snow.css dist/quill.js dist/quill.core.js dist/quill.min.js dist/quill.min.js.map .release/quill/
|
||||
|
||||
cd .release
|
||||
|
||||
# tar -czf quill.tar.gz quill
|
||||
|
||||
aws s3 cp quill/quill.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
|
||||
aws s3 cp quill/quill.min.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
|
||||
aws s3 cp quill/quill.core.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
|
||||
aws s3 cp quill/quill.bubble.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
|
||||
aws s3 cp quill/quill.core.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
|
||||
aws s3 cp quill/quill.snow.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
|
||||
aws s3 cp quill/quill.min.js.map s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/json; charset=utf-8" --profile quill
|
||||
aws s3 sync s3://cdn.quilljs.com/$VERSION/ s3://cdn.quilljs.com/latest/ --profile quill
|
||||
|
||||
cd ..
|
||||
# git tag v$VERSION -m "Version $VERSION"
|
||||
# git push origin v$VERSION
|
||||
# git push origin master
|
||||
|
||||
npm publish --tag dev
|
||||
Loading…
Reference in New Issue
Block a user