FuelLabs/fuels-rs · error
GITHUB_TOKEN is not set in the environment
Error message
GITHUB_TOKEN is not set in the environment
What it means
The repository's change-log maintenance script (scripts/change-log) reads GITHUB_TOKEN from the environment after loading .env via dotenv, and panics if it is unset. The token authenticates the octocrab GitHub client used to list branches and pull requests for changelog generation.
Source
Thrown at scripts/change-log/src/main.rs:15
use std::env;
use change_log::{
adapters::octocrab::OctocrabAdapter, domain::changelog::generate_changelog,
ports::github::GitHubPort,
};
use dialoguer::FuzzySelect;
use dotenv::dotenv;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let github_token =
env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN is not set in the environment");
let repo_owner = env::var("GITHUB_REPOSITORY_OWNER").unwrap_or_else(|_| "FuelLabs".to_string());
let repo_name = env::var("GITHUB_REPOSITORY_NAME").unwrap_or_else(|_| "fuels-rs".to_string());
let github_adapter = OctocrabAdapter::new(&github_token);
let branches = {
let mut branches = vec!["master".to_string()];
let lts_branches = github_adapter
.search_branches(&repo_owner, &repo_name, "lts/")
.await?;
branches.extend(lts_branches);
branches
};
let branch_selection = FuzzySelect::new()
.with_prompt("Select the target branch (start typing to filter)")
.items(&branches)
.default(0)View on GitHub (pinned to d9a250a518)
Solutions
- Create a .env file in the directory you run the script from containing GITHUB_TOKEN=<token>
- Export GITHUB_TOKEN in the shell or add the secret to the CI job environment
- Use a fine-grained personal access token with read access to the repository
Example fix
# before $ cargo run -p scripts/change-log # panics: GITHUB_TOKEN is not set in the environment # after $ echo 'GITHUB_TOKEN=ghp_yourtoken' > .env cargo run -p scripts/change-log
Defensive patterns
Strategy: validation
Validate before calling
# (shell) check before running the script
[ -n "$GITHUB_TOKEN" ] || { echo 'GITHUB_TOKEN missing'; exit 1; }
# or persist it: echo 'GITHUB_TOKEN=ghp_xxx' >> .env Prevention
- Create a .env file in the script's working directory with GITHUB_TOKEN
- Expose GITHUB_TOKEN as a CI secret on jobs that generate the changelog
- Use a fine-grained PAT with minimal read scopes and rotate it
When it happens
Trigger: Running cargo run -p scripts/change-log (or the corresponding release workflow step) with GITHUB_TOKEN neither exported nor present in a .env file in the working directory.
Common situations: Fresh clone of the repo; CI job missing the secret; .env file never created or gitignored and lost.
Related errors
AI-assisted analysis of FuelLabs/fuels-rs@d9a250a518 (2026-08-16).
Data as JSON: /api/errors/639c95ac5735b976.
Report an issue: GitHub.