Skip to content

Add jobs.<name>.then to inject custom pre-jobs before builtin workflow jobs - #26796

Closed
pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/add-pre-steps-to-jobs
Closed

pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/add-pre-steps-to-jobs

Conversation

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

This change adds a then dependency mechanism for top-level custom jobs, so a custom job can run as a pre-step for builtin/compiler-managed jobs. It addresses the gap where pre-step orchestration was only practical via manual needs wiring and did not compose cleanly with generated builtin jobs.

  • What changed

    • Added jobs.<job>.then to schema (string | string[]) in main_workflow_schema.json.
    • Extended custom job compilation to parse then, normalize aliases, and register deferred builtin dependency edges.
    • Applied deferred then edges after builtin/custom jobs are created, so generated jobs can depend on the custom job without requiring users to patch lockfiles.
    • Added validation for unsupported targets and invalid usage (e.g., targeting non-builtin/custom jobs incorrectly).
  • Compiler behavior

    • then targets are normalized and resolved against builtin job IDs.
    • Supported aliases include dash/underscore normalization where relevant (e.g., safe-outputs → safe_outputs, pre-activation → pre_activation).
    • Dependencies are appended idempotently (no duplicate needs entries).
  • Code path updates

    • WorkflowData now tracks pending then dependency edges.
    • buildCustomJobs(...) now extracts and records then relationships.
    • buildJobs(...) now applies recorded then relationships before final conclusion-job ordering.
jobs:
  prepare-safe:
    runs-on: ubuntu-latest
    then: [safe-outputs, activation]
    steps:
      - run: echo "prepare artifacts/config"

safe-outputs:
  create-issue: {}

In this example, both safe_outputs and activation are compiled to depend on prepare-safe, allowing custom pre-work to run before builtin job execution.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot review changes and keep working

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