Skip to content

Commit

Permalink
Add target to publish packages to Azure and GitHub.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldvanmanen committed Jun 4, 2024
1 parent a05bbca commit d749875
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 79 deletions.
66 changes: 14 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ jobs:
- { os: ubuntu, architecture: x64, configuration: debug, build-script: ./build.sh }
- { os: ubuntu, architecture: x64, configuration: release, build-script: ./build.sh }
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
source-url: https://pkgs.dev.azure.com/ronaldvanmanen/_packaging/ronaldvanmanen/nuget/v3/index.json
- run: ${{ matrix.platform.build-script }} test --configuration ${{ matrix.platform.configuration }} --architecture ${{ matrix.platform.architecture }}
env:
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }}
- run: ${{ matrix.platform.build-script }} -configuration ${{ matrix.platform.configuration }} -architecture ${{ matrix.platform.architecture }}
- uses: actions/upload-artifact@v3
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.os }}_${{ matrix.platform.configuration }}_${{ matrix.platform.architecture }}
path: |
Expand All @@ -45,59 +42,24 @@ jobs:
./artifacts/pkg/**/*
./artifacts/tst/**/*
if-no-files-found: error
build:
name: build (Any CPU)
publish:
name: publish
needs: [ test ]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
source-url: https://pkgs.dev.azure.com/ronaldvanmanen/_packaging/ronaldvanmanen/nuget/v3/index.json
- run: .\build.cmd publish --configuration release
env:
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }}
- run: .\build.cmd -configuration release -architecture x64
shell: cmd
- uses: actions/upload-artifact@v3
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
- uses: actions/upload-artifact@v4
with:
name: nuget
name: publish
path: |
./artifacts/bin/**/*
./artifacts/log/**/*
./artifacts/pkg/**/*
./artifacts/tst/**/*
if-no-files-found: error
publish-on-azure:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
needs: [ test, build ]
steps:
- uses: actions/download-artifact@v3
with:
name: nuget
path: ./artifacts
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
source-url: https://pkgs.dev.azure.com/ronaldvanmanen/_packaging/ronaldvanmanen/nuget/v3/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }}
- run: dotnet nuget push "./artifacts/pkg/Release/*.nupkg" --api-key AzureDevOps
publish-on-github:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
needs: [ test, build ]
steps:
- uses: actions/download-artifact@v3
with:
name: nuget
path: ./artifacts
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
source-url: https://nuget.pkg.github.com/ronaldvanmanen/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: dotnet nuget push "./artifacts/pkg/Release/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"Compile",
"Generate",
"Pack",
"Publish",
"Restore",
"Setup",
"Test"
Expand All @@ -100,6 +101,7 @@
"Compile",
"Generate",
"Pack",
"Publish",
"Restore",
"Setup",
"Test"
Expand Down
11 changes: 11 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
<packageSources>
<clear/>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github" value="https://nuget.pkg.github.com/ronaldvanmanen/index.json" />
<add key="azure" value="https://pkgs.dev.azure.com/ronaldvanmanen/_packaging/ronaldvanmanen/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<nuget>
<add key="Username" value="ronaldvanmanen" />
<add key="ClearTextPassword" value="%GITHUB_TOKEN%" />
</nuget>
<azure>
<add key="Username" value="ronaldvanmanen" />
<add key="ClearTextPassword" value="%AZURE_DEVOPS_PAT%" />
</azure>
</packageSourceCredentials>
</configuration>
2 changes: 1 addition & 1 deletion sources/Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

using Nuke.Common;

partial class Build : NukeBuild, IClean, ISetup, IRestore, IGenerate, ICompile, ITest, IPack
partial class Build : NukeBuild, IClean, ISetup, IRestore, IGenerate, ICompile, ITest, IPack, IPublish
{
public static int Main() => Execute<Build>(target => ((IPack)target).Pack);
}
3 changes: 1 addition & 2 deletions sources/Build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

<ItemGroup>
<PackageDownload Include="ClangSharpPInvokeGenerator" Version="[18.1.0]" />
<PackageDownload Include="libclang.runtime.linux-x64" Version="[18.1.3.2]" />
<PackageDownload Include="libClangSharp.runtime.linux-x64" Version="[18.1.3.1]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.12.0]" />
<PackageDownload Include="NuGet.CommandLine" Version="[6.10.0]" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions sources/Build/IBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Nuke.Common.Tools.GitVersion;
using static System.Runtime.InteropServices.RuntimeInformation;
using static System.Runtime.InteropServices.Architecture;
using Nuke.Common.CI.GitHubActions;

interface IBuild : INukeBuild
{
Expand Down Expand Up @@ -75,4 +76,5 @@ public string RuntimeIdentifier

public AbsolutePath GlobalPackagesFolder => AbsolutePath.Create(SettingsUtility.GetGlobalPackagesFolder(Settings.LoadDefaultSettings(null)));

public GitHubActions GitHubActions => GitHubActions.Instance;
}
63 changes: 63 additions & 0 deletions sources/Build/IPublish.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SDL2Sharp
//
// Copyright (C) 2021 Ronald van Manen <rvanmanen@gmail.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.

using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.NuGet;
using static Nuke.Common.Tools.NuGet.NuGetTasks;

interface IPublish : IBuild
{
public Target Publish => _ => _
.DependsOn<IPack>(target => target.Pack)
.Executes(() =>
{
var packagesDirectory = ArtifactsDirectory / "pkg" / "Release";
var packages = packagesDirectory.GlobFiles("*.nupkg");
foreach (var package in packages)
{
PublishOnAzure(package);
PublishOnGitHub(package);
}
});

void PublishOnAzure(AbsolutePath packagePath)
{
NuGetPush(settings => settings
.SetTargetPath(packagePath)
.SetSource("https://pkgs.dev.azure.com/ronaldvanmanen/_packaging/ronaldvanmanen/nuget/v3/index.json")
.SetApiKey("AzureDevOps")
.SetNonInteractive(IsServerBuild)
.SetProcessArgumentConfigurator(arguments => arguments.Add("-SkipDuplicate"))
);
}

void PublishOnGitHub(AbsolutePath packagePath)
{
NuGetPush(settings => settings
.SetTargetPath(packagePath)
.SetSource("https://nuget.pkg.github.com/ronaldvanmanen/index.json")
.SetApiKey(GitHubActions.Token)
.SetNonInteractive(IsServerBuild)
.SetProcessArgumentConfigurator(arguments => arguments.Add("-SkipDuplicate"))
);
}
}
15 changes: 5 additions & 10 deletions sources/Build/IRestore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,16 @@
interface IRestore : IBuild
{
public Target Restore => _ => _
.After<ISetup>(target => target.Setup)
.DependsOn<ISetup>(target => target.Setup)
.Executes(() =>
{
DotNetRestore(settings => settings
.SetProjectFile(Solution)
.SetProperty("NuGetInteractive", IsLocalBuild ? "true" : "false")
.SetProcessArgumentConfigurator(arguments =>
{
if (IsLocalBuild)
{
arguments.Add("--interactive");
}
return arguments;
})
.SetVerbosity(Verbosity.ToDotNetVerbosity())
.SetProcessArgumentConfigurator(arguments => arguments
.Add("--interactive", IsLocalBuild)
.Add("/property:NuGetInteractive=false", IsLocalBuild)
)
);
});
}
35 changes: 21 additions & 14 deletions sources/Build/ISetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ partial interface ISetup : IBuild

private Tool Bash => ToolResolver.GetPathTool("bash");

private Tool Sudo => ToolResolver.GetPathTool("sudo");

private Tool Echo => ToolResolver.GetPathTool("echo");

public Target Setup => _ => _
.After<IClean>(target => target.Clean)
.Executes(() =>
Expand Down Expand Up @@ -119,10 +123,13 @@ private void InstallDotNet(Version version)

private void InstallDotNetFrameworks()
{
var versions = GetTargetFrameworkVersions();
foreach (var version in versions.Where(version => version.Major < 5))
if (IsOSPlatform(OSPlatform.Windows))
{
InstallDotNetFramework(version);
var versions = GetTargetFrameworkVersions();
foreach (var version in versions.Where(version => version.Major < 5))
{
InstallDotNetFramework(version);
}
}
}

Expand Down Expand Up @@ -183,26 +190,26 @@ private void InstallMono()
{
if (Linux.IsUbuntu2004)
{
Bash("sudo apt install ca-certificates gnupg");
Bash("sudo gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF");
Bash("echo 'deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list");
Sudo("apt-get install ca-certificates gnupg");
Sudo("gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF");
Echo("'deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list");
}
else if (Linux.IsUbuntu1804)
{
Bash("sudo apt install ca-certificates gnupg");
Bash("sudo gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF");
Bash("echo 'deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-bionic main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list");
Sudo("apt-get install ca-certificates gnupg");
Sudo("gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF");
Echo("'deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-bionic main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list");
}
else if (Linux.IsUbuntu1604)
{
Bash("sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF");
Bash("sudo apt install apt-transport-https ca-certificates");
Bash("echo 'deb https://download.mono-project.com/repo/ubuntu stable-xenial main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list");
Sudo("apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF");
Sudo("apt-get install apt-transport-https ca-certificates");
Echo("'deb https://download.mono-project.com/repo/ubuntu stable-xenial main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list");
}

Bash("sudo apt update");
Sudo("apt-get update");

Bash("sudo apt install mono-devel");
Sudo("apt-get install mono-devel");
}
}

Expand Down

0 comments on commit d749875

Please sign in to comment.