forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cocos#8885 from cocos-creator/v3.2.0
support engine version validation (cocos#8874)
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fs = require('fs'); | ||
const ps = require('path'); | ||
const vGit = require('v-git'); | ||
|
||
const repo = vGit.init(ps.join(__dirname, '../')); | ||
const branchName = repo.branch; | ||
const branchRegExp = /^v?(\d+\.\d+\.\d+)(?:-.*)?$/ | ||
const matchResult = branchName.match(branchRegExp); | ||
if (!(matchResult && matchResult[1])) { | ||
console.warn(`Invalid branch name: "${branchName}", skip engine version validation.`) | ||
process.exit(0); | ||
} | ||
const branchVersion = matchResult[1]; | ||
|
||
const versionRegExpMap = { | ||
'./package.json': /"version": "(.*)"/, | ||
'./cocos/core/global-exports.ts': /engineVersion = '(.*)'/, | ||
}; | ||
for (filePath in versionRegExpMap) { | ||
const regExp = versionRegExpMap[filePath]; | ||
const content = fs.readFileSync(filePath, 'utf8'); | ||
const version = content.match(regExp)[1]; | ||
if (version !== branchVersion) { | ||
console.error(`Wrong engine version "${version}" in file "${filePath}", need to match branch name "${branchName}".`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
console.log('Engine version validation complete!'); | ||
process.exit(0); |