MahApps/MahApps.Metro · error · Exception
The GITHUB_TOKEN environment variable is not defined.
Error message
The GITHUB_TOKEN environment variable is not defined.
What it means
The Cake 'CreateRelease' task needs a GitHub access token to call GitReleaseManagerCreate and publish a release to the MahApps repo. It reads GITHUB_TOKEN from the environment and throws a plain Exception when the variable is empty or unset. The task is gated by !data.IsPullRequest, so it only runs on non-PR (push/release) builds.
Source
Thrown at build.cake:330
.Description("Ensures XAML Formatting is Clean")
.Does(() =>
{
Func<IFileSystemInfo, bool> exclude_Dir =
fileSystemInfo => !fileSystemInfo.Path.Segments.Contains("obj") && !fileSystemInfo.Path.ToString().Contains("Styles/Themes");
var files = GetFiles(srcDir + "/**/*.xaml", new GlobberSettings { Predicate = exclude_Dir });
Information("\nChecking " + files.Count() + " file(s) for XAML Structure");
ExecuteProcess(styler, "-f \"" + string.Join(",", files.Select(f => f.ToString())) + "\" -c \"" + stylerFile + "\"");
});
Task("CreateRelease")
.WithCriteria<BuildData>((context, data) => !data.IsPullRequest)
.Does<BuildData>(data =>
{
var token = EnvironmentVariable("GITHUB_TOKEN");
if (string.IsNullOrEmpty(token))
{
throw new Exception("The GITHUB_TOKEN environment variable is not defined.");
}
GitReleaseManagerCreate(token, "MahApps", repoName, new GitReleaseManagerCreateSettings {
Milestone = data.GitVersion.MajorMinorPatch,
Name = data.GitVersion.AssemblySemFileVer,
Prerelease = data.IsPrerelease,
TargetCommitish = data.GitVersion.BranchName,
WorkingDirectory = "."
});
});
///////////////////////////////////////////////////////////////////////////////
// HELPER
///////////////////////////////////////////////////////////////////////////////
void SignFiles(IEnumerable<FilePath> files, string description)
{
var vurl = EnvironmentVariable("azure-key-vault-url");View on GitHub (pinned to 72099e310b)
Solutions
- Set the GITHUB_TOKEN environment variable before invoking Cake: in PowerShell use $env:GITHUB_TOKEN = '<token>'; in GitHub Actions use the automatic GITHUB_TOKEN secret (secrets.GITHUB_TOKEN) passed via env:.
- Verify the CI job that runs CreateRelease actually has the secret in its environment (not just at workflow level).
- If you are testing locally and don't need a release, run a different target (e.g. Default) instead of CreateRelease.
- For GitHub Actions, map the built-in token explicitly: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}.
Example fix
# before (PowerShell, token missing)
./build.ps1 -Target CreateRelease
# after
$env:GITHUB_TOKEN = '<your PAT or CI token>'
./build.ps1 -Target CreateRelease
# GitHub Actions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} Defensive patterns
Strategy: validation
Validate before calling
// Before CreateRelease, validate the token and fail with a clear message
var token = EnvironmentVariable("GITHUB_TOKEN");
if (string.IsNullOrEmpty(token)) {
Warning("GITHUB_TOKEN not set — skipping CreateRelease.");
return; // or: throw with remediation hint
}
GitReleaseManagerCreate(token, "MahApps", repoName, new GitReleaseManagerCreateSettings { /* ... */ }); Prevention
- Configure GITHUB_TOKEN as a secret in the CI environment for the release job, not just the workflow.
- For GitHub Actions, map the built-in token: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}.
- Run CreateRelease only from release/push pipelines; skip it for local/feature builds.
- Document required environment variables (GITHUB_TOKEN, azure-key-vault-*) in the build README.
When it happens
Trigger: The 'CreateRelease' target executes (local or CI, not a PR build) and EnvironmentVariable("GITHUB_TOKEN") returns null or empty. GitReleaseManagerCreate is never reached because the guard throws first.
Common situations: CI secret not configured (e.g. GITHUB_TOKEN missing from GitHub Actions secrets or AppVeyor environment). Running build.ps1 -Target CreateRelease locally without setting GITHUB_TOKEN in the shell. Token secret renamed or scoped away from the build job.
Related errors
- {repoName} will only build on Windows because it's not possi
- File not found: {fileName}
- Errors occurred:{Environment.NewLine} {string.Join(Environme
- Exit code: {exitCode}
AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13).
Data as JSON: /api/errors/73c3e897c5c18299.
Report an issue: GitHub.