rust-lang/rust · error · anyhow::Error

Cannot determine the type of workflow that is being executed

Error message

Cannot determine the type of workflow that is being executed

What it means

Thrown by citool's calculate_job_matrix when GitHubContext::get_run_type() returns None. get_run_type matches the GITHUB_EVENT_NAME and GITHUB_REF environment variables against a fixed allowlist: pull_request events, or push events to the branches automation/bors/try, automation/bors/try-perf, automation/bors/auto, or main. Any other (event, ref) pair yields None, so citool cannot decide which job set to schedule and aborts.

Source

Thrown at src/ci/citool/src/jobs.rs:376

                env,
                continue_on_error: job.continue_on_error,
                free_disk: job.free_disk,
                doc_url: job.doc_url,
                codebuild: job.codebuild,
            }
        })
        .collect();

    Ok(jobs)
}

pub fn calculate_job_matrix(
    db: JobDatabase,
    gh_ctx: GitHubContext,
    channel: &str,
) -> anyhow::Result<()> {
    let run_type = gh_ctx.get_run_type().ok_or_else(|| {
        anyhow::anyhow!("Cannot determine the type of workflow that is being executed")
    })?;
    eprintln!("Run type: {run_type:?}");

    let jobs = calculate_jobs(&run_type, &db, channel)?;
    if jobs.is_empty() && !matches!(run_type, RunType::MainJob) {
        return Err(anyhow::anyhow!("Computed job list is empty"));
    }

    let run_type = match run_type {
        RunType::PullRequest => "pr",
        RunType::TryJob { .. } => "try",
        RunType::AutoJob => "auto",
        RunType::MainJob => "main",
    };

    eprintln!("Output");
    eprintln!("jobs={jobs:?}");
    eprintln!("run_type={run_type}");

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Set GITHUB_EVENT_NAME to pull_request or push, and GITHUB_REF to one of the recognized branch refs (refs/heads/main, refs/heads/automation/bors/try, etc.).
  2. If a genuinely new workflow event must be scheduled, add a match arm to GitHubContext::get_run_type in src/ci/citool/src/main.rs mapping it to a RunType variant.
  3. For reproducing a job locally, call the local-execution subcommand (which takes a job name directly) instead of calculate-job-matrix.

Example fix

// before
$ GITHUB_EVENT_NAME=workflow_dispatch GITHUB_REF=refs/heads/main citool calculate-job-matrix
Error: Cannot determine the type of workflow that is being executed

// after (use a recognized event/branch pair)
$ GITHUB_EVENT_NAME=pull_request GITHUB_REF=refs/pull/123/merge citool calculate-job-matrix
Defensive patterns

Strategy: validation

Validate before calling

// Before calling calculate_job_matrix, verify the event/ref pair is recognized.
fn is_supported_run_type(event_name: &str, branch_ref: &str) -> bool {
    matches!(
        (event_name, branch_ref),
        ("pull_request", _)
        | ("push", "refs/heads/automation/bors/try-perf")
        | ("push", "refs/heads/try-perf")
        | ("push", "refs/heads/automation/bors/try")
        | ("push", "refs/heads/automation/bors/auto")
        | ("push", "refs/heads/main")
    )
}

if !is_supported_run_type(&gh_ctx.event_name, &gh_ctx.branch_ref) {
    eprintln!("Unsupported GitHub event/ref; cannot determine run type");
    std::process::exit(1);
}

Prevention

When it happens

Trigger: Invoking the calculate-job-matrix subcommand with GITHUB_EVENT_NAME/GITHUB_REF set to an unrecognized combination, e.g. event=workflow_dispatch, event=schedule, event=release, or a push to a feature branch like refs/heads/feature/foo.

Common situations: Running citool locally for testing without the GitHub env vars populated; a CI workflow triggered by a new event type that the matrix logic was never taught to handle; bors branch refs renamed so the literal string match in get_run_type no longer fires.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/cb1e65c28ef0071d. Report an issue: GitHub.