Add safe-outputs.steps for injecting custom steps into safe-output jobs#18460
Add safe-outputs.steps for injecting custom steps into safe-output jobs#18460
safe-outputs.steps for injecting custom steps into safe-output jobs#18460Conversation
|
@copilot entire steps get merged from imported workflows |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
safe-outputs.steps for injecting custom steps into safe-output jobs
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds support for injecting custom steps into the consolidated safe-outputs job through a new safe-outputs.steps configuration field. These steps execute after repository checkout and action setup, but before any safe-output processing logic runs.
Changes:
- Added
stepsfield to thesafe-outputsconfiguration schema and type definitions - Implemented parsing and merging logic for user-provided steps (concatenating imported workflow steps after main workflow steps)
- Integrated step injection into the safe-outputs job compilation with SHA pinning support
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/parser/schemas/main_workflow_schema.json | Added steps property to safe-outputs schema definition |
| pkg/workflow/compiler_types.go | Added Steps []any field to SafeOutputsConfig struct |
| pkg/workflow/safe_outputs_config.go | Implemented parsing of steps from safe-outputs frontmatter |
| pkg/workflow/imports.go | Added logic to concatenate imported steps with main workflow steps |
| pkg/workflow/compiler_safe_outputs_job.go | Implemented step injection with SHA pinning in the consolidated job |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for i, step := range data.SafeOutputs.Steps { | ||
| stepMap, ok := step.(map[string]any) | ||
| if !ok { | ||
| consolidatedSafeOutputsJobLog.Printf("Warning: safe-outputs step at index %d is not a valid step object (must be a map with properties like name, run, uses). Skipping this step.", i) |
There was a problem hiding this comment.
The error message should mention that the step will be skipped in the generated workflow to make the impact clearer to users reviewing logs.
| consolidatedSafeOutputsJobLog.Printf("Warning: safe-outputs step at index %d is not a valid step object (must be a map with properties like name, run, uses). Skipping this step.", i) | |
| consolidatedSafeOutputsJobLog.Printf("Warning: safe-outputs step at index %d is not a valid step object (must be a map with properties like name, run, uses). Skipping this step in the generated workflow.", i) |
| } | ||
| typedStep, err := MapToStep(stepMap) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to convert safe-outputs step at index %d to typed step: %w", i, err) |
There was a problem hiding this comment.
Error message could be more actionable by suggesting the user check the step structure in their workflow configuration.
| return nil, nil, fmt.Errorf("failed to convert safe-outputs step at index %d to typed step: %w", i, err) | |
| return nil, nil, fmt.Errorf("failed to convert safe-outputs step at index %d to typed step: %w. Check that this entry in 'safe-outputs.steps' uses the correct GitHub Actions step structure (a map with keys like 'name', 'run', or 'uses').", i, err) |
Adds a
safe-outputs.stepsfield that lets users inject custom steps into the consolidated safe-outputs job. Injected steps run after repository checkout and action setup, but before any safe-output code executes. Steps from imported workflows are merged (concatenated) with the main workflow's steps.Changes
pkg/parser/schemas/main_workflow_schema.json): Addedstepsproperty tosafe-outputs, using$ref: #/$defs/githubActionsStepto reuse the existing step interfacepkg/workflow/compiler_types.go): AddedSteps []anytoSafeOutputsConfigpkg/workflow/safe_outputs_config.go): Parsesstepsfromsafe-outputsfrontmatter blockpkg/workflow/compiler_safe_outputs_job.go): Injects steps after PR checkout (if any) and before the handler manager step; applies action SHA pinning consistent withsafe-outputs.jobs.stepspkg/workflow/imports.go): Mergessafe-outputs.stepsfrom imported workflows by concatenating imported steps after the main workflow's stepsExample
Resulting step order in the generated job:
Original prompt
💡 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.