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..33958b907b --- /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 srcEntry = path.resolve(packageEntry, './src/index.ts'); + +function generateNextVersion() { + const versionCode = `\nexport const version = '${nextVersion}';\n`; + fs.writeFileSync(srcEntry, 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 ${srcEntry}`, { 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"