mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chrome: git commit info gha fix (#34981)
This commit is contained in:
parent
7a2d56d0ff
commit
98443e5749
1
.github/workflows/tests_primary.yml
vendored
1
.github/workflows/tests_primary.yml
vendored
@ -23,6 +23,7 @@ env:
|
|||||||
# Force terminal colors. @see https://www.npmjs.com/package/colors
|
# Force terminal colors. @see https://www.npmjs.com/package/colors
|
||||||
FORCE_COLOR: 1
|
FORCE_COLOR: 1
|
||||||
ELECTRON_SKIP_BINARY_DOWNLOAD: 1
|
ELECTRON_SKIP_BINARY_DOWNLOAD: 1
|
||||||
|
DEBUG_GIT_COMMIT_INFO: 1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test_linux:
|
test_linux:
|
||||||
|
|||||||
@ -62,10 +62,10 @@ const gitCommitInfoPlugin = (fullConfig: FullConfigInternal): TestRunnerPlugin =
|
|||||||
|
|
||||||
async function ciInfo(): Promise<CIInfo | undefined> {
|
async function ciInfo(): Promise<CIInfo | undefined> {
|
||||||
if (process.env.GITHUB_ACTIONS) {
|
if (process.env.GITHUB_ACTIONS) {
|
||||||
let pr: { title: string, number: number } | undefined;
|
let pr: { title: string, number: number, baseHash: string } | undefined;
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(await fs.promises.readFile(process.env.GITHUB_EVENT_PATH!, 'utf8'));
|
const json = JSON.parse(await fs.promises.readFile(process.env.GITHUB_EVENT_PATH!, 'utf8'));
|
||||||
pr = { title: json.pull_request.title, number: json.pull_request.number };
|
pr = { title: json.pull_request.title, number: json.pull_request.number, baseHash: json.pull_request.base.sha };
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ async function ciInfo(): Promise<CIInfo | undefined> {
|
|||||||
prTitle: pr ? pr.title : undefined,
|
prTitle: pr ? pr.title : undefined,
|
||||||
buildHref: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
|
buildHref: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
|
||||||
commitHash: process.env.GITHUB_SHA,
|
commitHash: process.env.GITHUB_SHA,
|
||||||
baseHash: process.env.GITHUB_BASE_REF,
|
baseHash: pr ? pr.baseHash : process.env.GITHUB_BASE_REF,
|
||||||
branch: process.env.GITHUB_REF_NAME,
|
branch: process.env.GITHUB_REF_NAME,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -144,15 +144,11 @@ async function gitCommitInfo(gitDir: string): Promise<GitCommitInfo | undefined>
|
|||||||
|
|
||||||
async function gitDiff(gitDir: string, ci?: CIInfo): Promise<string | undefined> {
|
async function gitDiff(gitDir: string, ci?: CIInfo): Promise<string | undefined> {
|
||||||
const diffLimit = 100_000;
|
const diffLimit = 100_000;
|
||||||
if (ci) {
|
if (ci?.baseHash) {
|
||||||
// First try the diff against the base branch.
|
// First try the diff against the base branch.
|
||||||
const diff = await runGit(`git diff ${ci.baseHash}`, gitDir);
|
const diff = await runGit(`git fetch origin ${ci.baseHash} && git diff ${ci.baseHash} HEAD`, gitDir);
|
||||||
if (diff)
|
if (diff)
|
||||||
return diff.substring(0, diffLimit);
|
return diff.substring(0, diffLimit);
|
||||||
|
|
||||||
// Grow history for shallow checkout.
|
|
||||||
const output = await runGit('git fetch --deepen=1 && git show HEAD', gitDir);
|
|
||||||
return output?.substring(0, diffLimit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check dirty state first.
|
// Check dirty state first.
|
||||||
@ -171,7 +167,7 @@ async function runGit(command: string, cwd: string): Promise<string | undefined>
|
|||||||
[],
|
[],
|
||||||
{ stdio: 'pipe', cwd, timeout: GIT_OPERATIONS_TIMEOUT_MS, shell: true }
|
{ stdio: 'pipe', cwd, timeout: GIT_OPERATIONS_TIMEOUT_MS, shell: true }
|
||||||
);
|
);
|
||||||
if (result.code) {
|
if (process.env.DEBUG_GIT_COMMIT_INFO && result.code) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(`Failed to run ${command}: ${result.stderr}`);
|
console.error(`Failed to run ${command}: ${result.stderr}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user