From 6a9dd4032d8c73cf4f6fb4ef394dce28ba4718a8 Mon Sep 17 00:00:00 2001 From: xile611 Date: Thu, 31 Aug 2023 14:13:11 +0800 Subject: [PATCH 1/5] chore: update the release and pre-release scripts and workflow --- .github/workflows/pre-release.yml | 8 +- .github/workflows/release.yml | 14 +++ common/config/rush/version-policies.json | 106 ++------------------- common/scripts/apply-prerelease-version.js | 12 +++ common/scripts/get-package-json.js | 8 ++ common/scripts/parse-version.js | 30 +++--- common/scripts/pre-release.js | 29 +++--- common/scripts/release.js | 16 +++- common/scripts/set-json-file.js | 30 ++++++ common/scripts/set-prelease-version.js | 70 ++++++++++++++ common/scripts/version-policies.js | 85 +++++++++++++++++ rush.json | 15 ++- 12 files changed, 276 insertions(+), 147 deletions(-) create mode 100644 common/scripts/apply-prerelease-version.js create mode 100644 common/scripts/get-package-json.js create mode 100644 common/scripts/set-json-file.js create mode 100644 common/scripts/set-prelease-version.js create mode 100644 common/scripts/version-policies.js diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 879b4cd33..6cc0dbaf3 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -34,14 +34,14 @@ jobs: - name: Parse semver version from branch name id: semver_parser - uses: xile611/read-package-version-action@v2.1 + uses: xile611/read-package-version-action@main with: path: packages/vrender semver_string: ${{ github.ref_name }} semver_pattern: '^pre-release/(.*)$' # ^v?(.*)$ by default - name: Apply prereleaseName - run: node common/scripts/install-run-rush.js publish --apply --prerelease-name ${{ steps.semver_parser.outputs.pre_release_name }} --partial-prerelease + run: node common/scripts/apply-prerelease-version.js ${{ steps.semver_parser.outputs.pre_release_name }} ${{ steps.semver_parser.outputs.main }} - name: Build packages run: node common/scripts/install-run-rush.js build --only tag:package @@ -57,7 +57,7 @@ jobs: - name: Get npm version id: package-version - uses: xile611/read-package-version-action@v2.1 + uses: xile611/read-package-version-action@main with: path: packages/vrender @@ -67,4 +67,4 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} message: 'build: prelease version ${{ steps.package-version.outputs.current_version }}' branch: ${{ github.ref_name }} - author_name: ${{ github.actor }} \ No newline at end of file + author_name: ${{ github.actor }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e5ec9e177..061216594 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,20 @@ jobs: - name: Install rush run: node common/scripts/install-run-rush.js install --bypass-policy + - name: Parse semver version from branch name + id: semver_parser + uses: xile611/read-package-version-action@main + with: + path: packages/vgrammar + semver_string: ${{ github.ref_name }} + semver_pattern: '^release/(.*)$' # ^v?(.*)$ by default + + - name: update nextBump of version policies + uses: xile611/set-next-bump-of-rush@main + with: + release_version: ${{ steps.semver_parser.outputs.full }} + write_next_bump: true + - name: Update version run: node common/scripts/install-run-rush.js version --bump diff --git a/common/config/rush/version-policies.json b/common/config/rush/version-policies.json index 048aef0fa..4c14bb215 100644 --- a/common/config/rush/version-policies.json +++ b/common/config/rush/version-policies.json @@ -1,102 +1,8 @@ -/** - * This is configuration file is used for advanced publishing configurations with Rush. - * More documentation is available on the Rush website: https://rushjs.io - */ - -/** - * A list of version policy definitions. A "version policy" is a custom package versioning - * strategy that affects "rush change", "rush version", and "rush publish". The strategy applies - * to a set of projects that are specified using the "versionPolicyName" field in rush.json. - */ [ - // { - // /** - // * (Required) Indicates the kind of version policy being defined ("lockStepVersion" or "individualVersion"). - // * - // * The "lockStepVersion" mode specifies that the projects will use "lock-step versioning". This - // * strategy is appropriate for a set of packages that act as selectable components of a - // * unified product. The entire set of packages are always published together, and always share - // * the same NPM version number. When the packages depend on other packages in the set, the - // * SemVer range is usually restricted to a single version. - // */ - // "definitionName": "lockStepVersion", - // - // /** - // * (Required) The name that will be used for the "versionPolicyName" field in rush.json. - // * This name is also used command-line parameters such as "--version-policy" - // * and "--to-version-policy". - // */ - // "policyName": "MyBigFramework", - // - // /** - // * (Required) The current version. All packages belonging to the set should have this version - // * in the current branch. When bumping versions, Rush uses this to determine the next version. - // * (The "version" field in package.json is NOT considered.) - // */ - // "version": "1.0.0", - // - // /** - // * (Required) The type of bump that will be performed when publishing the next release. - // * When creating a release branch in Git, this field should be updated according to the - // * type of release. - // * - // * Valid values are: "prerelease", "release", "minor", "patch", "major" - // */ - // "nextBump": "prerelease", - // - // /** - // * (Optional) If specified, all packages in the set share a common CHANGELOG.md file. - // * This file is stored with the specified "main" project, which must be a member of the set. - // * - // * If this field is omitted, then a separate CHANGELOG.md file will be maintained for each - // * package in the set. - // */ - // "mainProject": "my-app", - // - // /** - // * (Optional) If enabled, the "rush change" command will prompt the user for their email address - // * and include it in the JSON change files. If an organization maintains multiple repos, tracking - // * this contact information may be useful for a service that automatically upgrades packages and - // * needs to notify engineers whose change may be responsible for a downstream build break. It might - // * also be useful for crediting contributors. Rush itself does not do anything with the collected - // * email addresses. The default value is "false". - // */ - // // "includeEmailInChangeFile": true - // }, - // - // { - // /** - // * (Required) Indicates the kind of version policy being defined ("lockStepVersion" or "individualVersion"). - // * - // * The "individualVersion" mode specifies that the projects will use "individual versioning". - // * This is the typical NPM model where each package has an independent version number - // * and CHANGELOG.md file. Although a single CI definition is responsible for publishing the - // * packages, they otherwise don't have any special relationship. The version bumping will - // * depend on how developers answer the "rush change" questions for each package that - // * is changed. - // */ - // "definitionName": "individualVersion", - // - // "policyName": "MyRandomLibraries", - // - // /** - // * (Optional) This can be used to enforce that all packages in the set must share a common - // * major version number, e.g. because they are from the same major release branch. - // * It can also be used to discourage people from accidentally making "MAJOR" SemVer changes - // * inappropriately. The minor/patch version parts will be bumped independently according - // * to the types of changes made to each project, according to the "rush change" command. - // */ - // "lockedMajor": 3, - // - // /** - // * (Optional) When publishing is managed by Rush, by default the "rush change" command will - // * request changes for any projects that are modified by a pull request. These change entries - // * will produce a CHANGELOG.md file. If you author your CHANGELOG.md manually or announce updates - // * in some other way, set "exemptFromRushChange" to true to tell "rush change" to ignore the projects - // * belonging to this version policy. - // */ - // "exemptFromRushChange": false, - // - // // "includeEmailInChangeFile": true - // } + { + "definitionName": "lockStepVersion", + "policyName": "vrenderMain", + "version": "0.14.5", + "nextBump": "patch" + } ] diff --git a/common/scripts/apply-prerelease-version.js b/common/scripts/apply-prerelease-version.js new file mode 100644 index 000000000..7364daa97 --- /dev/null +++ b/common/scripts/apply-prerelease-version.js @@ -0,0 +1,12 @@ +const writePrereleaseVersion = require('./set-prelease-version'); +const checkAndUpdateNextBump = require('./version-policies'); + + +function run() { + const preReleaseName = process.argv.slice(2)[0]; + const nextBump = checkAndUpdateNextBump(process.argv.slice(2)[1]); + + writePrereleaseVersion(nextBump, preReleaseName); +} + +run() \ No newline at end of file diff --git a/common/scripts/get-package-json.js b/common/scripts/get-package-json.js new file mode 100644 index 000000000..a3afad336 --- /dev/null +++ b/common/scripts/get-package-json.js @@ -0,0 +1,8 @@ +const fs = require('fs') + +function getPackageJson(pkgJsonPath) { + const pkgJson = fs.readFileSync(pkgJsonPath, { encoding: 'utf-8' }) + return JSON.parse(pkgJson); +} + +module.exports = getPackageJson; \ No newline at end of file diff --git a/common/scripts/parse-version.js b/common/scripts/parse-version.js index 3b6953c54..e44c347f5 100644 --- a/common/scripts/parse-version.js +++ b/common/scripts/parse-version.js @@ -2,24 +2,20 @@ // reg test: https://regex101.com/r/vkijKf/1/ const SEMVER_REG = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm; -function parseVersion() { - const branchName = process.argv.slice(2)[0]; +function parseVersion(version) { + const res = SEMVER_REG.exec(version); - - if (branchName) { - const versionName = branchName.includes('release/') ? branchName.replace('release/', '') : branchName; - const res = SEMVER_REG.exec(versionName); - - if (res) { - return { - major: res[1], - minor: res[2], - patch: res[3], - preReleaseName: res[4], - preReleaseType: res[4].includes('.') ? res[4].split('.')[0] : res[4] - }; - } + if (res) { + return { + major: +res[1], + minor: +res[2], + patch: +res[3], + preReleaseName: res[4], + preReleaseType: res[4] && res[4].includes('.') ? res[4].split('.')[0] : res[4] + }; } return null; -} \ No newline at end of file +} + +module.exports = parseVersion \ No newline at end of file diff --git a/common/scripts/pre-release.js b/common/scripts/pre-release.js index a919dc60f..f1500620d 100644 --- a/common/scripts/pre-release.js +++ b/common/scripts/pre-release.js @@ -1,33 +1,33 @@ /** * prelease + * node release.js [alpha.0] [patch | major | minor | 1.0.0] */ const { spawnSync } = require('child_process') -const fs = require('fs') const path = require('path') +const checkAndUpdateNextBump = require('./version-policies'); +const getPackageJson = require('./get-package-json'); +const writePrereleaseVersion = require('./set-prelease-version'); -function getPackageJson(pkgJsonPath) { - const pkgJson = fs.readFileSync(pkgJsonPath, { encoding: 'utf-8' }) - return JSON.parse(pkgJson); -} const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(alpha|beta|rc)(?:\.(?:(0|[1-9])))*)$/; const preReleaseNameReg = /^((alpha|beta|rc)(?:\.(?:0|[1-9]))*)$/; + function run() { let preReleaseName = process.argv.slice(2)[0]; let preReleaseType = ''; - const cwd = process.cwd(); - const rushJson = getPackageJson(`${cwd}/rush.json`) + const rushJson = getPackageJson(path.join(__dirname, '../../rush.json')) const package = rushJson.projects.find((project) => project.packageName === '@visactor/vrender'); let regRes = null; + if (typeof preReleaseName === 'string' && preReleaseName && (regRes = preReleaseNameReg.exec(preReleaseName))) { preReleaseType = regRes[2]; } else if (!preReleaseName) { if (package) { - const pkgJsonPath = path.resolve(package.projectFolder, 'package.json') + const pkgJsonPath = path.join(__dirname, '../../', package.projectFolder, 'package.json') const pkgJson = getPackageJson(pkgJsonPath) const currentVersion = pkgJson.version; @@ -54,20 +54,14 @@ function run() { if (preReleaseName && preReleaseType) { // 1. apply version and update version of package.json - spawnSync('sh', ['-c', `rush publish --apply --prerelease-name ${preReleaseName} --partial-prerelease`], { - stdio: 'inherit', - shell: false, - }); - - + writePrereleaseVersion(checkAndUpdateNextBump(process.argv.slice(2)[1]), preReleaseName) + // 2. build all the packages spawnSync('sh', ['-c', `rush build --only tag:package`], { stdio: 'inherit', shell: false, }); - - // 3. publish to npm spawnSync('sh', ['-c', `rush publish --publish --include-all --tag ${preReleaseType}`], { stdio: 'inherit', @@ -81,7 +75,7 @@ function run() { }); if (package) { - const pkgJsonPath = path.resolve(package.projectFolder, 'package.json') + const pkgJsonPath = path.join(__dirname, '../../', package.projectFolder, 'package.json'); const pkgJson = getPackageJson(pkgJsonPath) // 5. add the the changes @@ -100,3 +94,4 @@ function run() { } run() + diff --git a/common/scripts/release.js b/common/scripts/release.js index e7ea515db..49aae5801 100644 --- a/common/scripts/release.js +++ b/common/scripts/release.js @@ -1,25 +1,32 @@ /** - * release + * prelease + * node release.js [alpha.0] [patch | major | minor | 1.0.0] */ const { spawnSync } = require('child_process') const fs = require('fs') const path = require('path') +const checkAndUpdateNextBump = require('./version-policies'); function getPackageJson(pkgJsonPath) { const pkgJson = fs.readFileSync(pkgJsonPath, { encoding: 'utf-8' }) return JSON.parse(pkgJson) } + function run() { + let releaseVersion = process.argv.slice(2)[0]; const cwd = process.cwd(); - + // 0. update `nextBump` + checkAndUpdateNextBump(releaseVersion); + // 1. update version of package.json, this operation will remove the common/changes spawnSync('sh', ['-c', `rush version --bump`], { stdio: 'inherit', shell: false, }); + // 2. build all the packages spawnSync('sh', ['-c', `rush build --only tag:package`], { stdio: 'inherit', @@ -38,11 +45,11 @@ function run() { shell: false, }); - const rushJson = getPackageJson(`${cwd}/rush.json`); + const rushJson = getPackageJson(path.join(__dirname, '../../rush.json')); const package = rushJson.projects.find((project) => project.name === '@visactor/vrender'); if (package) { - const pkgJsonPath = path.resolve(project.projectFolder, 'package.json') + const pkgJsonPath = path.join(__dirname, '../../', project.projectFolder, 'package.json') const pkgJson = getPackageJson(pkgJsonPath) // 5. add tag @@ -72,3 +79,4 @@ function run() { } run() + diff --git a/common/scripts/set-json-file.js b/common/scripts/set-json-file.js new file mode 100644 index 000000000..40f0f0184 --- /dev/null +++ b/common/scripts/set-json-file.js @@ -0,0 +1,30 @@ +function setJsonFileByKey(file, json, keys, newValue) { + const prevValue = keys.reduce((res, k) => { + return res[k]; + }, json); + + if (prevValue !== newValue) { + let startIndex = 0; + + keys.forEach(k => { + const keyStr = `"${k}"`; + const index = file.indexOf(keyStr, startIndex); + + if (index >= 0) { + startIndex = index + keyStr.length + 1; + } + }) + + const leftIndex = file.indexOf('"', startIndex); + const rightIndex = leftIndex >= 0 ? file.indexOf('"', leftIndex +1) : -1; + + if (leftIndex >= 0 && rightIndex >= 0) { + return `${file.slice(0, leftIndex)}"${newValue}"${file.slice(rightIndex + 1)}` + } + } + + return file; +} + +module.exports = setJsonFileByKey; + diff --git a/common/scripts/set-prelease-version.js b/common/scripts/set-prelease-version.js new file mode 100644 index 000000000..7541594c1 --- /dev/null +++ b/common/scripts/set-prelease-version.js @@ -0,0 +1,70 @@ +const fs = require('fs') +const path = require('path') +const getPackageJson = require('./get-package-json'); +const parseVersion = require('./parse-version'); +const setJsonFileByKey = require('./set-json-file'); + + +function writePrereleaseVersion(nextBump, preReleaseName) { + const rushJson = getPackageJson(path.join(__dirname, '../../rush.json')); + const projects = rushJson.projects; + const mainPackage = projects.find((project) => project.packageName === '@visactor/vgrammar'); + + if (!mainPackage) { + return; + } + + const mainPkgJsonPath = path.join(__dirname, '../../', mainPackage.projectFolder, 'package.json') + const mainPkgJson = getPackageJson(mainPkgJsonPath) + const mainVersion = mainPkgJson.version; + const version = parseVersion(mainVersion); + + if (!version) { + return; + } + + if (!version.preReleaseName) { + if (nextBump === 'major') { + version.major += 1; + } else if (nextBump === 'minor') { + version.minor += 1; + } else { + version.patch += 1; + } + } + + const nextVersion = `${version.major}.${version.minor}.${version.patch}-${preReleaseName}`; + const published = projects.filter(project => project.shouldPublish).map(project => project.packageName); + + projects.forEach(project => { + const pkgJsonPath = path.join( __dirname, '../../', project.projectFolder, 'package.json') + let jsonFile = fs.readFileSync(pkgJsonPath, { encoding: 'utf-8' }) + const pkgJson = JSON.parse(jsonFile); + + if (project.shouldPublish) { + jsonFile = setJsonFileByKey(jsonFile, pkgJson, ['version'], nextVersion); + } + + if (pkgJson.dependencies) { + Object.keys(pkgJson.dependencies).forEach(dep => { + if (published.includes(dep)) { + jsonFile = setJsonFileByKey(jsonFile, pkgJson, ['dependencies', dep], `workspace:${nextVersion}`); + } + }); + } + + if (pkgJson.devDependencies) { + Object.keys(pkgJson.devDependencies).forEach(dep => { + if (published.includes(dep)) { + jsonFile = setJsonFileByKey(jsonFile, pkgJson, ['devDependencies', dep], `workspace:${nextVersion}`); + } + }); + } + + fs.writeFileSync(pkgJsonPath, jsonFile) + }); + + +} + +module.exports = writePrereleaseVersion; \ No newline at end of file diff --git a/common/scripts/version-policies.js b/common/scripts/version-policies.js new file mode 100644 index 000000000..87455eb46 --- /dev/null +++ b/common/scripts/version-policies.js @@ -0,0 +1,85 @@ + +const fs = require('fs') +const path = require('path') +const parseVersion = require('./parse-version'); +const PRERELEASE = 'prerelease'; +const MINOR = 'minor'; +const MAJOR = 'major'; +const PATCH = 'patch'; +const NEXT_BUMPMS = [PRERELEASE, PATCH, MINOR, MAJOR]; +const setJsonFileByKey = require('./set-json-file'); + + +const parseNextBumpFromVersion = ( + versionString +) => { + const res = parseVersion(versionString); + + if (res) { + if (res.patch === 0) { + return formatted.minor == 0 ? MAJOR : MINOR; + } + + return PATCH + } + + console.error(`can parse nextBump from version: ${versionString}`) + process.exit(1); +} + +const writeNextBump = ( + nextBump, +) => { + const filePath = path.join(__dirname, '../config/rush/version-policies.json'); + let fileContent = fs.readFileSync(filePath).toString() + const json = JSON.parse(fileContent); + const curNextBump = json[0].nextBump + + if (nextBump !== curNextBump) { + fileContent = setJsonFileByKey(fileContent, json, ['0', 'nextBump'], nextBump); + + fs.writeFileSync(path.join(__dirname, '../config/rush/version-policies.json'), fileContent) + } +} + +const readNextBumpFromChanges = () => { + const changeRoot = path.join(__dirname, '../changes/@visactor/vgrammar'); + const filenames = fs.readdirSync(changeRoot); + + if (filenames && filenames.length) { + const changeType = []; + + filenames.forEach(fileName => { + const json = JSON.parse(fs.readFileSync(path.join(changeRoot, fileName)).toString()); + + if (json.changes && json.changes.length) { + json.changes.forEach(change => { + if (change.type && !changeType.includes(change.type)) { + changeType.push(change.type); + } + }) + } + }); + + return changeType.includes(MAJOR) ? MAJOR : changeType.includes(MINOR) ? MINOR : PATCH; + } else { + process.exit(1); + } +} + +const checkAndUpdateNextBump = (version) => { + let nextBump = PATCH; + + if (version && NEXT_BUMPMS.includes(version)) { + nextBump = version; + } else if (version) { + nextBump = parseNextBumpFromVersion(version); + } else { + nextBump = readNextBumpFromChanges(); + } + writeNextBump(nextBump); + + return nextBump; +} + +module.exports = checkAndUpdateNextBump; diff --git a/rush.json b/rush.json index bd9826694..c928165ce 100644 --- a/rush.json +++ b/rush.json @@ -23,31 +23,36 @@ "packageName": "@visactor/vrender-components", "projectFolder": "packages/vrender-components", "tags": ["package"], - "shouldPublish": true + "shouldPublish": true, + "versionPolicyName": "vrenderMain" }, { "packageName": "@visactor/react-vrender-utils", "projectFolder": "packages/react-vrender-utils", "tags": ["package"], - "shouldPublish": true + "shouldPublish": true, + "versionPolicyName": "vrenderMain" }, { "packageName": "@visactor/react-vrender", "projectFolder": "packages/react-vrender", "tags": ["package"], - "shouldPublish": true + "shouldPublish": true, + "versionPolicyName": "vrenderMain" }, { "packageName": "@visactor/vrender-kits", "projectFolder": "packages/vrender-kits", "tags": ["package"], - "shouldPublish": true + "shouldPublish": true, + "versionPolicyName": "vrenderMain" }, { "packageName": "@visactor/vrender", "projectFolder": "packages/vrender", "tags": ["package"], - "shouldPublish": true + "shouldPublish": true, + "versionPolicyName": "vrenderMain" }, { "packageName": "@internal/bundler", From 6f12d065b011f8ebdb5447dc0a8e1faddde3b905 Mon Sep 17 00:00:00 2001 From: xile611 Date: Thu, 31 Aug 2023 14:39:16 +0800 Subject: [PATCH 2/5] chore: fix the pre-release script of vrender --- common/scripts/set-prelease-version.js | 2 +- common/scripts/version-policies.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/scripts/set-prelease-version.js b/common/scripts/set-prelease-version.js index 7541594c1..96aa16851 100644 --- a/common/scripts/set-prelease-version.js +++ b/common/scripts/set-prelease-version.js @@ -8,7 +8,7 @@ const setJsonFileByKey = require('./set-json-file'); function writePrereleaseVersion(nextBump, preReleaseName) { const rushJson = getPackageJson(path.join(__dirname, '../../rush.json')); const projects = rushJson.projects; - const mainPackage = projects.find((project) => project.packageName === '@visactor/vgrammar'); + const mainPackage = projects.find((project) => project.packageName === '@visactor/vrender'); if (!mainPackage) { return; diff --git a/common/scripts/version-policies.js b/common/scripts/version-policies.js index 87455eb46..b049a7729 100644 --- a/common/scripts/version-policies.js +++ b/common/scripts/version-policies.js @@ -43,7 +43,7 @@ const writeNextBump = ( } const readNextBumpFromChanges = () => { - const changeRoot = path.join(__dirname, '../changes/@visactor/vgrammar'); + const changeRoot = path.join(__dirname, '../changes/@visactor/vrender'); const filenames = fs.readdirSync(changeRoot); if (filenames && filenames.length) { From b2c3b6b7039d3cd68623fd25cb1de5f6ceab1383 Mon Sep 17 00:00:00 2001 From: xile611 Date: Fri, 1 Sep 2023 14:15:22 +0800 Subject: [PATCH 3/5] chore: fix parse-version and add some logs --- common/scripts/apply-prerelease-version.js | 2 ++ common/scripts/parse-version.js | 3 +-- common/scripts/set-prelease-version.js | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/scripts/apply-prerelease-version.js b/common/scripts/apply-prerelease-version.js index 7364daa97..356f7d2b6 100644 --- a/common/scripts/apply-prerelease-version.js +++ b/common/scripts/apply-prerelease-version.js @@ -6,6 +6,8 @@ function run() { const preReleaseName = process.argv.slice(2)[0]; const nextBump = checkAndUpdateNextBump(process.argv.slice(2)[1]); + console.log('[apply prerelease version]: ', preReleaseName, nextBump); + writePrereleaseVersion(nextBump, preReleaseName); } diff --git a/common/scripts/parse-version.js b/common/scripts/parse-version.js index e44c347f5..dba6f8b36 100644 --- a/common/scripts/parse-version.js +++ b/common/scripts/parse-version.js @@ -1,9 +1,8 @@ // see more about the regex here: https://semver.org/lang/zh-CN/ // reg test: https://regex101.com/r/vkijKf/1/ -const SEMVER_REG = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm; function parseVersion(version) { - const res = SEMVER_REG.exec(version); + const res = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm.exec(version); if (res) { return { diff --git a/common/scripts/set-prelease-version.js b/common/scripts/set-prelease-version.js index 96aa16851..9462bed87 100644 --- a/common/scripts/set-prelease-version.js +++ b/common/scripts/set-prelease-version.js @@ -17,7 +17,9 @@ function writePrereleaseVersion(nextBump, preReleaseName) { const mainPkgJsonPath = path.join(__dirname, '../../', mainPackage.projectFolder, 'package.json') const mainPkgJson = getPackageJson(mainPkgJsonPath) const mainVersion = mainPkgJson.version; + console.log(`The version of main project is ${mainVersion}`); const version = parseVersion(mainVersion); + console.log('Parsed version:', version); if (!version) { return; @@ -35,12 +37,15 @@ function writePrereleaseVersion(nextBump, preReleaseName) { const nextVersion = `${version.major}.${version.minor}.${version.patch}-${preReleaseName}`; const published = projects.filter(project => project.shouldPublish).map(project => project.packageName); + console.log(`next version is: ${nextVersion}`); projects.forEach(project => { const pkgJsonPath = path.join( __dirname, '../../', project.projectFolder, 'package.json') let jsonFile = fs.readFileSync(pkgJsonPath, { encoding: 'utf-8' }) const pkgJson = JSON.parse(jsonFile); + console.log(`handle project: ${project.packageName}, from ${pkgJson.version} to ${nextVersion}`); + if (project.shouldPublish) { jsonFile = setJsonFileByKey(jsonFile, pkgJson, ['version'], nextVersion); } From c6443f1dc1aa9367fb524f36eb1c84bc9f447998 Mon Sep 17 00:00:00 2001 From: xile611 Date: Fri, 1 Sep 2023 14:16:37 +0800 Subject: [PATCH 4/5] chore: update current version in version-policies.json --- common/config/rush/version-policies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/rush/version-policies.json b/common/config/rush/version-policies.json index 4c14bb215..44cc6e879 100644 --- a/common/config/rush/version-policies.json +++ b/common/config/rush/version-policies.json @@ -2,7 +2,7 @@ { "definitionName": "lockStepVersion", "policyName": "vrenderMain", - "version": "0.14.5", + "version": "0.14.7", "nextBump": "patch" } ] From bf11f2c806b46dfcef85df98716f50bcc4ba2446 Mon Sep 17 00:00:00 2001 From: xile611 Date: Mon, 4 Sep 2023 15:02:08 +0800 Subject: [PATCH 5/5] chore: fix type error in file names --- common/scripts/apply-prerelease-version.js | 2 +- common/scripts/pre-release.js | 2 +- ...-prelease-version.js => set-prerelease-version.js} | 11 +++++++++-- common/scripts/version-policies.js | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) rename common/scripts/{set-prelease-version.js => set-prerelease-version.js} (87%) diff --git a/common/scripts/apply-prerelease-version.js b/common/scripts/apply-prerelease-version.js index 356f7d2b6..39806b11b 100644 --- a/common/scripts/apply-prerelease-version.js +++ b/common/scripts/apply-prerelease-version.js @@ -1,4 +1,4 @@ -const writePrereleaseVersion = require('./set-prelease-version'); +const writePrereleaseVersion = require('./set-prerelease-version'); const checkAndUpdateNextBump = require('./version-policies'); diff --git a/common/scripts/pre-release.js b/common/scripts/pre-release.js index f1500620d..2613278bb 100644 --- a/common/scripts/pre-release.js +++ b/common/scripts/pre-release.js @@ -7,7 +7,7 @@ const { spawnSync } = require('child_process') const path = require('path') const checkAndUpdateNextBump = require('./version-policies'); const getPackageJson = require('./get-package-json'); -const writePrereleaseVersion = require('./set-prelease-version'); +const writePrereleaseVersion = require('./set-prerelease-version'); const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(alpha|beta|rc)(?:\.(?:(0|[1-9])))*)$/; diff --git a/common/scripts/set-prelease-version.js b/common/scripts/set-prerelease-version.js similarity index 87% rename from common/scripts/set-prelease-version.js rename to common/scripts/set-prerelease-version.js index 9462bed87..698c957c3 100644 --- a/common/scripts/set-prelease-version.js +++ b/common/scripts/set-prerelease-version.js @@ -28,8 +28,11 @@ function writePrereleaseVersion(nextBump, preReleaseName) { if (!version.preReleaseName) { if (nextBump === 'major') { version.major += 1; + version.minor = 0; + version.patch = 0; } else if (nextBump === 'minor') { version.minor += 1; + version.patch = 0; } else { version.patch += 1; } @@ -44,8 +47,12 @@ function writePrereleaseVersion(nextBump, preReleaseName) { let jsonFile = fs.readFileSync(pkgJsonPath, { encoding: 'utf-8' }) const pkgJson = JSON.parse(jsonFile); - console.log(`handle project: ${project.packageName}, from ${pkgJson.version} to ${nextVersion}`); - + if (project.shouldPublish) { + console.log(`handle project: ${project.packageName}, from ${pkgJson.version} to ${nextVersion}`); + } else { + console.log(`handle project: ${project.packageName}, update "dependencies" and "devDependencies" `); + } + if (project.shouldPublish) { jsonFile = setJsonFileByKey(jsonFile, pkgJson, ['version'], nextVersion); } diff --git a/common/scripts/version-policies.js b/common/scripts/version-policies.js index b049a7729..dec8fb218 100644 --- a/common/scripts/version-policies.js +++ b/common/scripts/version-policies.js @@ -17,7 +17,7 @@ const parseNextBumpFromVersion = ( if (res) { if (res.patch === 0) { - return formatted.minor == 0 ? MAJOR : MINOR; + return res.minor == 0 ? MAJOR : MINOR; } return PATCH