Skip to content

Export main function instead of auto-executing in GitHub Actions scripts#7465

Merged
pelikhan merged 3 commits intomainfrom
copilot/fix-js-export-main
Dec 24, 2025
Merged

Export main function instead of auto-executing in GitHub Actions scripts#7465
pelikhan merged 3 commits intomainfrom
copilot/fix-js-export-main

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

Several JavaScript files used in GitHub Actions workflows were auto-executing main() on require, causing execution before workflows were ready. Workflows expect to import and explicitly call main().

Changes

Pattern changed from:

async function main() { /* ... */ }

main().catch(error => {
  core.setFailed(error instanceof Error ? error.message : String(error));
});

To:

async function main() { /* ... */ }

module.exports = { main };

Affected files (10):

  • checkout_pr_branch.cjs
  • add_copilot_reviewer.cjs
  • assign_issue.cjs
  • check_workflow_timestamp.cjs
  • create_agent_task.cjs
  • push_repo_memory.cjs

(Updated in both pkg/workflow/js/ source and actions/setup/js/ compiled locations)

Test files updated (2):

  • create_agent_task.test.cjs - Updated runScript() to call main() explicitly
  • add_copilot_reviewer.test.cjs - Added runScript() helper for explicit main() invocation

Not Changed

MCP server files (safe_inputs_mcp_server.cjs, safe_outputs_mcp_server.cjs) retain if (require.main === module) pattern as they're executed standalone via node script.cjs, not imported.

Original prompt

Reference: https://github.com/githubnext/gh-aw/actions/runs/20479528608/job/58850347664#step:13:1

Fix this JavaScript file

Export main, remove conditional main invocation


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Fixed 10 JavaScript files to export main function instead of automatically invoking it:
- actions/setup/js: checkout_pr_branch.cjs, add_copilot_reviewer.cjs, assign_issue.cjs, create_agent_task.cjs, push_repo_memory.cjs
- pkg/workflow/js: checkout_pr_branch.cjs, add_copilot_reviewer.cjs, assign_issue.cjs, check_workflow_timestamp.cjs, create_agent_task.cjs, push_repo_memory.cjs

Changed pattern from:
  main().catch(error => { core.setFailed(...); });

To:
  module.exports = { main };

This allows GitHub Actions workflows to import and call main() explicitly.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review December 24, 2025 06:22
Updated tests to explicitly call main() for files that now export instead of auto-execute:
- create_agent_task.test.cjs: Updated runScript to call main()
- add_copilot_reviewer.test.cjs: Added runScript helper and updated all tests

Tests for assign_issue and check_workflow_timestamp already used eval with explicit main() calls, so they work correctly.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix JavaScript file to export main and remove conditional invocation Export main function instead of auto-executing in GitHub Actions scripts Dec 24, 2025
Copilot AI requested a review from pelikhan December 24, 2025 06:25
@pelikhan pelikhan merged commit cd8ca0e into main Dec 24, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/fix-js-export-main branch December 24, 2025 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants