mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 09:06:56 +08:00
test: limit web diff coverage to current push range (#33523)
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
This commit is contained in:
parent
57d476d4e2
commit
0d72d99263
5
.github/workflows/main-ci.yml
vendored
5
.github/workflows/main-ci.yml
vendored
@ -63,8 +63,9 @@ jobs:
|
|||||||
if: needs.check-changes.outputs.web-changed == 'true'
|
if: needs.check-changes.outputs.web-changed == 'true'
|
||||||
uses: ./.github/workflows/web-tests.yml
|
uses: ./.github/workflows/web-tests.yml
|
||||||
with:
|
with:
|
||||||
base_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
|
base_sha: ${{ github.event.before || github.event.pull_request.base.sha }}
|
||||||
head_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
|
diff_range_mode: ${{ github.event.before && 'exact' || 'merge-base' }}
|
||||||
|
head_sha: ${{ github.event.after || github.event.pull_request.head.sha || github.sha }}
|
||||||
|
|
||||||
style-check:
|
style-check:
|
||||||
name: Style Check
|
name: Style Check
|
||||||
|
|||||||
4
.github/workflows/web-tests.yml
vendored
4
.github/workflows/web-tests.yml
vendored
@ -6,6 +6,9 @@ on:
|
|||||||
base_sha:
|
base_sha:
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
|
diff_range_mode:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
head_sha:
|
head_sha:
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
@ -89,6 +92,7 @@ jobs:
|
|||||||
- name: Check app/components diff coverage
|
- name: Check app/components diff coverage
|
||||||
env:
|
env:
|
||||||
BASE_SHA: ${{ inputs.base_sha }}
|
BASE_SHA: ${{ inputs.base_sha }}
|
||||||
|
DIFF_RANGE_MODE: ${{ inputs.diff_range_mode }}
|
||||||
HEAD_SHA: ${{ inputs.head_sha }}
|
HEAD_SHA: ${{ inputs.head_sha }}
|
||||||
run: node ./scripts/check-components-diff-coverage.mjs
|
run: node ./scripts/check-components-diff-coverage.mjs
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
buildGitDiffRevisionArgs,
|
||||||
getChangedBranchCoverage,
|
getChangedBranchCoverage,
|
||||||
getChangedStatementCoverage,
|
getChangedStatementCoverage,
|
||||||
getIgnoredChangedLinesFromSource,
|
getIgnoredChangedLinesFromSource,
|
||||||
@ -7,6 +8,11 @@ import {
|
|||||||
} from '../scripts/check-components-diff-coverage-lib.mjs'
|
} from '../scripts/check-components-diff-coverage-lib.mjs'
|
||||||
|
|
||||||
describe('check-components-diff-coverage helpers', () => {
|
describe('check-components-diff-coverage helpers', () => {
|
||||||
|
it('should build exact and merge-base git diff revision args', () => {
|
||||||
|
expect(buildGitDiffRevisionArgs('base-sha', 'head-sha', 'exact')).toEqual(['base-sha', 'head-sha'])
|
||||||
|
expect(buildGitDiffRevisionArgs('base-sha', 'head-sha')).toEqual(['base-sha...head-sha'])
|
||||||
|
})
|
||||||
|
|
||||||
it('should parse changed line maps from unified diffs', () => {
|
it('should parse changed line maps from unified diffs', () => {
|
||||||
const diff = [
|
const diff = [
|
||||||
'diff --git a/web/app/components/share/a.ts b/web/app/components/share/a.ts',
|
'diff --git a/web/app/components/share/a.ts b/web/app/components/share/a.ts',
|
||||||
|
|||||||
@ -3,6 +3,12 @@ import path from 'node:path'
|
|||||||
|
|
||||||
const DIFF_COVERAGE_IGNORE_LINE_TOKEN = 'diff-coverage-ignore-line:'
|
const DIFF_COVERAGE_IGNORE_LINE_TOKEN = 'diff-coverage-ignore-line:'
|
||||||
|
|
||||||
|
export function buildGitDiffRevisionArgs(base, head, mode = 'merge-base') {
|
||||||
|
return mode === 'exact'
|
||||||
|
? [base, head]
|
||||||
|
: [`${base}...${head}`]
|
||||||
|
}
|
||||||
|
|
||||||
export function parseChangedLineMap(diff, isTrackedComponentSourceFile) {
|
export function parseChangedLineMap(diff, isTrackedComponentSourceFile) {
|
||||||
const lineMap = new Map()
|
const lineMap = new Map()
|
||||||
let currentFile = null
|
let currentFile = null
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { execFileSync } from 'node:child_process'
|
|||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import {
|
import {
|
||||||
|
buildGitDiffRevisionArgs,
|
||||||
getChangedBranchCoverage,
|
getChangedBranchCoverage,
|
||||||
getChangedStatementCoverage,
|
getChangedStatementCoverage,
|
||||||
getIgnoredChangedLinesFromFile,
|
getIgnoredChangedLinesFromFile,
|
||||||
@ -24,6 +25,7 @@ const APP_COMPONENTS_COVERAGE_PREFIX = 'app/components/'
|
|||||||
const SHARED_TEST_PREFIX = 'web/__tests__/'
|
const SHARED_TEST_PREFIX = 'web/__tests__/'
|
||||||
const STRICT_TEST_FILE_TOUCH = process.env.STRICT_COMPONENT_TEST_TOUCH === 'true'
|
const STRICT_TEST_FILE_TOUCH = process.env.STRICT_COMPONENT_TEST_TOUCH === 'true'
|
||||||
const EXCLUDED_MODULES_LABEL = [...EXCLUDED_COMPONENT_MODULES].sort().join(', ')
|
const EXCLUDED_MODULES_LABEL = [...EXCLUDED_COMPONENT_MODULES].sort().join(', ')
|
||||||
|
const DIFF_RANGE_MODE = process.env.DIFF_RANGE_MODE === 'exact' ? 'exact' : 'merge-base'
|
||||||
|
|
||||||
const repoRoot = repoRootFromCwd()
|
const repoRoot = repoRootFromCwd()
|
||||||
const webRoot = path.join(repoRoot, 'web')
|
const webRoot = path.join(repoRoot, 'web')
|
||||||
@ -216,6 +218,7 @@ function buildSummary({
|
|||||||
'### app/components Diff Coverage',
|
'### app/components Diff Coverage',
|
||||||
'',
|
'',
|
||||||
`Compared \`${baseSha.slice(0, 12)}\` -> \`${headSha.slice(0, 12)}\``,
|
`Compared \`${baseSha.slice(0, 12)}\` -> \`${headSha.slice(0, 12)}\``,
|
||||||
|
`Diff range mode: \`${DIFF_RANGE_MODE}\``,
|
||||||
'',
|
'',
|
||||||
`Excluded modules: \`${EXCLUDED_MODULES_LABEL}\``,
|
`Excluded modules: \`${EXCLUDED_MODULES_LABEL}\``,
|
||||||
`Excluded file kinds: \`${COMPONENT_COVERAGE_EXCLUDE_LABEL}\``,
|
`Excluded file kinds: \`${COMPONENT_COVERAGE_EXCLUDE_LABEL}\``,
|
||||||
@ -365,7 +368,7 @@ function buildSkipSummary(changedExcludedSourceFiles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getChangedFiles(base, head) {
|
function getChangedFiles(base, head) {
|
||||||
const output = execGit(['diff', '--name-only', '--diff-filter=ACMR', `${base}...${head}`, '--', 'web/app/components', 'web/__tests__'])
|
const output = execGit(['diff', '--name-only', '--diff-filter=ACMR', ...buildGitDiffRevisionArgs(base, head, DIFF_RANGE_MODE), '--', 'web/app/components', 'web/__tests__'])
|
||||||
return output
|
return output
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(line => line.trim())
|
.map(line => line.trim())
|
||||||
@ -373,7 +376,7 @@ function getChangedFiles(base, head) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getChangedLineMap(base, head) {
|
function getChangedLineMap(base, head) {
|
||||||
const diff = execGit(['diff', '--unified=0', '--no-color', '--diff-filter=ACMR', `${base}...${head}`, '--', 'web/app/components'])
|
const diff = execGit(['diff', '--unified=0', '--no-color', '--diff-filter=ACMR', ...buildGitDiffRevisionArgs(base, head, DIFF_RANGE_MODE), '--', 'web/app/components'])
|
||||||
return parseChangedLineMap(diff, isTrackedComponentSourceFile)
|
return parseChangedLineMap(diff, isTrackedComponentSourceFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user