ci(v3): publish frontend from v3

This commit is contained in:
jxxghp
2026-08-07 22:08:37 +08:00
parent 6afa2bdc8a
commit 95674fa47a
8 changed files with 31 additions and 20 deletions

View File

@@ -20,7 +20,7 @@ function write(repository: string, filePath: string, content: string) {
function createRepository() {
const repository = mkdtempSync(resolve(tmpdir(), 'moviepilot-format-changed-'))
temporaryRepositories.push(repository)
git(repository, 'init', '--initial-branch=v2')
git(repository, 'init', '--initial-branch=v3')
git(repository, 'config', 'user.name', 'Format Test')
git(repository, 'config', 'user.email', 'format-test@example.invalid')
write(repository, '.gitignore', 'coverage/\n')
@@ -73,7 +73,7 @@ describe('Prettier 变更文件选择器', () => {
git(repository, 'add', '-A')
git(repository, 'commit', '-m', 'feature')
expect(listSelected(repository, '--base', 'v2', '--head', 'HEAD')).toEqual([
expect(listSelected(repository, '--base', 'v3', '--head', 'HEAD')).toEqual([
'src/line\nbreak.ts',
'src/modified.ts',
'src/new file.vue',
@@ -137,7 +137,7 @@ describe('Prettier 变更文件选择器', () => {
write(repository, 'src/modified.ts', "export const value='feature'\n")
git(repository, 'add', 'src/modified.ts')
git(repository, 'commit', '-m', 'feature')
git(repository, 'tag', 'v2', 'HEAD')
git(repository, 'tag', 'v3', 'HEAD')
expect(listSelected(repository)).toEqual(['src/modified.ts'])
})
@@ -154,8 +154,8 @@ describe('Prettier 变更文件选择器', () => {
cwd: repository,
encoding: 'utf8',
}).trim()
git(repository, 'update-ref', 'refs/remotes/upstream/v2', unrelatedCommit)
git(repository, 'update-ref', 'refs/remotes/origin/v2', baseCommit)
git(repository, 'update-ref', 'refs/remotes/upstream/v3', unrelatedCommit)
git(repository, 'update-ref', 'refs/remotes/origin/v3', baseCommit)
expect(listSelected(repository)).toEqual(['src/modified.ts'])
})
@@ -174,7 +174,7 @@ describe('Prettier 变更文件选择器', () => {
git(repository, 'add', '-A')
git(repository, 'commit', '-m', 'type changes')
expect(listSelected(repository, '--base', 'v2', '--head', 'HEAD')).toEqual(['src/to-regular.ts'])
expect(listSelected(repository, '--base', 'v3', '--head', 'HEAD')).toEqual(['src/to-regular.ts'])
})
it('Git 路径输出超过默认缓冲区时仍能完成选择', () => {

View File

@@ -3,19 +3,20 @@ import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
const workflowPath = resolve(process.cwd(), '.github/workflows/test.yml')
const releaseWorkflowPath = resolve(process.cwd(), '.github/workflows/build.yml')
const testingGuidePath = resolve(process.cwd(), 'docs/testing.md')
const codeQualityGuidePath = resolve(process.cwd(), 'docs/code-quality.md')
describe('前端测试 workflow', () => {
it('在 PR 与 v2 push 上运行,并将变更文件格式检查限制为 PR', () => {
it('在 PR 与 v3 push 上运行,并将变更文件格式检查限制为 PR', () => {
const workflow = readFileSync(workflowPath, 'utf8')
const formatJob = workflow.match(/\n {2}format:\n(?<job>[\s\S]*?)(?=\n {2}[\w-]+:\n|$)/)?.groups?.job
const qualityJob = workflow.match(/\n {2}typecheck-and-coverage:\n(?<job>[\s\S]*?)(?=\n {2}[\w-]+:\n|$)/)?.groups
?.job
expect(workflow).toContain('permissions:\n contents: read')
expect(workflow).toContain('pull_request:\n branches:\n - v2')
expect(workflow).toContain('push:\n branches:\n - v2')
expect(workflow).toContain('pull_request:\n branches:\n - v3')
expect(workflow).toContain('push:\n branches:\n - v3')
expect(workflow).toContain('group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}')
expect(formatJob).toBeDefined()
expect(formatJob).toContain("if: github.event_name == 'pull_request'")
@@ -37,10 +38,20 @@ describe('前端测试 workflow', () => {
const codeQualityGuide = readFileSync(codeQualityGuidePath, 'utf8')
expect(testingGuide).toContain('`typecheck-and-coverage` job')
expect(testingGuide).toContain('推送到 `v2`')
expect(testingGuide).toContain('推送到 `v3`')
expect(testingGuide).toContain('只在 Pull Request 事件运行')
expect(codeQualityGuide).toContain('lint 与 `typecheck-and-coverage` 使用不同 job')
expect(testingGuide).not.toContain('`unit-tests`')
expect(codeQualityGuide).not.toContain('`unit-tests`')
})
it('V3 前端发布只由 v3 分支上的版本变更触发', () => {
const workflow = readFileSync(releaseWorkflowPath, 'utf8')
expect(workflow).toContain('name: Build Moviepilot-Frontend v3')
expect(workflow).toContain('push:\n branches:\n - v3')
expect(workflow).toContain(" - 'package.json'")
expect(workflow).toContain('echo "frontend_version=v$frontend_version"')
expect(workflow).not.toContain(' - v2')
})
})