From ad96728a1c7e243f7fc659669dcddf1745ea4ffc Mon Sep 17 00:00:00 2001 From: Danica Shen Date: Fri, 10 Feb 2023 20:02:52 +0000 Subject: [PATCH] feat(17494): add generate-beta-commit (#17684) * feat(17494): add generate-beta-commit * Version v10.24.2-beta.0 * Version v10.24.2-beta.1 * feat(17494): revert back the package version * feat(17494): revert back the gitignore for yarn/versions --- development/generate-beta-commit.js | 37 +++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 development/generate-beta-commit.js diff --git a/development/generate-beta-commit.js b/development/generate-beta-commit.js new file mode 100644 index 000000000..5005e535f --- /dev/null +++ b/development/generate-beta-commit.js @@ -0,0 +1,37 @@ +const { promisify } = require('util'); +const { promises: fs } = require('fs'); +const exec = promisify(require('child_process').exec); +const VERSION = require('../package.json').version; + +start().catch(console.error); + +async function start() { + let betaVersion; + if (VERSION.includes('beta')) { + // Remove auto generated stableVersion to achieve bump + // You can find the issue here: https://github.com/yarnpkg/berry/issues/4328 + const packageJsonData = JSON.parse( + await fs.readFile('package.json', 'utf8'), + ); + delete packageJsonData.stableVersion; + await fs.writeFile( + 'package.json', + JSON.stringify(packageJsonData, null, 2), + ); + // generate next valid beta version + const splitVersion = VERSION.split('-beta.'); + const currentBetaVersion = Number(splitVersion[1]) + 1; + betaVersion = `${splitVersion[0]}-beta.${currentBetaVersion}`; + // bump existing beta version to next +1 one + await exec(`yarn version ${betaVersion}`); + } else { + betaVersion = `${VERSION}-beta.0`; + // change package.json version to beta-0 + await exec(`yarn version ${betaVersion}`); + } + // Generate a beta commit message and push changes to github + // Later on this will be picked up by CircleCI with the format of Version vx.x.x-beta.x + await exec( + `git add . && git commit -m "Version v${betaVersion}" && git push`, + ); +} diff --git a/package.json b/package.json index b298aba1b..2522b1e1c 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,8 @@ "test-storybook": "test-storybook -c .storybook", "test-storybook:ci": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn storybook:build && npx http-server storybook-build --port 6006 \" \"wait-on tcp:6006 && yarn test-storybook --maxWorkers=2\"", "githooks:install": "husky install", - "fitness-functions": "node development/fitness-functions/index.js" + "fitness-functions": "node development/fitness-functions/index.js", + "generate-beta-commit": "node ./development/generate-beta-commit.js" }, "resolutions": { "analytics-node/axios": "^0.21.2",