Skip to content

Commit 93f6e0d

Browse files
Copilotpelikhan
andcommitted
feat: use generateXMLMarker helper with id and workflow_id for activation comment footers
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent a4f7607 commit 93f6e0d

5 files changed

Lines changed: 79 additions & 14 deletions

File tree

actions/setup/js/generate_footer.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function generateXMLMarker(workflowName, runUrl) {
4343
const engineVersion = process.env.GH_AW_ENGINE_VERSION || "";
4444
const engineModel = process.env.GH_AW_ENGINE_MODEL || "";
4545
const trackerId = process.env.GH_AW_TRACKER_ID || "";
46+
const runId = process.env.GITHUB_RUN_ID || "";
47+
const workflowId = process.env.GH_AW_WORKFLOW_ID || "";
4648

4749
// Build the key-value pairs for the marker
4850
const parts = [];
@@ -70,6 +72,16 @@ function generateXMLMarker(workflowName, runUrl) {
7072
parts.push(`model: ${engineModel}`);
7173
}
7274

75+
// Add numeric run ID if available
76+
if (runId) {
77+
parts.push(`id: ${runId}`);
78+
}
79+
80+
// Add workflow identifier if available
81+
if (workflowId) {
82+
parts.push(`workflow_id: ${workflowId}`);
83+
}
84+
7385
// Always include run URL
7486
parts.push(`run: ${runUrl}`);
7587

actions/setup/js/generate_footer.test.cjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe("generate_footer.cjs", () => {
4545
delete process.env.GH_AW_ENGINE_MODEL;
4646
delete process.env.GH_AW_TRACKER_ID;
4747
delete process.env.GH_AW_WORKFLOW_ID;
48+
delete process.env.GITHUB_RUN_ID;
4849

4950
// Dynamic import to get fresh module state
5051
const module = await import("./generate_footer.cjs");
@@ -126,6 +127,42 @@ describe("generate_footer.cjs", () => {
126127

127128
expect(result).toBe("<!-- gh-aw-agentic-workflow: Test Workflow, gh-aw-tracker-id: workflow-2024-q1, engine: copilot, version: 1.0.0, model: gpt-5, run: https://github.com/test/repo/actions/runs/123 -->");
128129
});
130+
131+
it("should include run id when GITHUB_RUN_ID env var is set", async () => {
132+
process.env.GITHUB_RUN_ID = "9876543210";
133+
134+
vi.resetModules();
135+
const freshModule = await import("./generate_footer.cjs");
136+
137+
const result = freshModule.generateXMLMarker("Test Workflow", "https://github.com/test/repo/actions/runs/9876543210");
138+
139+
expect(result).toBe("<!-- gh-aw-agentic-workflow: Test Workflow, id: 9876543210, run: https://github.com/test/repo/actions/runs/9876543210 -->");
140+
});
141+
142+
it("should include workflow_id when GH_AW_WORKFLOW_ID env var is set", async () => {
143+
process.env.GH_AW_WORKFLOW_ID = "smoke-copilot";
144+
145+
vi.resetModules();
146+
const freshModule = await import("./generate_footer.cjs");
147+
148+
const result = freshModule.generateXMLMarker("Test Workflow", "https://github.com/test/repo/actions/runs/123");
149+
150+
expect(result).toBe("<!-- gh-aw-agentic-workflow: Test Workflow, workflow_id: smoke-copilot, run: https://github.com/test/repo/actions/runs/123 -->");
151+
});
152+
153+
it("should include all identifiers when all standard env vars are set", async () => {
154+
process.env.GH_AW_ENGINE_ID = "copilot";
155+
process.env.GH_AW_TRACKER_ID = "tracker-abc";
156+
process.env.GITHUB_RUN_ID = "12345";
157+
process.env.GH_AW_WORKFLOW_ID = "my-workflow";
158+
159+
vi.resetModules();
160+
const freshModule = await import("./generate_footer.cjs");
161+
162+
const result = freshModule.generateXMLMarker("My Workflow", "https://github.com/test/repo/actions/runs/12345");
163+
164+
expect(result).toBe("<!-- gh-aw-agentic-workflow: My Workflow, gh-aw-tracker-id: tracker-abc, engine: copilot, id: 12345, workflow_id: my-workflow, run: https://github.com/test/repo/actions/runs/12345 -->");
165+
});
129166
});
130167

131168
describe("generateWorkflowIdMarker", () => {

actions/setup/js/messages_footer.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ function generateXMLMarker(workflowName, runUrl) {
171171
const engineVersion = process.env.GH_AW_ENGINE_VERSION || "";
172172
const engineModel = process.env.GH_AW_ENGINE_MODEL || "";
173173
const trackerId = process.env.GH_AW_TRACKER_ID || "";
174+
const runId = process.env.GITHUB_RUN_ID || "";
175+
const workflowId = process.env.GH_AW_WORKFLOW_ID || "";
174176

175177
// Build the key-value pairs for the marker
176178
const parts = [];
@@ -198,6 +200,16 @@ function generateXMLMarker(workflowName, runUrl) {
198200
parts.push(`model: ${engineModel}`);
199201
}
200202

203+
// Add numeric run ID if available
204+
if (runId) {
205+
parts.push(`id: ${runId}`);
206+
}
207+
208+
// Add workflow identifier if available
209+
if (workflowId) {
210+
parts.push(`workflow_id: ${workflowId}`);
211+
}
212+
201213
// Always include run URL
202214
parts.push(`run: ${runUrl}`);
203215

actions/setup/js/update_activation_comment.cjs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ const { getMessages } = require("./messages_core.cjs");
66
const { sanitizeContent } = require("./sanitize_content.cjs");
77
const { getPullRequestCreatedMessage, getIssueCreatedMessage, getCommitPushedMessage } = require("./messages_run_status.cjs");
88
const { parseBoolTemplatable } = require("./templatable.cjs");
9+
const { generateXMLMarker } = require("./generate_footer.cjs");
910

1011
/**
11-
* Get the current workflow run ID from context or environment.
12+
* Build the workflow run URL from context and environment.
1213
* @param {any} context - GitHub Actions context
13-
* @returns {string} The run ID, or empty string if not available
14+
* @returns {string} The workflow run URL
1415
*/
15-
function getRunId(context) {
16-
return String(context.runId || process.env.GITHUB_RUN_ID || "");
16+
function getRunUrl(context) {
17+
const runId = context.runId || process.env.GITHUB_RUN_ID || "";
18+
const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com";
19+
return context.payload?.repository?.html_url ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
1720
}
1821

1922
/**
@@ -27,12 +30,10 @@ function getRunId(context) {
2730
*/
2831
async function updateActivationComment(github, context, core, itemUrl, itemNumber, itemType = "pull_request") {
2932
const itemLabel = itemType === "issue" ? "issue" : "pull request";
30-
const runId = getRunId(context);
33+
const workflowName = process.env.GH_AW_WORKFLOW_NAME || "Workflow";
34+
const runUrl = getRunUrl(context);
3135
const body = itemType === "issue" ? getIssueCreatedMessage({ itemNumber, itemUrl }) : getPullRequestCreatedMessage({ itemNumber, itemUrl });
32-
let linkMessage = `\n\n${body}`;
33-
if (runId) {
34-
linkMessage += `\n\n<!-- gh-aw-run-id: ${runId} -->`;
35-
}
36+
const linkMessage = `\n\n${body}\n\n${generateXMLMarker(workflowName, runUrl)}`;
3637
await updateActivationCommentWithMessage(github, context, core, linkMessage, itemLabel, { targetIssueNumber: itemNumber });
3738
}
3839

@@ -48,11 +49,9 @@ async function updateActivationComment(github, context, core, itemUrl, itemNumbe
4849
*/
4950
async function updateActivationCommentWithCommit(github, context, core, commitSha, commitUrl, options = {}) {
5051
const shortSha = commitSha.substring(0, 7);
51-
const runId = getRunId(context);
52-
let message = `\n\n${getCommitPushedMessage({ commitSha, shortSha, commitUrl })}`;
53-
if (runId) {
54-
message += `\n\n<!-- gh-aw-run-id: ${runId} -->`;
55-
}
52+
const workflowName = process.env.GH_AW_WORKFLOW_NAME || "Workflow";
53+
const runUrl = getRunUrl(context);
54+
const message = `\n\n${getCommitPushedMessage({ commitSha, shortSha, commitUrl })}\n\n${generateXMLMarker(workflowName, runUrl)}`;
5655
await updateActivationCommentWithMessage(github, context, core, message, "commit", options);
5756
}
5857

actions/setup/js/update_activation_comment.test.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const createTestableFunction = scriptContent => {
6666
},
6767
};
6868
}
69+
if (module === "./generate_footer.cjs") {
70+
return {
71+
generateXMLMarker: (workflowName, runUrl) => `<!-- gh-aw-agentic-workflow: ${workflowName}, run: ${runUrl} -->`,
72+
};
73+
}
6974
throw new Error(`Module ${module} not mocked in test`);
7075
};
7176
return new Function(

0 commit comments

Comments
 (0)