From fe82a9037f8f7d6b61207d32112e84d21c052fd6 Mon Sep 17 00:00:00 2001 From: wjgogogo <906626481@qq.com> Date: Thu, 14 Dec 2023 10:14:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E8=87=AA=E5=8A=A8=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E5=89=8D,=20=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E5=88=B0=E6=89=93=E5=8C=85=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto-release.yml | 4 +-- .releaserc.base.js | 16 +++++++++--- package.json | 1 + scripts/add-version.js | 42 ++++++++++++++++++++++++++++++ yarn.lock | 12 +++++++++ 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 scripts/add-version.js diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index d9bdec78bf..97cc405999 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -50,8 +50,8 @@ jobs: - name: Install dependencies run: yarn - - name: Build - run: yarn build + # - name: Build + # run: yarn build # 自动发布完成后 触发 github.release.published 事件 # 如果是 action 自带的 机器人 token, 出于安全考虑, github 会禁止循环触发, 使用真实用户的 token 可解决这个问题 diff --git a/.releaserc.base.js b/.releaserc.base.js index 29d4c0ef0e..544d514383 100644 --- a/.releaserc.base.js +++ b/.releaserc.base.js @@ -1,11 +1,13 @@ +const path = require('path'); + module.exports = { + extends: 'semantic-release-monorepo', branches: [ 'latest', { name: 'beta', channel: 'beta', prerelease: true }, { name: 'alpha', channel: 'alpha', prerelease: true }, { name: 'next', channel: 'next', prerelease: true }, ], - extends: 'semantic-release-monorepo', plugins: [ [ '@semantic-release/commit-analyzer', @@ -26,11 +28,19 @@ module.exports = { '@semantic-release/npm', [ '@semantic-release/git', - { + { message: 'chore(release): 🤖 ${nextRelease.gitTag} [skip ci]', - }, + }, ], '@semantic-release/github', + [ + '@semantic-release/exec', + { + prepareCmd: + `node ${path.resolve(__dirname, './scripts/add-version.js')} ` + + '${nextRelease.gitTag}', + }, + ], ], preset: 'angular', }; diff --git a/package.json b/package.json index 873bc44619..9cffc671cb 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "@rollup/plugin-typescript": "^8.2.5", "@rushstack/eslint-patch": "^1.1.3", "@semantic-release/changelog": "^6.0.1", + "@semantic-release/exec": "^6.0.3", "@semantic-release/git": "^10.0.1", "@size-limit/esbuild": "^11.0.0", "@size-limit/esbuild-why": "^11.0.0", diff --git a/scripts/add-version.js b/scripts/add-version.js new file mode 100644 index 0000000000..9ffe8de4b1 --- /dev/null +++ b/scripts/add-version.js @@ -0,0 +1,42 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const nextVersion = process.argv[2]; + +const packageEntry = process.cwd(); + +const packageName = path.basename(packageEntry); +const scrEntry = path.resolve(packageEntry, './src/index.ts'); + +function generateNextVersion() { + const versionCode = `\nexport const version = '${nextVersion}';\n`; + fs.writeFileSync(scrEntry, versionCode, { encoding: 'utf8', flag: 'a+' }); +} + +function build() { + // 直接运行 yarn build 要报错,用一下蠢办法 + execSync(`yarn clean`, { + stdio: 'inherit', + }); + + execSync(`yarn build:umd & yarn build:cjs & yarn build:esm`, { + stdio: 'inherit', + }); + + execSync(`yarn dts:build && yarn dts:extract`, { + stdio: 'inherit', + }); +} + +function restoreVersionChange() { + execSync(`git restore ${scrEntry}`, { stdio: 'inherit' }); +} + +console.log(`🔖 ${packageName} 添加 nextVersion: ${nextVersion}\n`); + +generateNextVersion(); +build(); +restoreVersionChange(); + +console.log(`✅ ${packageName} nextVersion(${nextVersion}) 添加成功 \n`); diff --git a/yarn.lock b/yarn.lock index 34ed584dd2..3667e8b38a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2550,6 +2550,18 @@ resolved "https://registry.yarnpkg.com/@semantic-release/error/-/error-3.0.0.tgz#30a3b97bbb5844d695eb22f9d3aa40f6a92770c2" integrity sha512-5hiM4Un+tpl4cKw3lV4UgzJj+SmfNIDCLLw0TepzQxz9ZGV5ixnqkzIVF+3tp0ZHgcMKE+VNGHJjEeyFG2dcSw== +"@semantic-release/exec@^6.0.3": + version "6.0.3" + resolved "https://registry.npmmirror.com/@semantic-release/exec/-/exec-6.0.3.tgz#d212fdf19633bdfb553de6cb6c7f8781933224db" + integrity sha512-bxAq8vLOw76aV89vxxICecEa8jfaWwYITw6X74zzlO0mc/Bgieqx9kBRz9z96pHectiTAtsCwsQcUyLYWnp3VQ== + dependencies: + "@semantic-release/error" "^3.0.0" + aggregate-error "^3.0.0" + debug "^4.0.0" + execa "^5.0.0" + lodash "^4.17.4" + parse-json "^5.0.0" + "@semantic-release/git@^10.0.1": version "10.0.1" resolved "https://registry.yarnpkg.com/@semantic-release/git/-/git-10.0.1.tgz#c646e55d67fae623875bf3a06a634dd434904498"