Skip to content

Commit

Permalink
ci: Use the same scripts and workflows in public and private projects.
Browse files Browse the repository at this point in the history
Just remove CodeQL workflow in private projects if not on GH Enterprise.

Signed-off-by: Riccardo De Agostini <[email protected]>
  • Loading branch information
rdeago committed Mar 5, 2023
1 parent 59f1368 commit ec1b8ca
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-test-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
19 changes: 12 additions & 7 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -181,24 +181,29 @@ 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.");
}
else if (data.Branch != "main")
{
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");
Expand Down
9 changes: 5 additions & 4 deletions build/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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())
Expand All @@ -125,8 +125,9 @@ static void NuGetPushAll(this ICakeContext context, BuildData data)
return;
}

var nugetSource = context.GetOptionOrFail<string>(data.IsPrerelease ? "prereleaseNugetSource" : "releaseNugetSource");
var nugetApiKey = context.GetOptionOrFail<string>(data.IsPrerelease ? "prereleaseNugetKey" : "releaseNugetKey");
var isPrivate = await context.IsPrivateRepositoryAsync(data);
var nugetSource = context.GetOptionOrFail<string>(isPrivate ? "privateNugetSource" : data.IsPrerelease ? "prereleaseNugetSource" : "releaseNugetSource");
var nugetApiKey = context.GetOptionOrFail<string>(isPrivate ? "privateNugetKey" : data.IsPrerelease ? "prereleaseNugetKey" : "releaseNugetKey");
var nugetPushSettings = new DotNetNuGetPushSettings {
ForceEnglishOutput = true,
Source = nugetSource,
Expand Down
16 changes: 15 additions & 1 deletion build/github.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<bool> 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.
Expand Down

0 comments on commit ec1b8ca

Please sign in to comment.