ci: check changed-file formatting (#557)

This commit is contained in:
InfinityPacer
2026-07-18 16:48:25 +08:00
committed by GitHub
parent 52479ebbd5
commit 395401e493
6 changed files with 180 additions and 37 deletions
+22
View File
@@ -0,0 +1,22 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
const workflowPath = resolve(process.cwd(), '.github/workflows/test.yml')
describe('前端 Pull Request workflow', () => {
it('使用只读的变更文件格式检查,并显式比较事件 base/head SHA', () => {
const workflow = readFileSync(workflowPath, 'utf8')
const formatJob = workflow.match(/\n {2}format:\n(?<job>[\s\S]*?)(?=\n {2}[\w-]+:\n|$)/)?.groups?.job
expect(workflow).toContain('permissions:\n contents: read')
expect(formatJob).toBeDefined()
expect(formatJob).toContain('fetch-depth: 0')
expect(formatJob).toContain("node-version: '24'")
expect(formatJob).toContain('run: yarn --frozen-lockfile')
expect(formatJob).toContain('BASE_SHA: ${{ github.event.pull_request.base.sha }}')
expect(formatJob).toContain('HEAD_SHA: ${{ github.event.pull_request.head.sha }}')
expect(formatJob).toContain('run: yarn format:check --base "$BASE_SHA" --head "$HEAD_SHA"')
expect(formatJob).not.toContain('--write')
})
})