Skip to content

Commit

Permalink
Merge pull request #129 from devlead/feature/githubactions
Browse files Browse the repository at this point in the history
Add GitHub Actions, Update Cake & .NET
  • Loading branch information
devlead authored Mar 27, 2022
2 parents a161b2b + c87151a commit b7d6dee
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: devlead
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build
on:
pull_request:
push:
branches:
- main
- develop
- hotfix/*

jobs:
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- name: Get the sources
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install .NET Core SDK
uses: actions/setup-dotnet@v1

- name: Run Cake script
uses: cake-build/cake-action@v1
env:
GH_PACKAGES_NUGET_SOURCE: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
GH_PACKAGES_NUGET_APIKEY: ${{ secrets.GITHUB_TOKEN }}
NUGET_SOURCE: ${{ secrets.NUGET_API_URL }}
NUGET_APIKEY: ${{ secrets.NUGET_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
cake-version: tool-manifest
target: GitHub-Actions
7 changes: 1 addition & 6 deletions azure-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
strategy:
matrix:
linux:
imageName: 'ubuntu-16.04'
imageName: 'ubuntu-20.04'
mac:
imageName: 'macos-10.15'
windows:
Expand All @@ -11,11 +11,6 @@ pool:
vmImage: $(imageName)

steps:
- task: UseDotNet@2
displayName: 'Use .NET Core sdk 2.1.202'
inputs:
version: 2.1.202

- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
inputs:
Expand Down
78 changes: 54 additions & 24 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Install modules
#module nuget:?package=Cake.DotNetTool.Module&version=0.3.0

// Install tools
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0

// Install .NET Core Global tools.
#tool "dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=5.0.1"
#tool "dotnet:?package=GitVersion.Tool&version=5.9.0"

///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
Expand All @@ -18,7 +15,7 @@ var configuration = Argument("configuration", "Release");
// PARAMETERS
//////////////////////////////////////////////////////////////////////

DotNetCoreMSBuildSettings msBuildSettings = null;
DotNetMSBuildSettings msBuildSettings = null;
string version = null,
semVersion = null,
milestone = null;
Expand Down Expand Up @@ -54,10 +51,12 @@ Setup(ctx =>
Information("Calculated Semantic Version: {0}", semVersion);
msBuildSettings = new DotNetCoreMSBuildSettings()
msBuildSettings = new DotNetMSBuildSettings()
.WithProperty("Version", semVersion)
.WithProperty("AssemblyVersion", version)
.WithProperty("FileVersion", version);
.WithProperty("FileVersion", version)
.WithProperty("ContinuousIntegrationBuild", BuildSystem.IsLocalBuild ? bool.FalseString : bool.TrueString);
if(!IsRunningOnWindows())
{
Expand Down Expand Up @@ -107,16 +106,16 @@ Task("Clean")
Task("Restore")
.IsDependentOn("Clean")
.Does(() => {
DotNetCoreRestore("./LitJSON.sln",
new DotNetCoreRestoreSettings { MSBuildSettings = msBuildSettings }
DotNetRestore("./LitJSON.sln",
new DotNetRestoreSettings { MSBuildSettings = msBuildSettings }
);
});

Task("Build")
.IsDependentOn("Restore")
.Does(() => {
DotNetCoreBuild("./LitJSON.sln",
new DotNetCoreBuildSettings {
DotNetBuild("./LitJSON.sln",
new DotNetBuildSettings {
Configuration = configuration,
MSBuildSettings = msBuildSettings,
ArgumentCustomization = args => args.Append("--no-restore")
Expand All @@ -127,10 +126,10 @@ Task("Build")
Task("Test")
.IsDependentOn("Build")
.Does(() => {
DotNetCoreTest("./test/LitJSON.Tests.csproj",
new DotNetCoreTestSettings {
DotNetTest("./test/LitJSON.Tests.csproj",
new DotNetTestSettings {
Configuration = configuration,
Framework = "netcoreapp2.0",
Framework = "net6.0",
NoBuild = true,
ArgumentCustomization = args => args.Append("--no-restore")
}
Expand All @@ -143,20 +142,20 @@ Task("Test")

Task("Test-SourceLink")
.IsDependentOn("Build")
.WithCriteria(IsRunningOnWindows())
.WithCriteria(IsRunningOnWindows() && AppVeyor.IsRunningOnAppVeyor)
.Does(() => {
foreach(var asssembly in GetFiles("./src/LitJson/bin/" + configuration + "/**/*.dll"))
{
DotNetCoreTool(litjsonProjectPath.FullPath, "sourcelink", $"test {asssembly}");
DotNetTool(litjsonProjectPath.FullPath, "sourcelink", $"test {asssembly}");
}
});

Task("Package")
.IsDependentOn("Test")
.IsDependentOn("Test-SourceLink")
.Does(() => {
DotNetCorePack(litjsonProjectPath.FullPath,
new DotNetCorePackSettings {
DotNetPack(litjsonProjectPath.FullPath,
new DotNetPackSettings {
Configuration = configuration,
NoBuild = true,
IncludeSymbols = true,
Expand Down Expand Up @@ -197,8 +196,8 @@ Task("Publish-MyGet")
foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg")))
{
DotNetCoreNuGetPush(package.FullPath,
new DotNetCoreNuGetPushSettings {
DotNetNuGetPush(package.FullPath,
new DotNetNuGetPushSettings {
ApiKey = apiKey,
Source = apiUrl
}
Expand All @@ -215,19 +214,47 @@ Task("Publish-NuGet")
// Resolve the API key.
var apiKey = EnvironmentVariable("NUGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
throw new InvalidOperationException("Could not resolve NuGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("NUGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve MyGet API url.");
throw new InvalidOperationException("Could not resolve NuGet API url.");
}
foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg")))
{
DotNetNuGetPush(package.FullPath,
new DotNetNuGetPushSettings {
ApiKey = apiKey,
Source = apiUrl
}
);
}
});

Task("Push-GitHub-Packages")
.IsDependentOn("Package")
.WithCriteria(GitHubActions.IsRunningOnGitHubActions && !GitHubActions.Environment.PullRequest.IsPullRequest)
.Does(() => {
// Resolve the API key.
var apiKey = EnvironmentVariable("GH_PACKAGES_NUGET_APIKEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve GitHub API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve GitHub API url.");
}
foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg")))
{
DotNetCoreNuGetPush(package.FullPath,
new DotNetCoreNuGetPushSettings {
DotNetNuGetPush(package.FullPath,
new DotNetNuGetPushSettings {
ApiKey = apiKey,
Source = apiUrl
}
Expand All @@ -240,6 +267,9 @@ Task("AppVeyor")
.IsDependentOn("Publish-MyGet")
.IsDependentOn("Publish-NuGet");

Task("GitHub-Actions")
.IsDependentOn("Push-GitHub-Packages");

Task("Default")
.IsDependentOn("Package");

Expand Down
4 changes: 2 additions & 2 deletions build.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
CAKE_VERSION=0.36.0
DOTNET_VERSION=3.0.101
CAKE_VERSION=2.1.0
DOTNET_VERSION=6.0.201
4 changes: 3 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"src"
],
"sdk": {
"version": "3.0.101"
"version": "6.0.201",
"allowPrerelease": false,
"rollForward": "feature"
}
}
6 changes: 4 additions & 2 deletions src/LitJson/LitJSON.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45;netstandard1.5;net40;net35;net20</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net45;netstandard1.5;net40;net35;net20;net6.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DebugType>embedded</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SourceLinkCreate Condition="'$(OS)' == 'Windows_NT'">true</SourceLinkCreate>
</PropertyGroup>

<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.3" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.3" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/LitJSON.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net45</TargetFrameworks>
<TargetFrameworks>net6.0;net45</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down

0 comments on commit b7d6dee

Please sign in to comment.