From 83b8346c658c5098dee7a2c169f41141168c88d7 Mon Sep 17 00:00:00 2001 From: ajaxzheng <894103554@qq.com> Date: Mon, 13 Jan 2025 19:43:59 +0800 Subject: [PATCH] ci(workflows): add script for full release of alpha test package (#2785) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ci(workflows): add script for full release of alpha test package * fix: 修复检视意见 --- .../workflows/dispatch-all-publish-alpha.yml | 91 +++++++++++++++++++ internals/cli/package.json | 1 + .../cli/src/commands/release/releaseAlpha.ts | 31 +++++++ internals/cli/src/index.ts | 3 + package.json | 1 + 5 files changed, 127 insertions(+) create mode 100644 .github/workflows/dispatch-all-publish-alpha.yml create mode 100644 internals/cli/src/commands/release/releaseAlpha.ts diff --git a/.github/workflows/dispatch-all-publish-alpha.yml b/.github/workflows/dispatch-all-publish-alpha.yml new file mode 100644 index 0000000000..2cc150db04 --- /dev/null +++ b/.github/workflows/dispatch-all-publish-alpha.yml @@ -0,0 +1,91 @@ +name: Dispatch All Publish Alpha +run-name: Dispatch All Publish Alpha--${{ inputs.version }} + +on: + workflow_dispatch: + inputs: + version: + description: | + 输入您将要发布的版本号, + 例如: `3.xx.xx`. + required: true + type: string +concurrency: + group: ${{ github.workflow }}-${{ github.sha }} + cancel-in-progress: true + +jobs: + build: + runs-on: windows-latest + outputs: + publishVersion: ${{ steps.parseVersion.outputs.publishVersion }} + steps: + - name: Parse Version + id: parseVersion + uses: actions/github-script@v6 + with: + script: | + const version = `${{ inputs.version }}` + if(!/^\d\.\d+\.\d+/.test(vserion)) { + throw new Error('版本号格式不正确') + } + const publishVersion = version.slice(2) + core.setOutput('publishVersion', publishVersion) + + - name: CheckOut Code + uses: actions/checkout@master + with: + ref: ${{ github.ref_name }} + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 20.10.0 + registry-url: 'https://registry.npmjs.org' + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm i --no-frozen-lockfile + + - name: Run Build Components + run: pnpm build:ui -t ${{ steps.parseVersion.outputs.publishVersion }} + + - name: Run Build Sass Common + run: pnpm build:ui saas-common -t ${{ steps.parseVersion.outputs.publishVersion }} -d saas + + - name: Run Build Theme + run: pnpm build:theme + + - name: Run Build Renderless + run: pnpm build:renderless + + - name: Run Build ThemeSaas + run: pnpm build:themeSaas + + - name: Run Build ThemeMobile + run: pnpm build:themeMobile + + - name: Run Build Runtime + run: pnpm build:runtime + + - name: Run Release alpha + run: pnpm release:alpha + + - name: Publish Vue3 And Vue2 components + run: pnpm pub:all + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_OPENTINY_VUE_TOKEN }} diff --git a/internals/cli/package.json b/internals/cli/package.json index d45d063d03..545cfde815 100644 --- a/internals/cli/package.json +++ b/internals/cli/package.json @@ -21,6 +21,7 @@ "build:runtime": "pnpm build:entry-app && esno src/index.ts build:runtime", "// ---------------------全局适配@aurora包名--------------------- ": "", "release:aurora": "esno src/index.ts release:aurora", + "release:alpha": "esno src/index.ts release:alpha", "// ----------------------辅助脚本---------------------- ": "", "create:ui": "esno src/commands/create/create-ui.ts", "sync-icons": "esno src/commands/create/sync-icons.ts", diff --git a/internals/cli/src/commands/release/releaseAlpha.ts b/internals/cli/src/commands/release/releaseAlpha.ts new file mode 100644 index 0000000000..671fd1d8e7 --- /dev/null +++ b/internals/cli/src/commands/release/releaseAlpha.ts @@ -0,0 +1,31 @@ +import { pathFromPackages } from '../build/build-ui' +import path from 'node:path' +import fs from 'fs-extra' + +const excludeFiles = ['.png', '.gif', '.jpeg', '.jpg', '.ttf', 'node_modules'] + +// 递归遍历所有的组件,然后依次修改文件内容 +const findAllpage = (packagesPath) => { + 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)) + }) + } else { + const content = fs.readFileSync(packagesPath).toString('UTF-8' as BufferEncoding) + let result = content.replace(/@opentiny\/vue/g, '@opentinyvue/vue') + + fs.writeFileSync(packagesPath, result) + } +} + +export const releaseAlpha = () => { + const distLists = ['dist3/', 'dist2/', 'renderless/dist', 'theme/dist', 'theme-mobile/dist', 'theme-saas/dist'] + distLists.forEach((item) => { + findAllpage(pathFromPackages(item)) + }) +} diff --git a/internals/cli/src/index.ts b/internals/cli/src/index.ts index 25252a8112..1ff28b04d3 100644 --- a/internals/cli/src/index.ts +++ b/internals/cli/src/index.ts @@ -3,11 +3,14 @@ import { Command, Option } from 'commander' import { createIconSaas } from './commands/create/index.js' import { buildUi, buildEntry, buildRuntime, buildReact, buildEntryReact, chartTheme } from './commands/build' import { releaseAurora } from './commands/release/releaseAurora' +import { releaseAlpha } from './commands/release/releaseAlpha' const program = new Command() program.command('release:aurora').description('转换为aurora的包').action(releaseAurora) +program.command('release:alpha').description('转换为组织名为@opentinyvue的包').action(releaseAlpha) + program.command('create:icon-saas').description('同步生成 icon-saas').action(createIconSaas) program.command('build:entry-react').description('生成 react 组件库入口').action(buildEntryReact) diff --git a/package.json b/package.json index c0e8221ec5..44b48addf3 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "build:virtual-template": "pnpm --filter @opentiny-internal/unplugin-virtual-template build", "build:site": "pnpm i -g pnpm && pnpm build:vite-import && pnpm build:virtual-template && pnpm -C examples/sites build", "release:aurora": "pnpm -C internals/cli release:aurora", + "release:alpha": "pnpm -C internals/cli release:alpha", "// ---------- 使用pnpm批量发布npm包 ----------": "", "pub2": "pnpm --filter=\"./packages/dist2/**\" publish --tag v2-latest --no-git-checks --access=public", "pub3": "pnpm --filter=\"./packages/dist3/**\" publish --no-git-checks --access=public",