Skip to content

Fix custom job runs-on array and object forms silently dropped#19407

Merged
pelikhan merged 3 commits intomainfrom
copilot/fix-runs-on-array-object-handling
Mar 3, 2026
Merged

Fix custom job runs-on array and object forms silently dropped#19407
pelikhan merged 3 commits intomainfrom
copilot/fix-runs-on-array-object-handling

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

  • Fix runs-on handling in buildCustomJobs() to support array and object forms
  • Add unit tests for string, array, and object runs-on forms
  • Add error path test case using unmarshalable value (channel), asserting error mentions job name
  • Run make fmt, make lint, make build to validate
Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Fix custom jobs runs-on array and object forms being silently dropped</issue_title>
<issue_description>## Objective

Fix buildCustomJobs() in pkg/workflow/compiler_jobs.go to correctly handle runs-on values that are arrays or objects, not just strings.

Context

From discussion #19383 (HIGH-2): The current code does a string type assertion on runs-on:

if runsOnStr, ok := runsOn.(string); ok {
    job.RunsOn = "runs-on: " + runsOnStr
}
// array/object: falls through silently, job.RunsOn stays ""

When runs-on is an array (e.g., [self-hosted, linux, large]), the assertion fails, job.RunsOn stays empty, and the compiled YAML is invalid — missing the required runs-on field. The top-level runs-on correctly uses extractTopLevelYAMLSection which handles all forms.

Approach

In pkg/workflow/compiler_jobs.go, in buildCustomJobs() around line 465, update the runs-on extraction:

  1. For the string case: keep existing behavior ("runs-on: " + runsOnStr)
  2. For array and object cases: use goccy/go-yaml to marshal the value back to a YAML snippet, then prepend "runs-on: "
  3. Add a validation error if runs-on is present but cannot be marshaled

Example target output for array form:

runs-on:
  - self-hosted
  - linux
  - large

Files to Modify

  • pkg/workflow/compiler_jobs.go — update runs-on handling in buildCustomJobs()

Acceptance Criteria

  • runs-on: ubuntu-latest (string) continues to work correctly
  • runs-on: [self-hosted, linux, large] (array) compiles to valid YAML
  • runs-on: {group: my-runners} (object) compiles to valid YAML
  • Invalid runs-on values produce a validation error (not silent empty output)
  • Unit tests added for all three runs-on forms
  • Run make agent-finish before committing

Generated by Plan Command for issue #discussion #19383 ·

  • expires on Mar 5, 2026, 10:49 AM UTC

Comments on the Issue (you are @copilot in this section)


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

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix custom jobs runs-on array and object forms handling Fix custom job runs-on array and object forms silently dropped Mar 3, 2026
@pelikhan pelikhan marked this pull request as ready for review March 3, 2026 11:16
Copilot AI review requested due to automatic review settings March 3, 2026 11:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes buildCustomJobs() so custom job runs-on is no longer silently dropped when specified in YAML array/object form, preventing invalid compiled workflows.

Changes:

  • Extend custom job runs-on extraction to support string, array, and object YAML forms (marshaling non-string forms to YAML and emitting an error on marshal failure).
  • Add a unit test covering string/array/object runs-on forms for custom jobs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/workflow/compiler_jobs.go Updates custom job runs-on handling to marshal array/object forms into an indented YAML snippet instead of dropping the field.
pkg/workflow/compiler_jobs_test.go Adds TestBuildCustomJobsRunsOnForms to verify string/array/object runs-on forms are preserved in job.RunsOn.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2205 to +2227
tests := []struct {
name string
runsOn any
expectedRunsOn string
expectedContains []string
shouldErr bool
}{
{
name: "string form",
runsOn: "ubuntu-latest",
expectedRunsOn: "runs-on: ubuntu-latest",
},
{
name: "array form",
runsOn: []any{"self-hosted", "linux", "large"},
expectedContains: []string{"runs-on:", "- self-hosted", "- linux", "- large"},
},
{
name: "object form",
runsOn: map[string]any{"group": "my-runners"},
expectedContains: []string{"runs-on:", "group: my-runners"},
},
}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The new runs-on handling returns an error when YAML marshaling fails, but this test suite never exercises that path (and shouldErr is unused). Add a test case with an unmarshalable runs-on value (e.g., a function or channel) and assert that buildCustomJobs returns an error mentioning the job name; or remove shouldErr if the error-path test is intentionally out of scope.

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Contributor

pelikhan commented Mar 3, 2026

@copilot Apply comments

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot Apply comments

Done in 0ceede6. Added a fourth test case "unmarshalable value returns error" using make(chan int) (channels can't be marshaled by go-yaml), which confirms buildCustomJobs returns an error that includes the job name.

@pelikhan pelikhan merged commit 0c9d366 into main Mar 3, 2026
77 checks passed
@pelikhan pelikhan deleted the copilot/fix-runs-on-array-object-handling branch March 3, 2026 11:45
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.

[plan] Fix custom jobs runs-on array and object forms being silently dropped

3 participants