Refactor safe_outputs.go into focused modules (1530 → 4 files) #6145
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
pkg/workflow/safe_outputs.go(1530 lines) was a monolithic file mixing configuration parsing, step builders, job assembly, and environment variable handling. This refactoring splits it into focused modules with clear boundaries.Changes
File Structure
safe_outputs.go(8 lines): Module documentationsafe_outputs_config.go(1024 lines): Configuration parsing, frontmatter extraction, tool filtering, JSON generationsafe_outputs_steps.go(232 lines): GitHub Script and custom action step builders, token resolution chainssafe_outputs_env.go(176 lines): Environment variable composition, metadata builderssafe_outputs_jobs.go(137 lines): Job assembly orchestration, pre/post step handlingModule Boundaries
Config (
safe_outputs_config.go):Steps (
safe_outputs_steps.go):Env (
safe_outputs_env.go):Jobs (
safe_outputs_jobs.go):Impact
Config file at 1024 lines remains acceptable for its scope (parsing 20+ safe-output types with validation).
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/user/usr/bin/gh gh api user --jq .login 03/add_labels.js GO111MODULE 64/bin/node GOINSECURE GOMOD GOMODCACHE 6A4v8A-equB52/x0NfzuPN1kAbisUKyYG2/Q1fNnWbDeA3s2--quiet 1/x6�� ry=1 pkg/mod/github.com/creack/pty@v1.1.24/ioctl.go e/git GOINSECURE GOMOD GOMODCACHE e/git(http block)/usr/bin/gh gh api user --jq .login INVALID,NEW -j DROP -815452616 GO111MODULE 64/bin/go Linux-1.0.9/bin/1 env -json GO111MODULE 1/x64/bin/node GOINSECURE GOMOD GOMODCACHE e/git-remote-httsecurity(http block)/usr/bin/gh gh api user --jq .login t0 GO111MODULE 9b9806c5d0de58d6c0eba22eea51ca68b13/log.json GOINSECURE GOMOD GOMODCACHE e/git -tes�� om/actions/setup-python.git om/actions/setup-python.git ache/node/24.11.1/x64/bin/node -test.run=^Test GOWORK 707fee729a3f2d8amoby git(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor Large Go File: pkg/workflow/safe_outputs.go</issue_title>
<issue_description>The file
pkg/workflow/safe_outputs.gohas grown to 1530 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.Current State
pkg/workflow/safe_outputs.gopkg/workflow/safe_outputs_test.go)Refactoring Strategy
Proposed File Splits
safe_outputs_config.goformatSafeOutputsRunsOn,HasSafeOutputsEnabled,GetEnabledSafeOutputToolNames,extractSafeOutputsConfig,normalizeSafeOutputIdentifier,parseMessagesConfig,serializeMessagesConfig,generateSafeOutputsConfig,generateFilteredToolsJSON.safe_outputs_steps.gobuildCustomActionStep,buildGitHubScriptStep,buildGitHubScriptStepWithoutDownload, token helpers (addCustomActionGitHubToken,addCustomActionCopilotGitHubToken,addCustomActionAgentGitHubToken),buildAgentOutputDownloadSteps,GitHubScriptStepConfig.safe_outputs_env.goapplySafeOutputEnvToMap,applySafeOutputEnvToSlice,buildWorkflowMetadataEnvVars,buildWorkflowMetadataEnvVarsWithTrackerID,buildSafeOutputJobEnvVars,buildEngineMetadataEnvVars,(*Compiler).buildStandardSafeOutputEnvVars.safe_outputs_jobs.goSafeOutputJobConfig,(*Compiler).buildSafeOutputJob,buildGitHubScriptStepWithoutDownloadcall orchestration, safe-job specific assembly.Shared Utilities
safe_outputs_tokens.go(optional) if token helpers remain chunky after split; otherwise keep them in steps file.DefaultScriptRegistry/GetActionPinusage centralized in steps builder to avoid duplication.Interface Abstractions
type TokenResolver interface { ResolveGitHubToken(data *WorkflowData, preferred string) string }) to decouple token preference chains from step builders.Test Coverage Plan
safe_outputs_config_test.gosafe_outputs_steps_test.gosafe_outputs_env_test.gosafe_outputs_jobs_test.goImplementation Guidelines
make test-unitpasses after each split.Acceptance Criteria
make test-unit).make lint) and build succeeds (make build).Additional Context
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.