Skip to content

Emit custom runs-on label arrays for self-hosted runners (#387)#418

Open
avidenic wants to merge 4 commits into
Fallout-build:mainfrom
avidenic:features/387-github-actions-runs-on-labels
Open

Emit custom runs-on label arrays for self-hosted runners (#387)#418
avidenic wants to merge 4 commits into
Fallout-build:mainfrom
avidenic:features/387-github-actions-runs-on-labels

Conversation

@avidenic

Copy link
Copy Markdown
Contributor

Closes #387.

What

Adds a public RunsOnLabels (string[]) to GitHubActionsAttribute so a generated workflow can target a self-hosted runner pool by label array — runs-on: [self-hosted, linux, x64] — instead of only the fixed GitHubActionsImage enum scalar.

[GitHubActions(
    "deploy",
    GitHubActionsImage.UbuntuLatest, // mandatory; ignored for runs-on when RunsOnLabels is set
    On = [GitHubActionsTrigger.WorkflowDispatch],
    InvokedTargets = [nameof(Deploy)],
    RunsOnLabels = ["self-hosted", "linux", "x64"])]
public partial class Build : NukeBuild { /* ... */ }
deploy:
  name: ubuntu-latest
  runs-on: [self-hosted, linux, x64]
  steps:
    - uses: actions/checkout@v6
    # ...

How

  1. GitHubActionsAttribute.RunsOnLabels (string[], defaults empty) → carried through GetJobs onto a matching GitHubActionsJob.RunsOnLabels.
  2. GitHubActionsJob.Write branches: non-empty → runs-on: [a, b, c] via JoinCommaSpace(); otherwise the existing scalar runs-on: {Image.GetValue()} path is untouched.
  3. Validated at configuration-generation time:
    • requires exactly one image — a multi-image matrix can't be disambiguated by a single label set, so it fails the build with a clear message rather than silently emitting N identical-runner jobs. (The constructor mandates an image regardless; when RunsOnLabels is set the image is ignored for runs-on: and only names the job.)
    • rejects null/empty/whitespace entries, which would otherwise emit malformed YAML such as runs-on: [a, ].

Per the issue, the property is named RunsOnLabels (not the fork's earlier RunsOnOptionalInputs). Job- and step-level runs-on and any GitHubActionsImage enum changes are out of scope.

Backwards compatibility

Purely additive. RunsOnLabels defaults to empty, so existing [GitHubActions(...)] usages generate byte-for-byte identical YAML (no runs-on: change). Non-breaking → target/2026, no breaking-change.

Testing

  • runs-on-labels Verify snapshot in ConfigurationGenerationTest — locks the runs-on: [self-hosted, linux, x64] array form; the existing scalar snapshots are unchanged, guarding the fallback path.
  • GitHubActionsRunsOnLabelsValidationTest: matrix+labels throws; single-image+labels and matrix-without-labels don't; single label is valid; null/empty/whitespace element throws.
  • Full solution ./build.sh Test Pack is green locally, including the Nuke.* transition-shim test projects that consume this public API.

Merge preference: (x) squash (default) ( ) rebase

…ld#387)

GitHubActionsJob.Write emitted runs-on: {Image.GetValue()} unconditionally,
so a workflow could only target the fixed GitHubActionsImage enum. Self-hosted
runner pools are selected by a label array (runs-on: [self-hosted, linux, x64])
which was impossible to produce.

Add an additive string[] RunsOnLabels to GitHubActionsAttribute, plumb it
through GetJobs onto GitHubActionsJob, and branch in Write: non-empty emits the
array form via JoinCommaSpace(), otherwise the existing scalar path is unchanged.
RunsOnLabels defaults empty, so existing usages generate byte-for-byte identical
YAML. Validated at configuration-generation time: it requires exactly one image
(a multi-image matrix is ambiguous) and rejects null/empty/whitespace entries
that would emit malformed YAML.

Covered by a runs-on-labels Verify snapshot and GitHubActionsRunsOnLabelsValidationTest.
@avidenic avidenic marked this pull request as ready for review June 21, 2026 13:15
@avidenic avidenic requested a review from a team as a code owner June 21, 2026 13:15
@ChrisonSimtian ChrisonSimtian added the Can Merge These PRs are just waiting to be merged, nothing more to do and maintainer has approved label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Can Merge These PRs are just waiting to be merged, nothing more to do and maintainer has approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GitHubActions] generator: custom runs-on label arrays for self-hosted runners

2 participants