{"record":{"id":"3991662f0ee1d5e8","repo":"linera-io/linera-protocol","slug":"github-pr-branch-is-not-set-this-must-be-run-from","errorCode":null,"errorMessage":"GITHUB_PR_BRANCH is not set! This must be run from within CI","messagePattern":"GITHUB_PR_BRANCH is not set! This must be run from within CI","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-summary/src/github.rs","lineNumber":127,"sourceCode":"\n        let (pr_commit_hash, pr_branch, base_branch, pr_number) = if is_local {\n            let (commit_hash, branch_name, base) = Self::get_local_git_info()?;\n            (\n                commit_hash,\n                branch_name,\n                base,\n                pr_number.ok_or_else(|| anyhow!(\"pr_number is None\"))?,\n            )\n        } else {\n            let pr_string = env_pr_number.map_err(|_| {\n                anyhow!(\"GITHUB_PR_NUMBER is not set! This must be run from within CI\")\n            })?;\n            (\n                env_pr_commit_hash.map_err(|_| {\n                    anyhow!(\"GITHUB_PR_COMMIT_HASH is not set! This must be run from within CI\")\n                })?,\n                env_pr_branch.map_err(|_| {\n                    anyhow!(\"GITHUB_PR_BRANCH is not set! This must be run from within CI\")\n                })?,\n                env_base_branch.map_err(|_| {\n                    anyhow!(\"GITHUB_BASE_BRANCH is not set! This must be run from within CI\")\n                })?,\n                pr_string\n                    .parse()\n                    .map_err(|_| anyhow!(\"GITHUB_PR_NUMBER is not a valid number: {pr_string}\"))?,\n            )\n        };\n\n        Ok(Self {\n            repository: GithubRepository::from_env(is_local)?,\n            pr_commit_hash,\n            pr_branch,\n            base_branch,\n            pr_number,\n        })\n    }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-summary/src/github.rs#L109-L145","documentation":"In CI mode, from_env reads GITHUB_PR_BRANCH — the source branch of the pull request — and requires it to be set. The tool uses it (with the base branch) to scope workflow-run and job queries to the PR's branches, so without it the context is incomplete and construction aborts.","triggerScenarios":"A CI environment where GITHUB_PR_BRANCH was never exported: non-Actions execution, or a workflow env block that maps github.head_ref under a different name.","commonSituations":"Hand-written workflows exporting github.head_ref as something else; jobs spawned via workflow_dispatch; scripts borrowing CI code paths outside Actions.","solutions":["Export the PR head branch: GITHUB_PR_BRANCH: ${{ github.head_ref }} in the workflow env","Or set it manually together with GITHUB_PR_NUMBER, GITHUB_PR_COMMIT_HASH and GITHUB_BASE_BRANCH when emulating CI","Verify all four GITHUB_PR_*/GITHUB_BASE_* variables are present — they are checked as a group"],"exampleFix":"# before\nenv:\n  GITHUB_PR_HEAD: ${{ github.head_ref }}\n# after\nenv:\n  GITHUB_PR_BRANCH: ${{ github.head_ref }}","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\n: \"${GITHUB_PR_BRANCH:?GITHUB_PR_BRANCH is required (PR head branch)}\"","typeGuard":null,"tryCatchPattern":"if let Err(e) = Github::new(false, None) {\n    if e.to_string().contains(\"GITHUB_PR_BRANCH\") {\n        eprintln!(\"export GITHUB_PR_BRANCH=${{ github.head_ref }} in the workflow env\");\n    }\n    return Err(e.into());\n}","preventionTips":["Map github.head_ref to GITHUB_PR_BRANCH explicitly in the workflow env block","Check all four variables together in a preflight script","Prefer pull_request-triggered workflows where head_ref is always populated"],"tags":["linera","ci","github-actions","environment"],"backgroundTag":"missing-env-var","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}