Skip to content

Add global.context setup before all scripts with actions/github-script#7459

Merged
pelikhan merged 4 commits intomainfrom
copilot/set-global-context-variable
Dec 24, 2025
Merged

Add global.context setup before all scripts with actions/github-script#7459
pelikhan merged 4 commits intomainfrom
copilot/set-global-context-variable

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

Bundled JavaScript scripts may contain require() calls for built-in Node.js modules (fs, path, crypto) that execute during module loading. Without globals set up beforehand, code executing at module-load time cannot access GitHub Actions variables like context, core, github.

Changes

Added global.context = context (plus core, github, exec, io) setup before all JavaScript in actions/github-script steps, whether using require() or inline mode:

Activation job scripts (compiler_activation_jobs.go):

  • check_stop_time, check_skip_if_match, check_command_position
  • compute_text, lock-issue, add_reaction_and_edit_comment

Safe output scripts (compiler_safe_outputs_core.go):

  • Inline mode safe output handlers

Participant & PR scripts:

  • copilot_participant_steps.go: assign_issue, add_copilot_reviewer
  • pr.go: PR checkout script (now uses require() when setup action is available)
  • create_issue.go: assign_copilot_to_created_issues
  • role_checks.go: membership check

Script updates:

  • checkout_pr_branch.cjs: Updated to export main function for use with require() pattern

Example

With require() (when setup action is available):

script: |
  global.core = core;
  global.github = github;
  global.context = context;
  global.exec = exec;
  global.io = io;
  const { main } = require('/tmp/gh-aw/actions/checkout_pr_branch.cjs');
  await main();

With inline mode (fallback):

script: |
  global.core = core;
  global.github = github;
  global.context = context;
  global.exec = exec;
  global.io = io;
  async function main() {
    const fs = require("fs");  // context now available
    const runId = context.runId;

This ensures consistent global variable availability across both require()-based and inline script loading patterns.

Original prompt

Make sure that "context" is stored in global for all inlined script with actions/github-script before require()

global.context = context


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

global.context = context;
global.exec = exec;
global.io = io;
async function main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot require the .cjs file and call main instead of inlining

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use require() pattern instead of inlining. Updated checkout_pr_branch.cjs to export the main function and modified pr.go to conditionally use require when setup action is available. (c69a0f1)

Copilot AI changed the title [WIP] Store context in global for all inlined scripts Add global.context setup before all inlined scripts with actions/github-script Dec 24, 2025
Copilot AI requested a review from pelikhan December 24, 2025 01:38
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Add global.context setup before all inlined scripts with actions/github-script Add global.context setup before all scripts with actions/github-script Dec 24, 2025
@pelikhan pelikhan marked this pull request as ready for review December 24, 2025 02:02
@pelikhan pelikhan merged commit b64d8c3 into main Dec 24, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/set-global-context-variable branch December 24, 2025 02:03
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