Skip to content

Commit

Permalink
- significantly lower scope of search for globber (limit by workspace…
Browse files Browse the repository at this point in the history
… root)

  - FIX #1251
  • Loading branch information
mikepenz committed Nov 28, 2024
1 parent a427a90 commit d0dd48d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
34 changes: 30 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as glob from '@actions/glob'
import * as fs from 'fs'
import * as parser from 'xml-js'
import * as pathHelper from 'path'
import {applyTransformer} from './utils'
import {applyTransformer, removePrefix} from './utils'

export interface ActualTestResult {
name: string
Expand Down Expand Up @@ -124,14 +124,29 @@ function safeParseInt(line: string | null): number | null {
*/
const resolvePathCache: {[key: string]: string} = {}

export async function resolvePath(fileName: string, excludeSources: string[], followSymlink = false): Promise<string> {
/**
* Resolves the path of a given file, optionally following symbolic links.
*
* @param {string} workspace - The optional workspace directory.
* @param {string} transformedFileName - The transformed file name to find.
* @param {string[]} excludeSources - List of source paths to exclude.
* @param {boolean} [followSymlink=false] - Whether to follow symbolic links.
* @returns {Promise<string>} - The resolved file path.
*/
export async function resolvePath(
workspace: string,
transformedFileName: string,
excludeSources: string[],
followSymlink = false
): Promise<string> {
const fileName: string = removePrefix(transformedFileName, workspace)
if (resolvePathCache[fileName]) {
return resolvePathCache[fileName]
}

core.debug(`Resolving path for ${fileName}`)
const normalizedFilename = fileName.replace(/^\.\//, '') // strip relative prefix (./)
const globber = await glob.create(`**/${normalizedFilename}.*`, {
const globber = await glob.create(`${workspace}/**/${normalizedFilename}.*`, {
followSymbolicLinks: followSymlink
})
const searchPath = globber.getSearchPaths() ? globber.getSearchPaths()[0] : ''
Expand Down Expand Up @@ -422,7 +437,7 @@ async function parseTestCases(
// the action only supports 1 failure per testcase
const failure = failures ? failures[0] : undefined

// identify amount of flaky failures
// identify the number of flaky failures
const flakyFailuresCount = testcase.flakyFailure
? Array.isArray(testcase.flakyFailure)
? testcase.flakyFailure.length
Expand Down Expand Up @@ -468,7 +483,7 @@ async function parseTestCases(
} else if (githubWorkspacePath && fs.existsSync(`${githubWorkspacePath}${transformedFileName}`)) {
resolvedPath = `${githubWorkspacePath}${transformedFileName}`
} else {
resolvedPath = await resolvePath(transformedFileName, excludeSources, followSymlink)
resolvedPath = await resolvePath(githubWorkspacePath || '', transformedFileName, excludeSources, followSymlink)
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,18 @@ function wrap(tag: string, content: string | null, attrs: {[attribute: string]:

return `<${tag}${htmlAttrs}>${content}</${tag}>`
}

/**
* Removes a specified prefix from the beginning of a string.
*
* @param {string} str - The original string.
* @param {string} prefix - The prefix to be removed.
* @returns {string} - The string without the prefix if it was present, otherwise the original string.
*/
export function removePrefix(str: string, prefix: string): string {
if (prefix.length === 0) return str
if (str.startsWith(prefix)) {
return str.slice(prefix.length)
}
return str
}

0 comments on commit d0dd48d

Please sign in to comment.