Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
zzcr marked this conversation as resolved.
Show resolved Hide resolved

// 递归遍历所有的组件,然后依次修改文件内容
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)
}
zzcr marked this conversation as resolved.
Show resolved Hide resolved
}
zzcr marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading