linera-io/linera-protocol · error
GITHUB_PR_NUMBER is not set! This must be run from within CI
Error message
GITHUB_PR_NUMBER is not set! This must be run from within CI
What it means
In CI mode, GithubContext::from_env reads GITHUB_PR_NUMBER to identify the pull request; GitHub Actions sets it on pull_request events, and the tool treats its absence as 'not actually running in a PR CI context', failing fast.
Source
Thrown at linera-summary/src/github.rs:120
}
fn from_env(is_local: bool, pr_number: Option<u64>) -> Result<Self> {
let env_pr_commit_hash = env::var("GITHUB_PR_COMMIT_HASH");
let env_pr_branch = env::var("GITHUB_PR_BRANCH");
let env_base_branch = env::var("GITHUB_BASE_BRANCH");
let env_pr_number = env::var("GITHUB_PR_NUMBER");
let (pr_commit_hash, pr_branch, base_branch, pr_number) = if is_local {
let (commit_hash, branch_name, base) = Self::get_local_git_info()?;
(
commit_hash,
branch_name,
base,
pr_number.ok_or_else(|| anyhow!("pr_number is None"))?,
)
} else {
let pr_string = env_pr_number.map_err(|_| {
anyhow!("GITHUB_PR_NUMBER is not set! This must be run from within CI")
})?;
(
env_pr_commit_hash.map_err(|_| {
anyhow!("GITHUB_PR_COMMIT_HASH is not set! This must be run from within CI")
})?,
env_pr_branch.map_err(|_| {
anyhow!("GITHUB_PR_BRANCH is not set! This must be run from within CI")
})?,
env_base_branch.map_err(|_| {
anyhow!("GITHUB_BASE_BRANCH is not set! This must be run from within CI")
})?,
pr_string
.parse()
.map_err(|_| anyhow!("GITHUB_PR_NUMBER is not a valid number: {pr_string}"))?,
)
};
Ok(Self {View on GitHub (pinned to 6c226ddcb3)
Solutions
- Restrict the summary job to pull_request triggers in the workflow (if: github.event_name == 'pull_request')
- Or export a valid number: GITHUB_PR_NUMBER=42 with the other GITHUB_* variables
- Use pull_request_target/pull_request workflows where the variable is populated
Example fix
# before on: [push, pull_request] # after on: [pull_request]
Defensive patterns
Strategy: validation
Validate before calling
#!/usr/bin/env bash
# Fail fast before running the summary step in CI mode
: "${GITHUB_PR_NUMBER:?GITHUB_PR_NUMBER is required; run under a pull_request workflow}" Try / catch
if let Err(e) = Github::new(false, None) {
if e.to_string().contains("GITHUB_PR_NUMBER") {
eprintln!("no PR context; restrict this job to pull_request events");
}
return Err(e.into());
} Prevention
- Condition summary jobs on github.event_name == 'pull_request'
- Use :"${VAR:?}" guards in scripts that emulate CI
- Remember a nonzero numeric value is also required — a non-numeric value fails the sibling parse error
When it happens
Trigger: Running the summary workflow on a push event or workflow_dispatch (no PR context), or outside GitHub Actions without exporting the variable.
Common situations: Adding the summary step to a workflow whose triggers include push; manual workflow_dispatch runs; runners with a minimal environment.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- GITHUB_REPOSITORY is not set! This must be run from within C
- GITHUB_PR_COMMIT_HASH is not set! This must be run from with
- GITHUB_PR_BRANCH is not set! This must be run from within CI
- GITHUB_BASE_BRANCH is not set! This must be run from within
- No base jobs found!
AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22).
Data as JSON: /api/errors/24eb1e5f31156827.
Report an issue: GitHub.