From c4a883545dcdab4bd6fd26535d24cd59ac221822 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Sat, 13 Jan 2024 08:25:26 +0800 Subject: [PATCH] Update release script --- .eslintignore | 1 + .github/workflows/release.yml | 30 ++++++++++ package.json | 2 +- packages/quill/package.json | 2 +- scripts/release.js | 102 ++++++++++++++++++++++++++++++++++ scripts/release.sh | 39 ------------- 6 files changed, 135 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 scripts/release.js delete mode 100755 scripts/release.sh diff --git a/.eslintignore b/.eslintignore index 849ddff3b7..2dd688c0bb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ dist/ +scripts/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..a62deee6fb --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/package.json b/package.json index 0d8977a8ca..36f77592b1 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/packages/quill/package.json b/packages/quill/package.json index 1cde31810e..11764f9bb5 100644 --- a/packages/quill/package.json +++ b/packages/quill/package.json @@ -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": { diff --git a/scripts/release.js b/scripts/release.js new file mode 100755 index 0000000000..acca64799c --- /dev/null +++ b/scripts/release.js @@ -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 || ""}`); + } + + 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"); + +/* + * 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` +); diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 94ab723b88..0000000000 --- a/scripts/release.sh +++ /dev/null @@ -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