Skip to content

Commit 813e540

Browse files
Copilotpelikhan
andauthored
fix: add detailed logging for cross-repo resolution in hash check
Add GITHUB_WORKFLOW_REF, GITHUB_REPOSITORY, resolved source repo, and same-repo/cross-repo invocation logging consistent with resolve_host_repo.cjs. Also adds tests covering same-repo logging and the new log lines. Agent-Logs-Url: https://github.com/github/gh-aw/sessions/905801db-b0c1-482f-b2e9-8d176009b69a Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 303b44c commit 813e540

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

actions/setup/js/check_workflow_timestamp_api.cjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async function main() {
3737
// When running cross-repo via org rulesets, context.repo points to the target
3838
// repository, not the repository that defines the workflow files.
3939
const workflowEnvRef = process.env.GITHUB_WORKFLOW_REF || "";
40+
const currentRepo = process.env.GITHUB_REPOSITORY || `${context.repo.owner}/${context.repo.repo}`;
4041
const repoMatch = workflowEnvRef.match(/^([^/]+)\/([^/]+)\//);
4142
const refMatch = workflowEnvRef.match(/@(.+)$/);
4243

@@ -47,11 +48,15 @@ async function main() {
4748
// Use the workflow ref if parseable, otherwise fall back to context.sha
4849
const ref = refMatch ? refMatch[1] : context.sha;
4950

50-
// Log cross-repo detection for debugging
51-
const currentRepo = process.env.GITHUB_REPOSITORY || `${context.repo.owner}/${context.repo.repo}`;
51+
core.info(`GITHUB_WORKFLOW_REF: ${workflowEnvRef || "(not set)"}`);
52+
core.info(`GITHUB_REPOSITORY: ${currentRepo}`);
53+
core.info(`Resolved source repo: ${owner}/${repo} @ ${ref}`);
54+
5255
const workflowRepo = `${owner}/${repo}`;
5356
if (workflowRepo !== currentRepo) {
5457
core.info(`Cross-repo invocation detected: workflow source is "${workflowRepo}", current repo is "${currentRepo}"`);
58+
} else {
59+
core.info(`Same-repo invocation: checking out ${workflowRepo} @ ${ref}`);
5560
}
5661

5762
// Helper function to compute and compare frontmatter hashes

actions/setup/js/check_workflow_timestamp_api.test.cjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ engine: copilot
105105
expect(mockCore.setFailed).not.toHaveBeenCalled();
106106
expect(mockCore.summary.addRaw).not.toHaveBeenCalled();
107107
});
108+
109+
it("should log same-repo invocation when GITHUB_WORKFLOW_REF matches GITHUB_REPOSITORY", async () => {
110+
process.env.GITHUB_WORKFLOW_REF = "test-owner/test-repo/.github/workflows/test.lock.yml@refs/heads/main";
111+
process.env.GITHUB_REPOSITORY = "test-owner/test-repo";
112+
113+
mockGithub.rest.repos.getContent.mockResolvedValue({ data: null });
114+
115+
await main();
116+
117+
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("Same-repo invocation"));
118+
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("GITHUB_WORKFLOW_REF:"));
119+
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("Resolved source repo:"));
120+
});
108121
});
109122

110123
describe("when lock file is outdated (hashes differ)", () => {
@@ -520,6 +533,16 @@ engine: copilot
520533
expect(mockCore.setFailed).not.toHaveBeenCalled();
521534
});
522535

536+
it("should log GITHUB_WORKFLOW_REF, GITHUB_REPOSITORY, and resolved source repo", async () => {
537+
mockGithub.rest.repos.getContent.mockResolvedValue({ data: null });
538+
539+
await main();
540+
541+
expect(mockCore.info).toHaveBeenCalledWith("GITHUB_WORKFLOW_REF: source-owner/source-repo/.github/workflows/test.lock.yml@refs/heads/main");
542+
expect(mockCore.info).toHaveBeenCalledWith("GITHUB_REPOSITORY: target-owner/target-repo");
543+
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("Resolved source repo: source-owner/source-repo @ refs/heads/main"));
544+
});
545+
523546
it("should use the workflow ref from GITHUB_WORKFLOW_REF, not context.sha", async () => {
524547
const validHash = "c2a79263dc72f28c76177afda9bf0935481b26da094407a50155a6e0244084e3";
525548
const lockFileContent = `# frontmatter-hash: ${validHash}

0 commit comments

Comments
 (0)