From ec1b8cae6623c42fdaeb23070571fd62d7169702 Mon Sep 17 00:00:00 2001 From: Riccardo De Agostini Date: Sun, 5 Mar 2023 11:07:58 +0100 Subject: [PATCH] ci: Use the same scripts and workflows in public and private projects. Just remove CodeQL workflow in private projects if not on GH Enterprise. Signed-off-by: Riccardo De Agostini --- .github/workflows/build-test-pack.yml | 1 + .github/workflows/deploy-pages.yml | 1 + .github/workflows/release.yml | 12 ++++++++++-- build.cake | 19 ++++++++++++------- build/dotnet.cake | 9 +++++---- build/github.cake | 16 +++++++++++++++- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-test-pack.yml b/.github/workflows/build-test-pack.yml index 4925452..fce1ea0 100644 --- a/.github/workflows/build-test-pack.yml +++ b/.github/workflows/build-test-pack.yml @@ -14,6 +14,7 @@ jobs: DOTNET_CLI_TELEMETRY_OPTOUT: 'true' DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 'true' DOTNET_CLI_UI_LANGUAGE: 'en-US' + MYGET_PRIVATE_FEED_PASSWORD: ${{ secrets.MYGET_PRIVATE_FEED_PASSWORD }} steps: - name: Checkout repository with full history uses: actions/checkout@v3 diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 9799d2a..3801c27 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -33,6 +33,7 @@ jobs: DOTNET_CLI_TELEMETRY_OPTOUT: 'true' DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 'true' DOTNET_CLI_UI_LANGUAGE: 'en-US' + MYGET_PRIVATE_FEED_PASSWORD: ${{ secrets.MYGET_PRIVATE_FEED_PASSWORD }} CAKE_VERBOSITY: ${{ inputs.cakeVerbosity }} steps: - name: Checkout repository with full history diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f48ae1e..604fd77 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -51,10 +51,18 @@ jobs: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 'true' DOTNET_CLI_UI_LANGUAGE: 'en-US' GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} - PRERELEASE_NUGET_SOURCE: 'https://www.myget.org/F/tenacom-preview/api/v3/index.json' - PRERELEASE_NUGET_KEY: ${{ secrets.MYGET_DEPLOYMENT_KEY }} + + # Deploy non-prerelease public packages on NuGet RELEASE_NUGET_SOURCE: 'https://api.nuget.org/v3/index.json' RELEASE_NUGET_KEY: ${{ secrets.NUGET_DEPLOYMENT_KEY }} + # Deploy prerelease public packages on a public MyGet feed + PRERELEASE_NUGET_SOURCE: 'https://www.myget.org/F/tenacom-preview/api/v3/index.json' + PRERELEASE_NUGET_KEY: ${{ secrets.MYGET_DEPLOYMENT_KEY }} + # Deploy all private packages on a private MyGet feed + MYGET_PRIVATE_FEED_PASSWORD: ${{ secrets.MYGET_PRIVATE_FEED_PASSWORD }} + PRIVATE_NUGET_SOURCE: 'https://www.myget.org/F/tenacom/api/v3/index.json' + PRIVATE_NUGET_KEY: ${{ secrets.MYGET_PRIVATE_FEED_KEY }} + VERSION_SPEC_CHANGE: ${{ inputs.versionSpecChange }} CHECK_PUBLIC_API: ${{ inputs.checkPublicApi }} FORCE_UPDATE_CHANGELOG: ${{ inputs.forceUpdateChangelog }} diff --git a/build.cake b/build.cake index 7306b3f..e0fed66 100644 --- a/build.cake +++ b/build.cake @@ -181,17 +181,14 @@ Task("Release") } // Publish NuGet packages - context.NuGetPushAll(data); + await context.NuGetPushAllAsync(data); // If this is not a prerelease and we are releasing from the main branch, // dispatch a separate workflow to publish documentation. - // Unless, of course, there is no documentation workflow. + // Unless, of course, there is no documentation to publish, or no workflow to do it. + FilePath docFxJsonPath = "docs/docfx.json"; FilePath pagesDeploymentWorkflow = ".github/workflows/deploy-pages.yml"; - if (!SysFile.Exists(pagesDeploymentWorkflow.FullPath)) - { - context.Information($"Documentation update skipped: there is no documentation workflow."); - } - else if (data.IsPrerelease) + if (data.IsPrerelease) { context.Information("Documentation update skipped: not needed on prerelease."); } @@ -199,6 +196,14 @@ Task("Release") { context.Information($"Documentation update skipped: releasing from '{data.Branch}', not 'main'."); } + else if (!SysFile.Exists(pagesDeploymentWorkflow.FullPath)) + { + context.Information($"Documentation update skipped: {docFxJsonPath} not present."); + } + else if (!SysFile.Exists(pagesDeploymentWorkflow.FullPath)) + { + context.Warning($"Documentation update skipped: there is no documentation workflow."); + } else { await context.DispatchWorkflow(data, SysPath.GetFileName(pagesDeploymentWorkflow.FullPath), "main"); diff --git a/build/dotnet.cake b/build/dotnet.cake index f6824c2..67d4df0 100644 --- a/build/dotnet.cake +++ b/build/dotnet.cake @@ -106,7 +106,7 @@ static void PackSolution(this ICakeContext context, BuildData data, bool restore } /* - * Summary : Push all produced NuGet packages to the appropriate NuGet server. + * Summary : Asynchronously pushes all produced NuGet packages to the appropriate NuGet server. * Params : context - The Cake context. * data - Build configuration data. * Remarks : - This method uses the following environment variables: @@ -116,7 +116,7 @@ static void PackSolution(this ICakeContext context, BuildData data, bool restore * * RELEASE_NUGET_KEY - API key for RELEASE_NUGET_SOURCE * - If there are no .nupkg files in the designated artifacts directory, this method does nothing. */ -static void NuGetPushAll(this ICakeContext context, BuildData data) +static async Task NuGetPushAllAsync(this ICakeContext context, BuildData data) { const string nupkgMask = "*.nupkg"; if (!SysDirectory.EnumerateFiles(data.ArtifactsPath.FullPath, nupkgMask).Any()) @@ -125,8 +125,9 @@ static void NuGetPushAll(this ICakeContext context, BuildData data) return; } - var nugetSource = context.GetOptionOrFail(data.IsPrerelease ? "prereleaseNugetSource" : "releaseNugetSource"); - var nugetApiKey = context.GetOptionOrFail(data.IsPrerelease ? "prereleaseNugetKey" : "releaseNugetKey"); + var isPrivate = await context.IsPrivateRepositoryAsync(data); + var nugetSource = context.GetOptionOrFail(isPrivate ? "privateNugetSource" : data.IsPrerelease ? "prereleaseNugetSource" : "releaseNugetSource"); + var nugetApiKey = context.GetOptionOrFail(isPrivate ? "privateNugetKey" : data.IsPrerelease ? "prereleaseNugetKey" : "releaseNugetKey"); var nugetPushSettings = new DotNetNuGetPushSettings { ForceEnglishOutput = true, Source = nugetSource, diff --git a/build/github.cake b/build/github.cake index 020737e..3ca8f18 100644 --- a/build/github.cake +++ b/build/github.cake @@ -2,7 +2,7 @@ // See LICENSE file in the project root for full license information. #addin nuget:?package=Cake.Http&version=2.0.0 -#addin nuget:?package=Octokit&version=3.0.1 +#addin nuget:?package=Octokit&version=5.0.0 #nullable enable @@ -15,6 +15,20 @@ using Octokit; using SysFile = System.IO.File; +/* + * Summary : Asynchronously gets the visibility of the current repository. + * Params : context - The Cake context. + * data - Build configuration data. + * Returns : A Task that represents the ongoing operation. + */ +static async Task IsPrivateRepositoryAsync(this ICakeContext context, BuildData data) +{ + context.Information("Fetching repository information..."); + var client = context.CreateGitHubClient(); + var repository = await client.Repository.Get(data.RepositoryOwner, data.RepositoryName).ConfigureAwait(false); + return repository.Private; +} + /* * Summary : Asynchronously creates a new draft release on the GitHub repository. * Params : context - The Cake context.