linera-io/linera-protocol · error
GITHUB_PR_COMMIT_HASH is not set! This must be run from with
Error message
GITHUB_PR_COMMIT_HASH is not set! This must be run from within CI
What it means
In CI mode, from_env reads GITHUB_PR_COMMIT_HASH — the head commit of the pull request — and fails when it is unset, because later steps compare runs and jobs against that exact commit. It is normally provided by the workflow config on pull_request events.
Source
Thrown at linera-summary/src/github.rs:124
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 {
repository: GithubRepository::from_env(is_local)?,
pr_commit_hash,
pr_branch,
base_branch,View on GitHub (pinned to 6c226ddcb3)
Solutions
- Run inside a pull_request-triggered workflow that exports GITHUB_PR_COMMIT_HASH (typically from github.event.pull_request.head.sha)
- Or export it manually: GITHUB_PR_COMMIT_HASH=<full-sha> alongside the other GITHUB_PR_* variables
- Check the workflow's env: block — a typo'd variable name produces exactly this failure
Example fix
# before
env:
GITHUB_PR_COMMIT: ${{ github.event.pull_request.head.sha }}
# after
env:
GITHUB_PR_COMMIT_HASH: ${{ github.event.pull_request.head.sha }} Defensive patterns
Strategy: validation
Validate before calling
#!/usr/bin/env bash
: "${GITHUB_PR_COMMIT_HASH:?GITHUB_PR_COMMIT_HASH is required (PR head sha)}" Try / catch
if let Err(e) = Github::new(false, None) {
if e.to_string().contains("GITHUB_PR_COMMIT_HASH") {
eprintln!("export GITHUB_PR_COMMIT_HASH=${{ github.event.pull_request.head.sha }} in the workflow env");
}
return Err(e.into());
} Prevention
- Centralize the four GITHUB_PR_*/BASE exports in one reusable env block
- Name variables exactly as the tool expects — no abbreviations
- Add a workflow lint that greps for all required GITHUB_* names
When it happens
Trigger: A CI invocation missing GITHUB_PR_COMMIT_HASH: running outside GitHub Actions, or a workflow that forgot to export github.event.pull_request.head.sha into this variable.
Common situations: Custom workflow YAML that sets only some GITHUB_* variables; local emulation of CI; refactoring that renamed the export step.
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_NUMBER is not set! This must be run from within CI
- 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/8db7d5970b70eea0.
Report an issue: GitHub.