Skip to content

Commit 3fac1cf

Browse files
chore: sync actions from [email protected] (#178)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent dadd6a0 commit 3fac1cf

25 files changed

Lines changed: 874 additions & 179 deletions

‎setup/js/add_reaction_and_edit_comment.cjs‎

Lines changed: 19 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { ERR_API, ERR_NOT_FOUND, ERR_VALIDATION } = require("./error_codes.cjs");
99
const { buildWorkflowRunUrl } = require("./workflow_metadata_helpers.cjs");
1010
const { resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs");
1111
const { resolveInvocationContext } = require("./invocation_context_helpers.cjs");
12-
const { addReaction, addDiscussionReaction } = require("./add_reaction.cjs");
12+
const { addReaction, addDiscussionReaction, getDiscussionNodeId } = require("./add_reaction.cjs");
1313

1414
/**
1515
* Event type descriptions for comment messages
@@ -106,9 +106,9 @@ async function resolveEventEndpoints(eventName, owner, repo, payload) {
106106
return null;
107107
}
108108
// Discussions use GraphQL API - get the node ID
109-
const discussion = await getDiscussionId(owner, repo, discussionNumber);
109+
const discussionNodeId = await getDiscussionNodeId(owner, repo, discussionNumber);
110110
return {
111-
reactionEndpoint: discussion.id, // Store node ID for GraphQL
111+
reactionEndpoint: discussionNodeId, // Store node ID for GraphQL
112112
commentUpdateEndpoint: `discussion:${discussionNumber}`, // Special format to indicate discussion
113113
};
114114
}
@@ -186,37 +186,6 @@ async function main() {
186186
}
187187
}
188188

189-
/**
190-
* Get the node ID for a discussion
191-
* @param {string} owner - Repository owner
192-
* @param {string} repo - Repository name
193-
* @param {number} discussionNumber - Discussion number
194-
* @returns {Promise<{id: string, url: string}>} Discussion details
195-
*/
196-
async function getDiscussionId(owner, repo, discussionNumber) {
197-
const { repository } = await github.graphql(
198-
`
199-
query($owner: String!, $repo: String!, $num: Int!) {
200-
repository(owner: $owner, name: $repo) {
201-
discussion(number: $num) {
202-
id
203-
url
204-
}
205-
}
206-
}`,
207-
{ owner, repo, num: discussionNumber }
208-
);
209-
210-
if (!repository || !repository.discussion) {
211-
throw new Error(`${ERR_NOT_FOUND}: Discussion #${discussionNumber} not found in ${owner}/${repo}`);
212-
}
213-
214-
return {
215-
id: repository.discussion.id,
216-
url: repository.discussion.url,
217-
};
218-
}
219-
220189
/**
221190
* Helper function to set comment outputs
222191
* @param {string} commentId - The comment ID
@@ -274,50 +243,25 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
274243
];
275244
const commentBody = commentParts.join("\n\n");
276245

277-
if (eventName === "discussion") {
278-
// Parse discussion number from special format: "discussion:NUMBER"
246+
if (eventName === "discussion" || eventName === "discussion_comment") {
247+
// Parse discussion number from special format: "discussion:NUMBER" or "discussion_comment:NUMBER:COMMENT_ID"
279248
const discussionNumber = parseInt(endpoint.split(":")[1], 10);
280-
const { id: discussionId } = await getDiscussionId(eventRepo.owner, eventRepo.repo, discussionNumber);
281-
282-
const result = await github.graphql(
283-
`
284-
mutation($dId: ID!, $body: String!) {
285-
addDiscussionComment(input: { discussionId: $dId, body: $body }) {
286-
comment {
287-
id
288-
url
249+
const discussionId = await getDiscussionNodeId(eventRepo.owner, eventRepo.repo, discussionNumber);
250+
// For discussion_comment events, thread the reply under the triggering comment.
251+
// GitHub Discussions only supports two nesting levels, so resolve the top-level parent node ID.
252+
const replyToId = eventName === "discussion_comment" ? await resolveTopLevelDiscussionCommentId(github, eventPayload?.comment?.node_id) : null;
253+
const mutation = replyToId
254+
? `mutation($dId: ID!, $body: String!, $replyToId: ID!) {
255+
addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
256+
comment { id url }
289257
}
290-
}
291-
}`,
292-
{ dId: discussionId, body: commentBody }
293-
);
294-
295-
const comment = result.addDiscussionComment.comment;
296-
setCommentOutputs(comment.id, comment.url, eventRepo);
297-
return;
298-
} else if (eventName === "discussion_comment") {
299-
// Parse discussion number from special format: "discussion_comment:NUMBER:COMMENT_ID"
300-
const discussionNumber = parseInt(endpoint.split(":")[1], 10);
301-
const { id: discussionId } = await getDiscussionId(eventRepo.owner, eventRepo.repo, discussionNumber);
302-
303-
// Get the comment node ID to use as the parent for threading.
304-
// GitHub Discussions only supports two nesting levels, so if the triggering comment is
305-
// itself a reply, we resolve the top-level parent's node ID.
306-
const commentNodeId = await resolveTopLevelDiscussionCommentId(github, eventPayload?.comment?.node_id);
307-
308-
const result = await github.graphql(
309-
`
310-
mutation($dId: ID!, $body: String!, $replyToId: ID!) {
311-
addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
312-
comment {
313-
id
314-
url
258+
}`
259+
: `mutation($dId: ID!, $body: String!) {
260+
addDiscussionComment(input: { discussionId: $dId, body: $body }) {
261+
comment { id url }
315262
}
316-
}
317-
}`,
318-
{ dId: discussionId, body: commentBody, replyToId: commentNodeId }
319-
);
320-
263+
}`;
264+
const result = await github.graphql(mutation, { dId: discussionId, body: commentBody, ...(replyToId ? { replyToId } : {}) });
321265
const comment = result.addDiscussionComment.comment;
322266
setCommentOutputs(comment.id, comment.url, eventRepo);
323267
return;

‎setup/js/add_workflow_run_comment.cjs‎

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,16 @@ function setCommentOutputs(commentId, commentUrl, eventRepo = context.repo, opti
8484
* @returns {Record<string, any>|null}
8585
*/
8686
function parseObject(value) {
87-
if (!value) {
88-
return null;
89-
}
87+
if (!value) return null;
9088
if (typeof value === "string") {
9189
const trimmed = value.trim();
92-
if (!trimmed) {
93-
return null;
94-
}
90+
if (!trimmed) return null;
9591
try {
9692
const parsed = JSON.parse(trimmed);
97-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
98-
return parsed;
99-
}
93+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
10094
} catch {
10195
return null;
10296
}
103-
return null;
10497
}
10598
if (typeof value === "object" && !Array.isArray(value)) {
10699
return /** @type {Record<string, any>} */ value;
@@ -396,31 +389,18 @@ function buildCommentBody(eventName, runUrl, workflowNameOverride) {
396389
*/
397390
async function postDiscussionComment(discussionNumber, commentBody, replyToNodeId = null, eventRepo = context.repo) {
398391
const discussionId = await getDiscussionNodeId(discussionNumber, eventRepo);
399-
400-
/** @type {any} */
401-
let result;
402-
if (replyToNodeId) {
403-
result = await github.graphql(
404-
`
405-
mutation($dId: ID!, $body: String!, $replyToId: ID!) {
392+
const mutation = replyToNodeId
393+
? `mutation($dId: ID!, $body: String!, $replyToId: ID!) {
406394
addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
407395
comment { id url }
408396
}
409-
}`,
410-
{ dId: discussionId, body: commentBody, replyToId: replyToNodeId }
411-
);
412-
} else {
413-
result = await github.graphql(
414-
`
415-
mutation($dId: ID!, $body: String!) {
397+
}`
398+
: `mutation($dId: ID!, $body: String!) {
416399
addDiscussionComment(input: { discussionId: $dId, body: $body }) {
417400
comment { id url }
418401
}
419-
}`,
420-
{ dId: discussionId, body: commentBody }
421-
);
422-
}
423-
402+
}`;
403+
const result = await github.graphql(mutation, { dId: discussionId, body: commentBody, ...(replyToNodeId ? { replyToId: replyToNodeId } : {}) });
424404
const comment = result.addDiscussionComment.comment;
425405
return setCommentOutputs(comment.id, comment.url, eventRepo);
426406
}

‎setup/js/chroot_home_cleanup.test.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { fileURLToPath } from "url";
88
const __dirname = path.dirname(fileURLToPath(import.meta.url));
99
const POST_SCRIPT_PATH = path.join(__dirname, "..", "post.js");
1010
const CLEAN_SCRIPT_PATH = path.join(__dirname, "..", "clean.sh");
11+
const INSTALL_COPILOT_CLI_SCRIPT_PATH = path.join(__dirname, "..", "sh", "install_copilot_cli.sh");
1112

1213
const tempDirs = [];
1314

@@ -136,3 +137,19 @@ describe("clean.sh chroot-home cleanup", () => {
136137
expect(fs.readFileSync(logPath, "utf8")).toContain("-exec rm -rf -- {} +");
137138
});
138139
});
140+
141+
describe("install_copilot_cli.sh chroot-home cleanup", () => {
142+
it("cleans stale chroot-home directories before starting Copilot CLI installation", () => {
143+
const script = fs.readFileSync(INSTALL_COPILOT_CLI_SCRIPT_PATH, "utf8");
144+
145+
const ownershipFixIndex = script.indexOf('sudo chown -R "$(id -u):$(id -g)" "$COPILOT_DIR"');
146+
const cleanupBannerIndex = script.indexOf('echo "Cleaning up stale AWF chroot home directories..."');
147+
const cleanupCommandIndex = script.indexOf(
148+
"sudo find /tmp -maxdepth 1 -name 'awf-*-chroot-home' -type d -exec rm -rf -- {} + 2>/dev/null || true"
149+
);
150+
151+
expect(ownershipFixIndex).toBeGreaterThanOrEqual(0);
152+
expect(cleanupBannerIndex).toBeGreaterThan(ownershipFixIndex);
153+
expect(cleanupCommandIndex).toBeGreaterThan(cleanupBannerIndex);
154+
});
155+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// @ts-check
2+
/// <reference types="@actions/github-script" />
3+
4+
const fs = require("fs");
5+
6+
/** Path written by install_frontmatter_skills.cjs during the activation job. */
7+
const SKILL_FAILURES_FILE = "/tmp/gh-aw/skill_install_failures.json";
8+
9+
/**
10+
* Read the shared failures file produced by install_frontmatter_skills.cjs.
11+
* Returns an empty array when the file does not exist or cannot be parsed.
12+
* @returns {Array<{skill: string; error: string}>}
13+
*/
14+
function readSkillInstallFailures() {
15+
try {
16+
if (!fs.existsSync(SKILL_FAILURES_FILE)) {
17+
return [];
18+
}
19+
const raw = fs.readFileSync(SKILL_FAILURES_FILE, "utf8");
20+
const parsed = JSON.parse(raw);
21+
if (!Array.isArray(parsed)) {
22+
return [];
23+
}
24+
return parsed.filter(entry => entry && typeof entry.skill === "string" && typeof entry.error === "string");
25+
} catch (readErr) {
26+
// Warn so "no failures" vs "couldn't read failures file" is distinguishable in logs
27+
core.warning(`Could not read skill install failures file: ${readErr instanceof Error ? readErr.message : String(readErr)}`);
28+
return [];
29+
}
30+
}
31+
32+
async function main() {
33+
const failures = readSkillInstallFailures();
34+
const failureCount = failures.length;
35+
36+
core.info(`Skill install failures detected: ${failureCount}`);
37+
38+
core.setOutput("failure_count", String(failureCount));
39+
core.setOutput("errors", failures.map(f => `${f.skill}\t${f.error.replace(/\r?\n/g, " ").replace(/\t/g, " ")}`).join("\n"));
40+
41+
if (failureCount > 0) {
42+
core.warning(`${failureCount} skill(s) failed to install — see agent failure issue/comment for details`);
43+
}
44+
}
45+
46+
module.exports = { main, readSkillInstallFailures };

‎setup/js/convert_gateway_config_claude.cjs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require("./shim.cjs");
2323
*/
2424

2525
const path = require("path");
26-
const { rewriteUrl, loadGatewayContext, logCLIFilters, filterAndTransformServers, logServerStats, writeSecureOutput } = require("./convert_gateway_config_shared.cjs");
26+
const { rewriteUrl, normalizeGatewayEntry, loadGatewayContext, logCLIFilters, filterAndTransformServers, logServerStats, writeSecureOutput } = require("./convert_gateway_config_shared.cjs");
2727

2828
const OUTPUT_PATH = path.join(process.env.RUNNER_TEMP || "/tmp", "gh-aw/mcp-config/mcp-servers.json");
2929

@@ -33,14 +33,10 @@ const OUTPUT_PATH = path.join(process.env.RUNNER_TEMP || "/tmp", "gh-aw/mcp-conf
3333
* @returns {Record<string, unknown>}
3434
*/
3535
function transformClaudeEntry(entry, urlPrefix) {
36-
const transformed = { ...entry };
37-
// Claude uses "type": "http" for HTTP-based MCP servers
38-
transformed.type = "http";
39-
// Fix the URL to use the correct domain
40-
if (typeof transformed.url === "string") {
41-
transformed.url = rewriteUrl(transformed.url, urlPrefix);
42-
}
43-
return transformed;
36+
return normalizeGatewayEntry(entry, urlPrefix, transformed => {
37+
// Claude uses "type": "http" for HTTP-based MCP servers
38+
transformed.type = "http";
39+
});
4440
}
4541

4642
function main() {

‎setup/js/convert_gateway_config_copilot.cjs‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require("./shim.cjs");
2525
*/
2626

2727
const path = require("path");
28-
const { rewriteUrl, loadGatewayContext, logCLIFilters, filterAndTransformServers, logServerStats, writeSecureOutput } = require("./convert_gateway_config_shared.cjs");
28+
const { rewriteUrl, normalizeGatewayEntry, loadGatewayContext, logCLIFilters, filterAndTransformServers, logServerStats, writeSecureOutput } = require("./convert_gateway_config_shared.cjs");
2929

3030
/**
3131
* Resolves the Copilot CLI MCP config output path from the runtime $HOME.
@@ -54,16 +54,12 @@ function resolveCopilotConfigOutputPath() {
5454
* @returns {Record<string, unknown>}
5555
*/
5656
function transformCopilotEntry(entry, urlPrefix) {
57-
const transformed = { ...entry };
58-
// Add tools field if not present
59-
if (!transformed.tools) {
60-
transformed.tools = ["*"];
61-
}
62-
// Fix the URL to use the correct domain
63-
if (typeof transformed.url === "string") {
64-
transformed.url = rewriteUrl(transformed.url, urlPrefix);
65-
}
66-
return transformed;
57+
return normalizeGatewayEntry(entry, urlPrefix, transformed => {
58+
// Add tools field if not present
59+
if (!transformed.tools) {
60+
transformed.tools = ["*"];
61+
}
62+
});
6763
}
6864

6965
function main() {

‎setup/js/convert_gateway_config_gemini.cjs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,18 @@ require("./shim.cjs");
3131
*/
3232

3333
const path = require("path");
34-
const { rewriteUrl, loadGatewayContext, logCLIFilters, filterAndTransformServers, logServerStats, writeSecureOutput } = require("./convert_gateway_config_shared.cjs");
34+
const { rewriteUrl, normalizeGatewayEntry, loadGatewayContext, logCLIFilters, filterAndTransformServers, logServerStats, writeSecureOutput } = require("./convert_gateway_config_shared.cjs");
3535

3636
/**
3737
* @param {Record<string, unknown>} entry
3838
* @param {string} urlPrefix
3939
* @returns {Record<string, unknown>}
4040
*/
4141
function transformGeminiEntry(entry, urlPrefix) {
42-
const transformed = { ...entry };
43-
// Remove "type" field — Gemini uses transport auto-detection from url/httpUrl
44-
delete transformed.type;
45-
// Fix the URL to use the correct domain
46-
if (typeof transformed.url === "string") {
47-
transformed.url = rewriteUrl(transformed.url, urlPrefix);
48-
}
49-
return transformed;
42+
return normalizeGatewayEntry(entry, urlPrefix, transformed => {
43+
// Remove "type" field — Gemini uses transport auto-detection from url/httpUrl
44+
delete transformed.type;
45+
});
5046
}
5147

5248
function main() {

‎setup/js/convert_gateway_config_shared.cjs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ function rewriteUrl(url, urlPrefix) {
1616
return url.replace(/^http:\/\/[^/]+\/mcp\//, `${urlPrefix}/mcp/`);
1717
}
1818

19+
/**
20+
* Shallow-clone a gateway entry, apply provider-specific mutations, and rewrite URL.
21+
* Note: only the top-level object is cloned; nested fields (e.g., `headers`) are shared references.
22+
*
23+
* @param {Record<string, unknown>} entry
24+
* @param {string} urlPrefix
25+
* @param {(transformed: Record<string, unknown>) => void} [mutate]
26+
* @returns {Record<string, unknown>}
27+
*/
28+
function normalizeGatewayEntry(entry, urlPrefix, mutate) {
29+
const transformed = { ...entry };
30+
if (mutate) {
31+
mutate(transformed);
32+
}
33+
if (typeof transformed.url === "string") {
34+
transformed.url = rewriteUrl(transformed.url, urlPrefix);
35+
}
36+
return transformed;
37+
}
38+
1939
/**
2040
* @param {string} name
2141
* @returns {string}
@@ -129,6 +149,7 @@ function writeSecureOutput(outputPath, output) {
129149

130150
module.exports = {
131151
rewriteUrl,
152+
normalizeGatewayEntry,
132153
loadGatewayContext,
133154
logCLIFilters,
134155
filterAndTransformServers,

0 commit comments

Comments
 (0)