From a0f83593ae093d9a09935284d877de1330c99b75 Mon Sep 17 00:00:00 2001 From: Antoine Aubry Date: Fri, 2 Dec 2022 20:30:24 +0000 Subject: [PATCH] Fix release permission issues --- .github/workflows/create-release.yml | 3 ++- tools/build/BuildDefinition.cs | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 0bd58bec..ee786f61 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -40,5 +40,6 @@ jobs: - name: Create draft release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_TOKEN }} + GITHUB_REPOSITORY: "aaubry/YamlDotNet" run: ./build.sh CreateGithubRelease diff --git a/tools/build/BuildDefinition.cs b/tools/build/BuildDefinition.cs index 8ca418ce..c1336e35 100644 --- a/tools/build/BuildDefinition.cs +++ b/tools/build/BuildDefinition.cs @@ -444,13 +444,23 @@ public static void Document(Options options) "); } - private static string GitHubRepository => - Program.Host switch + private static string GitHubRepository + { + get { - Host.AppVeyor => Environment.GetEnvironmentVariable("APPVEYOR_REPO_NAME"), - _ => Environment.GetEnvironmentVariable("GITHUB_REPOSITORY") + var repository = Program.Host switch + { + Host.AppVeyor => Environment.GetEnvironmentVariable("APPVEYOR_REPO_NAME"), + _ => Environment.GetEnvironmentVariable("GITHUB_REPOSITORY") + }; + if (repository == null) + { + WriteWarning("Could not determine the current repository. Falling-back to sandbox!"); + repository = "aaubry/YamlDotNet.Sandbox"; + } + return repository; } - ?? "aaubry/YamlDotNet.Sandbox"; + } private static readonly Lazy GitHubClient = new Lazy(() => { @@ -463,7 +473,7 @@ public static void Document(Options options) gitHubClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json")); gitHubClient.DefaultRequestHeaders.Add("User-Agent", GitHubRepository.Split('/')[0]); - gitHubClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", token); + gitHubClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); return gitHubClient; });