denoland/deno · error · anyhow::Error
GITHUB_REF environment variable is not set
Error message
GITHUB_REF environment variable is not set
What it means
Provenance predicate construction reads `GITHUB_REF` (the branch/tag ref being built) after GITHUB_SERVER_URL and throws this message when it is unset. All of these variables are stock on GitHub Actions runners; a missing one means the publish process is not seeing the full Actions environment.
Source
Thrown at cli/tools/publish/provenance.rs:183
anyhow!("GITHUB_REPOSITORY environment variable is not set")
})?;
let rel_ref = std::env::var("GITHUB_WORKFLOW_REF")
.unwrap_or_default()
.replace(&format!("{}/", &repo), "");
let (workflow_path, workflow_ref) = if let Some(delimn) = rel_ref.find('@')
{
let (path, ref_) = rel_ref.split_at(delimn);
(path, &ref_[1..])
} else {
(rel_ref.as_str(), "")
};
let server_url = std::env::var("GITHUB_SERVER_URL").map_err(|_| {
anyhow!("GITHUB_SERVER_URL environment variable is not set")
})?;
let github_ref = std::env::var("GITHUB_REF")
.map_err(|_| anyhow!("GITHUB_REF environment variable is not set"))?;
let github_sha = std::env::var("GITHUB_SHA")
.map_err(|_| anyhow!("GITHUB_SHA environment variable is not set"))?;
let runner_env = std::env::var("RUNNER_ENVIRONMENT").map_err(|_| {
anyhow!("RUNNER_ENVIRONMENT environment variable is not set")
})?;
let run_id = std::env::var("GITHUB_RUN_ID")
.map_err(|_| anyhow!("GITHUB_RUN_ID environment variable is not set"))?;
let run_attempt = std::env::var("GITHUB_RUN_ATTEMPT").map_err(|_| {
anyhow!("GITHUB_RUN_ATTEMPT environment variable is not set")
})?;
Ok(Self {
build_definition: BuildDefinition {
build_type: GITHUB_BUILD_TYPE,
external_parameters: ExternalParameters {
workflow: GhaWorkflow {
ref_: workflow_ref.to_string(),
repository: format!("{}/{}", server_url, &repo),View on GitHub (pinned to 89f33cbef2)
Solutions
- Forward the complete Actions environment into the publish process (GITHUB_REF included)
- Run publish directly on the runner instead of through an env-sanitizing wrapper
- Drop `--provenance` when publishing outside GitHub Actions
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "$GITHUB_REF" ]; then echo "GITHUB_REF unset — publish --provenance needs the full Actions env" >&2 exit 1 fi
Prevention
- Do not hand-pick runner variables to forward; pass the whole environment
- Keep provenance publishes on unmodified GitHub-hosted runners
- Test the publish job on a real workflow run, not a local simulation
When it happens
Trigger: `deno publish --provenance` in an environment where GITHUB_REPOSITORY and GITHUB_SERVER_URL exist but GITHUB_REF does not — partial env forwarding into a container, or a wrapper that clears specific variables.
Common situations: Dockerized CI steps with selective env passthrough; minimal repro environments built by copying only a few runner variables.
Related errors
- GITHUB_REPOSITORY environment variable is not set
- GITHUB_SERVER_URL environment variable is not set
- GITHUB_SHA environment variable is not set
- RUNNER_ENVIRONMENT environment variable is not set
- GITHUB_RUN_ID environment variable is not set
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/025c61d40ea92033.
Report an issue: GitHub.