Skip to content

Add job-level environment variables for safe outputs configuration only - #1061

Merged
pelikhan merged 9 commits into
mainfrom
copilot/fix-358a918a-48c1-412a-b782-2f0599e27eab
Sep 27, 2025
Merged

pelikhan merged 9 commits into
mainfrom
copilot/fix-358a918a-48c1-412a-b782-2f0599e27eab

Conversation

Copilot AI commented Sep 26, 2025 •

Copy link
Copy Markdown
Contributor

Overview

This PR implements job-level environment variables for the "agent" job when safe outputs are configured, specifically limited to configuration variables needed at the job level.

Problem

Previously, safe output configuration variables like GITHUB_AW_SAFE_OUTPUTS_CONFIG were only available at the step level. Steps that needed to reference these variables had to use expressions like ${{ env.GITHUB_AW_SAFE_OUTPUTS_CONFIG }}, but the variables weren't actually defined at the job level, causing potential issues with variable resolution.

Solution

Key Changes

  1. Enhanced Job Struct: Added Env map[string]string field to the Job struct to support job-level environment variables.

  2. Updated YAML Rendering: Modified the renderJob() function to render the job-level env: section with proper indentation and sorted keys for consistent output.

  3. Modified Main Job Builder: Updated buildMainJob() function to automatically populate only essential configuration environment variables when safe outputs are configured:

    • GITHUB_AW_SAFE_OUTPUTS_CONFIG: Contains the JSON configuration for safe outputs (properly quoted)
    • Excluded: GITHUB_AW_SAFE_OUTPUTS (remains available through step-level export)
    • Excluded: Custom environment variables from safe-outputs.env (passed to individual safe output jobs where needed)
  4. Lock File Management: Reverted automatically generated .lock.yml files to their original state to prevent unintended changes to existing workflows while preserving the new functionality for future workflows.

Example Output

The agent job now includes only essential configuration environment variables:

agent:
  needs: activation
  runs-on: ubuntu-latest
  permissions: read-all
  env:
    GITHUB_AW_SAFE_OUTPUTS_CONFIG: "{\"create-issue\":{}}"
  outputs:
    output: ${{ steps.collect_output.outputs.output }}
  steps: [...]

Benefits

  • Proper Variable Resolution: Steps can now reliably reference safe outputs configuration using ${{ env.GITHUB_AW_SAFE_OUTPUTS_CONFIG }} syntax
  • Clean Separation: Only configuration needed at the job level is included; runtime values and custom variables are handled appropriately in their respective contexts
  • Consistent Configuration: Safe output configuration is available at the job level for all steps to use
  • Backward Compatibility: All existing functionality continues to work unchanged, with existing workflows preserved in their original state

Architecture Decisions

  • GITHUB_AW_SAFE_OUTPUTS: Excluded from job level as it's dynamically set by the "Setup agent output" step using core.exportVariable()
  • Custom safe-outputs.env variables: Excluded from job level as they belong in individual safe output jobs where they're actually used
  • GITHUB_AW_SAFE_OUTPUTS_CONFIG: Included at job level as it's needed by multiple steps for configuration purposes

Testing

  • Added comprehensive unit and integration tests in main_job_env_test.go
  • All existing tests continue to pass
  • Manual CLI testing confirms correct environment variable generation
  • Validated proper JSON quoting and YAML formatting
  • Verified that existing workflow files remain unchanged
  • Confirmed that custom variables are still properly passed to safe output jobs

This change ensures that safe outputs functionality works correctly by providing only the necessary configuration environment variables at the job level scope while maintaining proper separation of concerns.

Original prompt

Update the compiler to generate an "env" section at the job level for the "action" job with the environment variables for safe outputs (file location and config)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update the compiler to generate an "env" section at the job level for the "action" job with the environment variables for safe outputs (file location and config) Add job-level environment variables for safe outputs in agent job Sep 26, 2025
Copilot AI requested a review from pelikhan September 26, 2025 22:18
Comment thread .github/workflows/ci-doctor.lock.yml Resolved
Comment thread pkg/workflow/compiler.go Resolved
Comment thread pkg/workflow/compiler.go Outdated
}

// Add custom environment variables from safe-outputs.env
if len(data.SafeOutputs.Env) > 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot remove this code, safeoutputs.env do not belong here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the code that adds custom environment variables from safe-outputs.env to the job-level environment. These custom variables are still passed to individual safe output jobs where they're needed, but no longer appear at the agent job level. Updated tests accordingly. (e82abf4)

Copilot AI changed the title Add job-level environment variables for safe outputs in agent job Add job-level environment variables for safe outputs in agent job (excluding GITHUB_AW_SAFE_OUTPUTS) Sep 27, 2025
Copilot AI requested a review from pelikhan September 27, 2025 00:31
Copilot AI changed the title Add job-level environment variables for safe outputs in agent job (excluding GITHUB_AW_SAFE_OUTPUTS) Add job-level environment variables for safe outputs configuration only Sep 27, 2025
…ty and error handling

- Simplified environment variable checks and JSON parsing in create_discussion.js and create_issue.js
- Enhanced logging for better debugging and user feedback
- Streamlined discussion and issue creation logic, ensuring consistent handling of labels and titles
- Added comments to parent issues when creating related issues
- Improved summary output for staged mode previews
@pelikhan
pelikhan marked this pull request as ready for review September 27, 2025 00:40
@pelikhan
pelikhan merged commit 8a599f9 into main Sep 27, 2025
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