Skip to content

Commit

Permalink
ci(workflows): added automatic upgrade function for external test pac…
Browse files Browse the repository at this point in the history
…kages (#2804)

* fix: fix alpha publish error

* ci(workflows): added automatic upgrade function for external test packages

* ci(workflows): added automatic upgrade function for external test packages
  • Loading branch information
zzcr authored Jan 15, 2025
1 parent 9a71be6 commit 6d8081a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ jobs:
throw new Error('请输入正确的包名称')
}
if (!branchName.includes('release-3.')) {
throw new Error('请使用release-3.xx.xx分支发布正式包')
}
- name: CheckOut Code
uses: actions/checkout@master
with:
Expand Down Expand Up @@ -85,7 +81,7 @@ jobs:
run: pnpm build:runtime

- name: Run Release alpha
run: pnpm release:alpha
run: pnpm release:alpha -u

- name: Publish
run: |
Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/dispatch-ui-publish-alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ jobs:
build:
runs-on: windows-latest
steps:
- name: Parse Components
id: parseComponents
uses: actions/github-script@v6
with:
script: |
const branchName = `${{ github.ref_name }}`
if (!branchName.includes('release-3.')) {
throw new Error('请使用release-3.xx.xx分支发布正式包')
}
- name: CheckOut Code
uses: actions/checkout@master
with:
Expand Down Expand Up @@ -63,7 +52,7 @@ jobs:
run: pnpm build:ui ${{ inputs.components }}

- name: Run Release alpha
run: pnpm release:alpha
run: pnpm release:alpha -u

- name: Publish
run: |
Expand Down
36 changes: 30 additions & 6 deletions internals/cli/src/commands/release/releaseAlpha.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
import { pathFromPackages } from '../build/build-ui'
import path from 'node:path'
import fs from 'fs-extra'
import semver from 'semver'
import { execSync } from 'node:child_process'

const excludeFiles = ['.png', '.gif', '.jpeg', '.jpg', '.ttf', 'node_modules']

/**
* @param {string} packageName 包名
* @param {string} version 原始版本号
* @returns {string} 自动升级patch版本后的版本号
*/
const getPatchVersion = (packageName: string, version: string): string => {
try {
// 防止测试仓库没有发布过该包,导致获取不到版本号
const npmVersion = execSync(`npm v ${packageName} version`).toString('utf-8').replace(/\n/, '')
const updateVersion = version.startsWith('2.') ? `2${npmVersion.slice(1)}` : npmVersion
return semver.inc(updateVersion, 'patch')
} catch (error) {
return version
}
}

// 递归遍历所有的组件,然后依次修改文件内容
const findAllpage = (packagesPath) => {
const findAllpage = (packagesPath, updateVersion) => {
if (excludeFiles.some((item) => packagesPath.includes(item)) || !fs.existsSync(packagesPath)) {
return
}

if (fs.statSync(packagesPath).isDirectory()) {
// 循环递归查找子文件夹
fs.readdirSync(packagesPath).forEach((childPatch) => {
findAllpage(path.join(packagesPath, childPatch))
findAllpage(path.join(packagesPath, childPatch), updateVersion)
})
} else {
const content = fs.readFileSync(packagesPath).toString('UTF-8' as BufferEncoding)
let result = content.replace(/@opentiny\/vue/g, '@opentinyvue/vue')
const result = content.replace(/@opentiny\/vue/g, '@opentinyvue/vue')

fs.writeFileSync(packagesPath, result)
if (packagesPath.endsWith('package.json') && updateVersion) {
const packageJSON = JSON.parse(result)
packageJSON.version = getPatchVersion(packageJSON.name, packageJSON.version)
fs.writeFileSync(packagesPath, JSON.stringify(packageJSON, null, 2) + '\n')
} else {
fs.writeFileSync(packagesPath, result)
}
}
}

export const releaseAlpha = () => {
export const releaseAlpha = ({ updateVersion }) => {
const distLists = ['dist3/', 'dist2/', 'renderless/dist', 'theme/dist', 'theme-mobile/dist', 'theme-saas/dist']
distLists.forEach((item) => {
findAllpage(pathFromPackages(item))
findAllpage(pathFromPackages(item), updateVersion)
})
}
6 changes: 5 additions & 1 deletion internals/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const program = new Command()

program.command('release:aurora').description('转换为aurora的包').action(releaseAurora)

program.command('release:alpha').description('转换为组织名为@opentinyvue的包').action(releaseAlpha)
program
.command('release:alpha')
.description('转换为组织名为@opentinyvue的包')
.option('-u, --updateVersion', '是否自动升级patch版本号', false)
.action(releaseAlpha)

program.command('create:icon-saas').description('同步生成 icon-saas').action(createIconSaas)

Expand Down

0 comments on commit 6d8081a

Please sign in to comment.