From 4dbf3d3b1b409e8279c17fa89831457d1245abbb Mon Sep 17 00:00:00 2001 From: * <8> Date: Tue, 2 Aug 2022 11:30:29 +0800 Subject: [PATCH] Match-id-7ab6cb252d727ba6c0b5191e9eaca0fb9f0cfcb3 --- .cloudbuild/CI.sh | 2 - .cloudbuild/build.yml | 6 ++- .cloudbuild/release.js | 80 +++++++++++++++++++++++++++++++ .cloudbuild/{tag.yml => test.yml} | 17 +++++-- 4 files changed, 97 insertions(+), 8 deletions(-) delete mode 100644 .cloudbuild/CI.sh create mode 100644 .cloudbuild/release.js rename .cloudbuild/{tag.yml => test.yml} (54%) diff --git a/.cloudbuild/CI.sh b/.cloudbuild/CI.sh deleted file mode 100644 index 7972c069..00000000 --- a/.cloudbuild/CI.sh +++ /dev/null @@ -1,2 +0,0 @@ -yarn -yarn run test diff --git a/.cloudbuild/build.yml b/.cloudbuild/build.yml index 01ece498..b6fcaac9 100644 --- a/.cloudbuild/build.yml +++ b/.cloudbuild/build.yml @@ -19,7 +19,8 @@ env: - type: workspace steps: PRE_BUILD: - - checkout + - checkout: + path: horizon-core - gitlab: url: https://szv-y.codehub.huawei.com/CloudSOP/CloudSOP-CI.git branch: $branch @@ -29,5 +30,8 @@ steps: command: | npm install yarn -g yarn config set strict-ssl false + cd horizon-core yarn yarn run test + yarn run build + node .cloudbuild/release.js diff --git a/.cloudbuild/release.js b/.cloudbuild/release.js new file mode 100644 index 00000000..d7012513 --- /dev/null +++ b/.cloudbuild/release.js @@ -0,0 +1,80 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. + */ + +const fs = require('fs'); +const path = require('path'); +const childProcess = require('child_process'); + +const version = process.env.releaseVersion; +const HORIZON_PACKAGE_JSON = path.resolve(__dirname, '../libs/horizon/package.json'); +const DIST_PATH = path.resolve(__dirname, '../build/horizon'); + +const NPMRC = `registry=https://cmc.centralrepo.rnd.huawei.com/npm +@cloudsop:registry=https://cmc.centralrepo.rnd.huawei.com/artifactory/product_npm +_auth = Y2xvdWRzb3BhcnRpZmFjdG9yeTpDbG91ZHNvcDY2NiEhIQ +always-auth = true +email = cloudsop@huawei.com +`; +if (!version) { + return; +} +if (!/\d+\.\d+\.\d+/.test(version)) { + console.log('请输入正确版本号'); + return; +} + +const exec = (cmd, cwd) => { + return new Promise((resolve, reject) => { + childProcess.exec( + cmd, + { + cwd, + }, + function (error, stdout, stderr) { + if (error) { + error && console.log(`Error: ${error}`); + reject(error); + } else { + stdout && console.log(`STDOUT: ${stdout}`); + resolve(stdout); + } + } + ); + }); +}; + + +const writeVersion = version => { + return new Promise((resolve, reject) => { + const file = HORIZON_PACKAGE_JSON; + fs.readFile(file, 'utf8', function (err, data) { + if (err) { + console.log(`${file}: write version failed`); + reject(err); + } + const packageJson = JSON.parse(data); + packageJson.version = version; + fs.writeFileSync(file, JSON.stringify(packageJson, null, 2)); + resolve(); + }); + }); +}; + +const main = async () => { + console.log(`==== Horizon Upgrade ${version} ====`); + await writeVersion(version); + + if (!version.includes('SNAPSHOT')) { + console.log('==== Create git tag ====='); + const tagName = `v${version}-h1`; + await exec(`git tag ${tagName}`); + await exec('git push --tags'); + } + + fs.writeFileSync(path.resolve(DIST_PATH, '.npmrc'), NPMRC); + + console.log('==== Publish new version===='); + await exec('npm publish', DIST_PATH); +}; +main(); diff --git a/.cloudbuild/tag.yml b/.cloudbuild/test.yml similarity index 54% rename from .cloudbuild/tag.yml rename to .cloudbuild/test.yml index 4b562f49..0593afd8 100644 --- a/.cloudbuild/tag.yml +++ b/.cloudbuild/test.yml @@ -19,12 +19,19 @@ env: - type: workspace steps: PRE_BUILD: - - checkout + - checkout: + path: horizon-core - gitlab: - url: https://szv-y.codehub.huawei.com/CloudSOP/CloudSOP-CI.git - branch: $branch - path: CI + url: https://szv-open.codehub.huawei.com/innersource/shanhai/wutong/react/horizon-test.git + branch: one_tree_dev + path: horizon-test BUILD: - build_execute: command: | - git tag $releaseVersion + npm install yarn -g + yarn config set strict-ssl false + cd horizon-core + yarn + cd ../horizon-test + yarn + yarn run test