From 517d00994b477b62962f7ed85cbdebc4d5c1d7b9 Mon Sep 17 00:00:00 2001 From: Zihua <635902+luin@users.noreply.github.com> Date: Mon, 13 May 2024 15:46:30 +0800 Subject: [PATCH] Config git for all workflows --- .github/workflows/changelog.yml | 3 +- scripts/changelog.mjs | 3 + scripts/release.js | 213 ++++++++++++++++---------------- scripts/utils/configGit.mjs | 8 ++ 4 files changed, 121 insertions(+), 106 deletions(-) create mode 100644 scripts/utils/configGit.mjs diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 162c903484..978154c852 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -3,6 +3,7 @@ name: Generate Changelog on: release: types: [published, created] + workflow_dispatch: {} jobs: changelog: @@ -10,8 +11,6 @@ jobs: steps: - name: Git checkout uses: actions/checkout@v4 - - run: git config --global user.email "17000285+quill-bot@users.noreply.github.com" - - run: git config --global user.name "quill-bot" - name: Use Node.js uses: actions/setup-node@v4 with: diff --git a/scripts/changelog.mjs b/scripts/changelog.mjs index ebde57ef79..07a3596d16 100644 --- a/scripts/changelog.mjs +++ b/scripts/changelog.mjs @@ -6,6 +6,7 @@ import { $ } from "execa"; import { readFile, writeFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; +import configGit from "./utils/configGit.mjs"; const changelogFilename = "CHANGELOG.md"; @@ -26,6 +27,8 @@ if (currentChangeLog.includes(`# ${release.tagName}`)) { process.exit(0); } +await configGit(); + const filteredReleaseNote = (note) => { const ignoreSections = [ "## new contributors", diff --git a/scripts/release.js b/scripts/release.js index 1f62be9328..d53057b7d8 100755 --- a/scripts/release.js +++ b/scripts/release.js @@ -30,121 +30,126 @@ if (!process.env.CI) { exec('echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'); -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 inputVersion = args.values.version; - if (!inputVersion) { - exitWithError('Missing required argument: "--version "'); +async function main() { + await configGit(); + + /* + * 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" + ); } - if (inputVersion === "experimental") { - const randomId = crypto - .randomBytes(Math.ceil(9 / 2)) - .toString("hex") - .slice(0, 9); - - return [ - `0.0.0-experimental-${randomId}-${new Date() - .toISOString() - .slice(0, 10) - .replace(/-/g, "")}`, - "experimental", - ]; - } - - const match = inputVersion.match( - /^(?:[0-9]+\.){2}(?:[0-9]+)(?:-(dev|alpha|beta|rc)\.[0-9]+)?$/ + /* + * Check that the version is valid. Also extract the dist-tag from the version. + */ + const [version, distTag] = (() => { + const inputVersion = args.values.version; + if (!inputVersion) { + exitWithError('Missing required argument: "--version "'); + } + + if (inputVersion === "experimental") { + const randomId = crypto + .randomBytes(Math.ceil(9 / 2)) + .toString("hex") + .slice(0, 9); + + return [ + `0.0.0-experimental-${randomId}-${new Date() + .toISOString() + .slice(0, 10) + .replace(/-/g, "")}`, + "experimental", + ]; + } + + const match = inputVersion.match( + /^(?:[0-9]+\.){2}(?:[0-9]+)(?:-(dev|alpha|beta|rc)\.[0-9]+)?$/ + ); + if (!match) { + exitWithError(`Invalid version: ${inputVersion}`); + } + + return [inputVersion, 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}` ); - if (!match) { - exitWithError(`Invalid version: ${inputVersion}`); - } - return [inputVersion, 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}` -); - -/* - * Bump npm versions - */ -exec(`npm version ${version} --workspaces --force`); -exec("git add **/package.json"); -exec(`npm version ${version} --include-workspace-root --force`); - -const pushCommand = `git push origin ${process.env.GITHUB_REF_NAME} --follow-tags`; -if (distTag === "experimental") { - console.log(`Skipping: "${pushCommand}" for experimental version`); -} else { - if (dryRun) { - console.log(`Skipping: "${pushCommand}" in dry-run mode`); + /* + * Bump npm versions + */ + exec(`npm version ${version} --workspaces --force`); + exec("git add **/package.json"); + exec(`npm version ${version} --include-workspace-root --force`); + + const pushCommand = `git push origin ${process.env.GITHUB_REF_NAME} --follow-tags`; + if (distTag === "experimental") { + console.log(`Skipping: "${pushCommand}" for experimental version`); } else { - exec(pushCommand); + if (dryRun) { + console.log(`Skipping: "${pushCommand}" in dry-run mode`); + } else { + exec(pushCommand); + } } -} -/* - * 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"); -} + /* + * 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" + ); + } -const readme = fs.readFileSync("README.md", "utf-8"); -fs.writeFileSync(path.join(distFolder, "README.md"), readme); + const readme = fs.readFileSync("README.md", "utf-8"); + fs.writeFileSync(path.join(distFolder, "README.md"), readme); -exec(`npm publish --tag ${distTag}${dryRun ? " --dry-run" : ""}`, { - cwd: distFolder, -}); + exec(`npm publish --tag ${distTag}${dryRun ? " --dry-run" : ""}`, { + cwd: distFolder, + }); -/* - * Create GitHub release - */ -if (distTag === "experimental") { - console.log("Skipping GitHub release for experimental version"); -} else { - const prereleaseFlag = distTag === "latest" ? "--latest" : " --prerelease"; - const releaseCommand = `gh release create v${version} ${prereleaseFlag} -t "Version ${version}" --generate-notes`; - if (dryRun) { - console.log(`Skipping: "${releaseCommand}" in dry-run mode`); + /* + * Create GitHub release + */ + if (distTag === "experimental") { + console.log("Skipping GitHub release for experimental version"); } else { - exec(releaseCommand); + const prereleaseFlag = distTag === "latest" ? "--latest" : " --prerelease"; + const releaseCommand = `gh release create v${version} ${prereleaseFlag} -t "Version ${version}" --generate-notes`; + if (dryRun) { + console.log(`Skipping: "${releaseCommand}" in dry-run mode`); + } else { + exec(releaseCommand); + } } + + /* + * Create npm package tarball + */ + exec("npm pack", { cwd: distFolder }); } -/* - * Create npm package tarball - */ -exec("npm pack", { cwd: distFolder }); +main(); diff --git a/scripts/utils/configGit.mjs b/scripts/utils/configGit.mjs new file mode 100644 index 0000000000..aadf5a1bc4 --- /dev/null +++ b/scripts/utils/configGit.mjs @@ -0,0 +1,8 @@ +import { $ } from "execa"; + +async function configGit() { + await $`git config --global user.name ${"Zihua Li"}`; + await $`git config --global user.email ${"635902+luin@users.noreply.github.com"}`; +} + +export default configGit;