Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

The safe_outputs job was generating inline bash scripts to write JavaScript files and embedding full script content in YAML. This converts it to use the actions/setup action and require mode for loading scripts.

Changes

  • Replaced inline bash with actions/setup action (compiler_safe_outputs_core.go)

    • Removed GenerateWriteScriptsStep call and script collection logic
    • Added sparse checkout of actions folder (dev mode) + setup action invocation
    • Scripts now copied from pkg/workflow/js/ to /tmp/gh-aw/actions/ via action
  • Converted to require mode (compiler_safe_outputs_core.go)

    • Changed buildConsolidatedSafeOutputStep from inlining scripts to using require pattern
    • Scripts loaded via const { main } = require('/tmp/gh-aw/actions/script.cjs'); await main()
    • Exposes GitHub Actions globals to required modules
  • Fixed GitHub App token insertion (compiler_safe_outputs_core.go)

    • Updated insertion index to account for setup action steps
    • Prevents YAML key conflicts with subsequent steps
  • Fixed update_cache_memory job (cache.go)

    • Moved setup action addition after restore-only cache check
    • Prevents empty job creation when all caches are restore-only

Before/After

# Before: Inline mode
- name: Setup JavaScript files
  shell: bash
  run: |
    mkdir -p /tmp/gh-aw/scripts
    cat > /tmp/gh-aw/scripts/add_comment.cjs << 'EOF'
    // ... 500+ lines of embedded JavaScript ...
    EOF

- name: Add Comment
  uses: actions/github-script@v8
  with:
    script: |
      // ... 500+ lines of inlined JavaScript ...
# After: Require mode
- name: Setup Scripts
  uses: ./actions/setup
  with:
    destination: /tmp/gh-aw/actions

- name: Add Comment
  uses: actions/github-script@v8
  with:
    script: |
      global.core = core;
      global.github = github;
      global.context = context;
      global.exec = exec;
      global.io = io;
      const { main } = require('/tmp/gh-aw/actions/add_comment.cjs');
      await main();

Note

TestActivationJobNoCheckoutStep failure is pre-existing from base commit e203925 (unrelated to these changes).

Original prompt

Convert to using the require action mode in the safe_outputs job:

  • setup scripts
  • use require mode instead of inline for all safe output scripts

See run, it is still using the inline mode:

Reference: https://github.com/githubnext/gh-aw/actions/runs/20461070211/job/58793909094


💡 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.

Copilot AI self-assigned this Dec 23, 2025
Copilot AI and others added 2 commits December 23, 2025 13:09
- Replace inline bash script for JavaScript files with actions/setup action
- Change buildConsolidatedSafeOutputStep to use require mode pattern
- Fix GitHub App token insertion index to account for setup action steps
- All 121 workflows now compile successfully

Co-authored-by: pelikhan <[email protected]>
- Move setup action addition to after the check for writable caches
- Ensures update_cache_memory job is not created when all caches are restore-only
- Fixes TestCacheMemoryWithThreatDetection test

Co-authored-by: pelikhan <[email protected]>
Copilot AI changed the title [WIP] Convert safe outputs job to use require action mode Convert safe_outputs job to use setup action and require mode Dec 23, 2025
Copilot AI requested a review from pelikhan December 23, 2025 13:26
@pelikhan pelikhan marked this pull request as ready for review December 23, 2025 14:21
@pelikhan pelikhan merged commit 7214a67 into copilot/create-custom-action-setup-activation Dec 23, 2025
@pelikhan pelikhan deleted the copilot/convert-safe-outputs-to-require branch December 23, 2025 14:21
pelikhan added a commit that referenced this pull request Dec 23, 2025
* Initial plan

* Add setup-activation action with dependencies

Co-authored-by: pelikhan <[email protected]>

* Modify compiler to use setup-activation action with require()

Co-authored-by: pelikhan <[email protected]>

* Update actions README and test recompile with inline mode

Co-authored-by: pelikhan <[email protected]>

* Complete setup-activation action implementation

Co-authored-by: pelikhan <[email protected]>

* Attach GitHub builtin objects to global before require()

Co-authored-by: pelikhan <[email protected]>

* Infer action mode from binary version tag

Co-authored-by: pelikhan <[email protected]>

* Add sparse checkout of actions folder in dev mode

Co-authored-by: pelikhan <[email protected]>

* Replace Node.js file embedding with bash script in setup-safe-outputs action (#6921)

* Merge main branch

Co-authored-by: pelikhan <[email protected]>

* Merge main branch (second merge)

Co-authored-by: pelikhan <[email protected]>

* Merge main and recompile workflows

Co-authored-by: pelikhan <[email protected]>

* Merge main branch (fourth merge)

Co-authored-by: pelikhan <[email protected]>

* Merge main branch (fifth merge)

Co-authored-by: pelikhan <[email protected]>

* Co-authored-by: pelikhan <[email protected]>

* Merge main branch (sixth merge)

Co-authored-by: pelikhan <[email protected]>

* Rebuild setup-activation action with updated dependencies

Co-authored-by: pelikhan <[email protected]>

* Co-authored-by: pelikhan <[email protected]>

* Convert setup-activation to shell script with no runtime dependencies

Co-authored-by: pelikhan <[email protected]>

* Rebuild and recompile before merge

* Merge main branch (seventh merge)

Co-authored-by: pelikhan <[email protected]>

* Merge main, format, and recompile workflows (eighth merge)

Co-authored-by: pelikhan <[email protected]>

* Merge main, format, lint, and recompile (ninth merge)

Co-authored-by: pelikhan <[email protected]>

* Merge main, format, lint, and recompile (tenth merge)

Co-authored-by: pelikhan <[email protected]>

* Update dev.md to read issue and post poem in staged mode

Co-authored-by: pelikhan <[email protected]>

* Add isRelease/IsDev helper methods and use them for action mode checks

Co-authored-by: pelikhan <[email protected]>

* Recompile all workflows in dev mode with local action paths

Co-authored-by: pelikhan <[email protected]>

* Add setup action to externalize all workflow job scripts

Co-authored-by: pelikhan <[email protected]>

* Use script registry to dynamically discover all .cjs files for setup action

Co-authored-by: pelikhan <[email protected]>

* Co-authored-by: pelikhan <[email protected]>

* Remove inline mode and externalize all scripts via setup-activation action

Co-authored-by: pelikhan <[email protected]>

* Remove inline mode, default to dev mode with local action paths

BREAKING CHANGE: Inline script mode has been removed. All workflows now use external actions to load scripts via require() calls. Default mode is now dev (local action paths) instead of inline. Release mode uses version tags, never dirty SHAs.

- Removed ActionModeInline constant and all inline mode references
- Updated DetectActionMode() to default to dev mode instead of inline
- Updated compiler defaults to use ActionModeDev
- Removed IsInline() helper method
- Updated UsesExternalActions() to always return true
- Fixed all test files to remove ActionModeInline references
- Updated action_reference.go to remove inline mode handling
- All 121 workflows recompiled successfully with dev mode

Co-authored-by: pelikhan <[email protected]>

* Rename action from setup-activation to setup

- Renamed actions/setup-activation directory to actions/setup
- Updated all code references in pkg/cli/actions_build_command.go
- Updated all code references in pkg/workflow/compiler_activation_jobs.go
- Updated documentation in actions/README.md
- Updated documentation in actions/setup/README.md
- Rebuilt action with new name
- Recompiled all 121 workflows successfully
- All workflows now reference ./actions/setup instead of ./actions/setup-activation
- Formatted and linted all code successfully

Co-authored-by: pelikhan <[email protected]>

* Rename step from "Setup Activation Scripts" to "Setup Scripts"

- Updated step name in pkg/workflow/compiler_activation_jobs.go (2 occurrences)
- Recompiled all 121 workflows successfully
- All workflows now show "Setup Scripts" instead of "Setup Activation Scripts"

Co-authored-by: pelikhan <[email protected]>

* Co-authored-by: pelikhan <[email protected]>

* Convert conclusion and pre-activation jobs to use setup action with require() calls

- Modified buildConclusionJob to add setup action at job start with checkout in dev mode
- Updated buildGitHubScriptStepWithoutDownload to support require() via ScriptFile field
- Added ScriptFile field to GitHubScriptStepConfig struct
- Updated conclusion job scripts to use require(): noop.cjs, missing_tool.cjs, notify_comment_error.cjs
- Updated unlock-issue step to use require() instead of inline script
- Fixed DetectActionMode to treat "-dirty" version suffix as dev mode
- Recompiled all 121 workflows successfully
- All workflows now use ./actions/setup (local path) in dev mode
- Checkout actions folder step present in both pre_activation and conclusion jobs
- Formatted and linted all code successfully

Co-authored-by: pelikhan <[email protected]>

* Convert agent and detection jobs to use setup action with require() calls

- Modified buildMainJob to add setup action + sparse checkout at job start
- Modified buildThreatDetectionSteps to add setup action + sparse checkout at job start
- Both jobs now load scripts via setup action before executing
- Agent job: Setup action added before repository checkout step
- Detection job: Setup action added before artifact download steps
- Formatted and linted all code successfully
- Recompiled all 121 workflows successfully (121/121)
- All workflows now use ./actions/setup (local path) in dev mode
- Total: 737 jobs, 9320 steps, 3507 scripts (43.2 MB)

Co-authored-by: pelikhan <[email protected]>

* Migrate upload_assets, cache_memory, and repo_memory jobs to use setup action

- Modified buildUploadAssetsJob in publish_assets.go to add setup action at job start
- Modified buildUpdateCacheMemoryJob in cache.go to add setup action at job start
- Modified buildPushRepoMemoryJob in repo_memory.go to add setup action at job start
- All three jobs now include sparse checkout + setup action in dev mode
- Formatted and linted all code successfully
- Recompiled all 121 workflows successfully (121/121)
- All workflows now use ./actions/setup (local path) in dev mode
- Total: 737 jobs, 9416 steps, 3507 scripts (43.4 MB)

Co-authored-by: pelikhan <[email protected]>

* Stage lock file changes before merge

* Merge main and recompile all workflows

- Merged origin/main into branch
- Resolved conflicts in .gitignore and dev.lock.yml
- Rebuilt binary with latest main changes
- Recompiled all 121 workflows successfully (121/121)
- All workflows continue to use ./actions/setup (local path) in dev mode
- Total: 737 jobs, 9416 steps, 3507 scripts (43.4 MB)

Co-authored-by: pelikhan <[email protected]>

* Fix action mode detection to use local paths for dev builds

- Updated DetectActionMode to require version to start with 'v' for release mode
- Git SHAs (like b72a404) are now correctly detected as dev mode
- Rebuilt binary and recompiled all 121 workflows successfully
- All workflows now use ./actions/setup (local path) in dev mode
- Verified 0 workflows use remote SHA references
- Total: 737 jobs, 9416 steps, 3507 scripts (43.4 MB)

Co-authored-by: pelikhan <[email protected]>

* Merge main and recompile all workflows

- Merged origin/main into branch
- Resolved conflicts automatically in 7 lock files
- Merged updates from main: version.go, header improvements, CLI updates
- Rebuilt binary with latest main changes
- Recompiled all 121 workflows successfully (121/121)
- All workflows continue to use ./actions/setup (local path) in dev mode
- Total: 737 jobs, 9510 steps, 3507 scripts (43.2 MB)

Co-authored-by: pelikhan <[email protected]>

* Fix setup action to pass INPUT_DESTINATION in composite action

- Modified actions/setup/action.yml to explicitly pass destination input as INPUT_DESTINATION env var
- Composite actions don't automatically convert inputs to INPUT_* environment variables
- This fixes the "Cannot find module '/tmp/gh-aw/actions/activation/noop.cjs'" error in conclusion job
- Setup action now correctly receives the destination path and creates files in /tmp/gh-aw/actions/activation/
- Recompiled all 121 workflows successfully with the fix
- Formatted and linted all code successfully
- Total: 737 jobs, 9510 steps, 3507 scripts (43.2 MB)

Co-authored-by: pelikhan <[email protected]>

* Change setup action destination to /tmp/gh-aw/actions/ and add constant

- Added SetupActionDestination constant in bundler_file_mode.go
- Changed destination from /tmp/gh-aw/actions/activation to /tmp/gh-aw/actions
- Updated all references to use the constant instead of hardcoded strings
- Updated action.yml default value to match new path
- Files modified:
  - pkg/workflow/bundler_file_mode.go (added constant)
  - pkg/workflow/cache.go
  - pkg/workflow/compiler_activation_jobs.go
  - pkg/workflow/notify_comment.go
  - pkg/workflow/publish_assets.go
  - pkg/workflow/repo_memory.go
  - pkg/workflow/safe_outputs_steps.go
  - pkg/workflow/threat_detection.go
  - actions/setup/action.yml
- Recompiled all 121 workflows successfully (121/121)
- All workflows now use /tmp/gh-aw/actions as destination
- All require() statements updated to use new path
- Total: 737 jobs, 9510 steps, 3507 scripts (43.2 MB)

Co-authored-by: pelikhan <[email protected]>

* Add missing scripts to GetJavaScriptSources and setup action

- Added 35 missing scripts from scripts.go to GetJavaScriptSources() map in js.go
- Added noop.cjs, unlock-issue.cjs, missing_tool.cjs, and notify_comment_error.cjs to setup.sh
- Fixed "Cannot find module '/tmp/gh-aw/actions/noop.cjs'" error in conclusion job
- Setup action now embeds 117 scripts instead of 82
- Setup.sh now contains 15 essential scripts including all conclusion job dependencies
- All 121 workflows compiled successfully (121/121)
- Total: 737 jobs, 9510 steps, 3507 scripts (43.2 MB)
- Verified 117 workflows use noop.cjs via require() calls

Co-authored-by: pelikhan <[email protected]>

* Fix noop.cjs to use absolute path for load_agent_output require

- Changed require("./load_agent_output.cjs") to require("/tmp/gh-aw/actions/load_agent_output.cjs")
- Fixes "Cannot find module" error when noop.cjs is loaded via require() from workflows
- Relative requires don't work when script is executed from a different directory
- All 121 workflows compiled successfully (121/121)
- Verified noop.cjs now correctly requires load_agent_output.cjs from setup action destination
- Total: 737 jobs, 9510 steps, 3507 scripts (43.2 MB)

Co-authored-by: pelikhan <[email protected]>

* Export main function from scripts instead of calling it directly

- Modified noop.cjs, unlock-issue.cjs, missing_tool.cjs, and notify_comment_error.cjs to export main function via module.exports
- Updated safe_outputs_steps.go to require() and await the exported main function
- Updated notify_comment.go to use the same pattern for unlock-issue.cjs
- Scripts no longer execute immediately when required - calling code controls execution
- All 121 workflows compiled successfully (121/121)
- Formatted and linted all code successfully
- Total: 737 jobs, 9510 steps, 3507 scripts (43.2 MB)

Co-authored-by: pelikhan <[email protected]>

* Fix noop.cjs embedded in setup.sh to use absolute path

- Updated actions/setup/setup.sh to use absolute path for load_agent_output require
- Changed require("./load_agent_output.cjs") to require("/tmp/gh-aw/actions/load_agent_output.cjs")
- Source file pkg/workflow/js/noop.cjs already has correct absolute path
- Source file correctly exports { main } without calling it
- This fixes the require path mismatch in the embedded shell script
- All linting passed successfully

Co-authored-by: pelikhan <[email protected]>

* Refactor setup action to copy files instead of embedding them

- Modified buildSetupAction() to copy JavaScript files to js/ directory instead of embedding in setup.sh
- Rewrote setup.sh to copy files from js/ to destination using bash commands
- Setup action now uses same pattern as setup-safe-outputs action
- JavaScript files (117 .cjs files) are built into actions/setup/js/ by make actions-build
- Setup.sh uses simple cp commands to copy files at runtime
- No more here-documents (EOF markers) embedding full file contents
- Added actions/setup/js/ to .gitignore as it's a build artifact
- All 121 workflows compile successfully
- Formatted and linted all code successfully

Co-authored-by: pelikhan <[email protected]>

* Commit actions/setup/js/ directory to fix sparse checkout workflows (#7389)

* Convert safe_outputs job to use setup action and require mode (#7391)

* Merge main and recompile all workflows

- Successfully merged latest changes from origin/main
- Resolved conflicts in campaign-manager.lock.yml and go-file-size-reduction-project64.campaign.g.lock.yml
- Rebuilt binary with latest version
- Rebuilt all actions with make actions-build (117 scripts copied to setup action)
- Recompiled all 121 workflows successfully (121/121)
- Validated lock file format - all workflows properly formatted
- Total: 737 jobs, 9624 steps, 3393 scripts (36.3 MB)
- All workflows use local action path ./actions/setup in dev mode
- Lock files contain proper YAML structure and formatting

Co-authored-by: pelikhan <[email protected]>

* Fix invalid runner ubuntu-slim to ubuntu-latest

- Changed DefaultActivationJobRunnerImage constant from "ubuntu-slim" to "ubuntu-latest"
- ubuntu-slim is not a valid GitHub Actions runner type
- Fixed dev.lock.yml and all other workflows using activation jobs
- Recompiled all 121 workflows successfully (121/121)
- Validated dev.lock.yml is valid YAML and valid GitHub Actions workflow
- All workflows now use ubuntu-latest for activation/pre-activation jobs
- Total: 737 jobs, 9624 steps, 3393 scripts (36.3 MB)

Co-authored-by: pelikhan <[email protected]>

* Fix setup action reference in safe_outputs jobs

- Fixed resolveActionReference calls to use "./actions/setup" instead of "actions/setup"
- The missing "./" prefix caused GitHub Actions to reject the workflow (invalid action format)
- Updated both occurrences in compiler_safe_outputs_core.go (lines 65 and 392)
- Reverted ubuntu-slim runner as it is actually valid (was not the issue)
- All 121 workflows recompiled successfully (121/121)
- Validated dev.lock.yml with actionlint - no errors
- Total: 737 jobs, 9624 steps, 3393 scripts (36.3 MB)

Co-authored-by: pelikhan <[email protected]>

* Merge main and recompile all workflows

- Successfully merged latest changes from origin/main
- Resolved conflict in .gitignore (combined both branches' additions)
- Rebuilt binary with latest version (641c9d1)
- Rebuilt all actions with make actions-build (117 scripts in setup action)
- Recompiled all 123 workflows successfully (123/123)
- Total: 747 jobs, 9763 steps, 3444 scripts (36.8 MB)
- All workflows use local action path ./actions/setup in dev mode
- Setup action properly configured with file copying pattern

Co-authored-by: pelikhan <[email protected]>

* Export main from safe output scripts instead of auto-executing (#7409)

* Initial plan

* Export main from safe output scripts and update tests

- Changed all safe output scripts to export main instead of executing it
- Updated test files to call main() explicitly after importing/evaluating
- Fixed context global exposure (already present in compiler)
- Updated 24 script files and their corresponding tests

Co-authored-by: pelikhan <[email protected]>

* Fix remaining test failures for safe output script changes

- Updated create_pull_request.test.cjs to handle module.exports pattern
- Updated missing_tool.test.cjs to provide mock module object
- Updated push_to_pull_request_branch.test.cjs assertion
- Fixed add_reaction_and_edit_comment.cjs to export main

Test results improved from 65 failures to 15 failures

Co-authored-by: pelikhan <[email protected]>

* Complete safe output script export changes with recompiled workflows

- All safe output scripts now export main instead of executing it
- Recompiled all workflow lock files with updated scripts
- Updated tests to handle new module.exports pattern
- Context object already available in global scope (compiler line 519)

The scripts are now ready to be called from github-script with await main()

Co-authored-by: pelikhan <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: pelikhan <[email protected]>

* Fix add_comment.cjs to use absolute paths for require statements

- Changed relative requires (./file.cjs) to absolute paths (/tmp/gh-aw/actions/file.cjs)
- Updated 5 require statements: load_agent_output, messages_footer, get_repository_url, temporary_id, get_tracker_id
- add_comment.cjs already exports main function correctly (no changes needed to export pattern)
- Relative requires fail when script is loaded via require() from different directory
- Rebuilt actions with make actions-build (117 scripts in setup action)
- Rebuilt binary with latest changes
- Recompiled all 123 workflows successfully (123/123)
- Total: 747 jobs, 9763 steps, 3444 scripts (36.8 MB)
- All workflows use local action path ./actions/setup in dev mode

Co-authored-by: pelikhan <[email protected]>

* Merge main, format, lint, and recompile all workflows

- Successfully merged origin/main (resolved conflict in playground-org-project-update-issue.lock.yml)
- Formatted all code with make fmt (all files unchanged)
- Linted all code with make lint (0 issues, all validations passed)
- Rebuilt binary with latest changes (version 340474d-dirty)
- Rebuilt all actions with make actions-build (117 scripts in setup action)
- Recompiled all 123 workflows successfully (123/123)
- Total: 747 jobs, 9767 steps, 3446 scripts (36.8 MB)
- All workflows use local action path ./actions/setup in dev mode
- Note: Some workflow tests need updates for new require() pattern (expected breaking change from inline mode removal)

Co-authored-by: pelikhan <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: pelikhan <[email protected]>
Co-authored-by: Peli de Halleux <[email protected]>
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