{"record":{"id":"1472f5250e5a8478","repo":"ElectronNET/Electron.NET","slug":"could-not-resolve-github-token","errorCode":null,"errorMessage":"Could not resolve GitHub token.","messagePattern":"Could not resolve GitHub token\\.","errorType":"exception","errorClass":"BuildAbortedException","httpStatus":null,"severity":"error","filePath":"nuke/Build.cs","lineNumber":185,"sourceCode":"\n    Target PublishPreRelease => _ => _\n        .DependsOn(PublishPackages)\n        .Executes(() =>\n        {\n            string gitHubToken;\n\n            if (GitHubActions != null)\n            {\n                gitHubToken = GitHubActions.Token;\n            }\n            else\n            {\n                gitHubToken = Environment.GetEnvironmentVariable(\"GITHUB_TOKEN\");\n            }\n\n            if (gitHubToken.IsNullOrEmpty())\n            {\n                throw new BuildAbortedException(\"Could not resolve GitHub token.\");\n            }\n\n            var credentials = new Credentials(gitHubToken);\n\n            GitHubTasks.GitHubClient = new GitHubClient(\n                new ProductHeaderValue(nameof(NukeBuild)),\n                new InMemoryCredentialStore(credentials));\n\n            GitHubTasks.GitHubClient.Repository.Release\n                .Create(\"ElectronNET\", \"Electron.NET\", new NewRelease(Version + VersionPostFix)\n                {\n                    Name = \"ElectronNET.Core \" + Version + VersionPostFix,\n                    Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes),\n                    Prerelease = true,\n                    TargetCommitish = \"develop\",\n                });\n        });\n","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/ElectronNET/Electron.NET/blob/87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2/nuke/Build.cs#L167-L203","documentation":"A GitHub target in the Nuke build (creating a release / uploading assets) needs a GitHub token to authenticate Octokit (new Credentials(gitHubToken) is constructed right after this check). It falls back to the GITHUB_TOKEN environment variable and throws BuildAbortedException if the token is null or empty, refusing to make unauthenticated GitHub API calls.","triggerScenarios":"Executing the GitHub release/publish target (Build.cs:185) when GITHUB_TOKEN is not set (or empty), including when the preceding code path that sets gitHubToken did not run or yielded nothing.","commonSituations":"GitHub Actions workflow does not pass the built-in GITHUB_TOKEN to the build step (missing `env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}`); running the release target locally without a personal access token; token secret renamed or scoped to the wrong repo; using a fork where secrets are not available.","solutions":["Export GITHUB_TOKEN with a valid personal access token (repo scope) before running the build, or","In the CI workflow, wire the automatic token: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} on the build step.","Check that any custom token source the target reads from (e.g. a parameter before the env fallback) actually provides a non-empty value.","Ensure the token has sufficient permissions (contents:write) if the error recurs after authentication."],"exampleFix":"// before (GitHub Actions step)\n- run: ./build.sh Release\n// after\n- run: ./build.sh Release\n  env:\n    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(\"GITHUB_TOKEN\")))\n    throw new InvalidOperationException(\"GITHUB_TOKEN must be set (CI: ${{ secrets.GITHUB_TOKEN }}).\");","typeGuard":null,"tryCatchPattern":"try\n{\n    // github release target\n}\ncatch (BuildAbortedException ex) when (ex.Message.Contains(\"GitHub token\"))\n{\n    Logger.Warn(\"No GITHUB_TOKEN available; skipping GitHub release step.\");\n}","preventionTips":["Wire ${{ secrets.GITHUB_TOKEN }} into the build step env in every workflow that publishes.","Use a PAT with contents:write only when the built-in token is insufficient.","Keep secret names stable; centralize them in reusable workflows.","Run a dry-run locally with a scoped token before CI releases."],"tags":["github","token","ci","environment-variable","build"],"backgroundTag":"missing-env-var","analyzedSha":"87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2","analyzedAt":"2026-09-14T03:09:47.608Z","contentChangedAt":"2026-09-14T03:09:47.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}