Skip to content

Commit

Permalink
new ci
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyNovikov89 committed Aug 13, 2024
1 parent fac81c5 commit 04df7dc
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 107 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
on:
push:
paths-ignore:
- "**/*.md"
- "**/*.yml"

jobs:
build_and_test:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup dotnet (5.0.x)
uses: actions/setup-dotnet@v4
with:
dotnet-version: 5.0.x

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2

- name: Run the build script
uses: cake-build/cake-action@v2
env:
diadoc_signing_secret: ${{ secrets.DIADOC_SIGNING_SECRET }}
github_ref_type: ${{ github.ref_type }}
with:
target: Default
arguments: |
configuration: Release
verbosity: Diagnostic
cake-version: 1.3.0

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: |
bin/Release/*.nupkg
bin/Release/*.zip
if-no-files-found: error

publish:
runs-on: ubuntu-20.04
needs: build_and_test
if: startsWith(github.event.ref, 'refs/tags/version')
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.x

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: packages

- name: Create github release
uses: softprops/action-gh-release@v1
with:
fail_on_unmatched_files: true
draft: false
prerelease: false
files: |
**/*.nupkg
**/*.zip
- name: Push NuGet package
run: |
dotnet nuget push "**/*.nupkg" --source ${{ secrets.NUGET_SOURCE }} --api-key ${{ secrets.NUGET_KEY }}
43 changes: 0 additions & 43 deletions appveyor.yml

This file was deleted.

80 changes: 16 additions & 64 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#tool "nuget:?package=ILMerge&version=2.12.803"
#addin "nuget:?package=Cake.Git&version=0.21.0"
#addin "nuget:?package=Cake.Git&version=1.0.0"
#tool "nuget:?package=ILRepack.MSBuild.Task&version=2.0.13"
#tool "nuget:?package=protobuf-net&version=1.0.0.280"
#tool "nuget:?package=secure-file&version=1.0.31"
#tool "nuget:?package=Brutal.Dev.StrongNameSigner&version=2.7.1"
#addin "nuget:?package=Cake.StrongNameSigner&version=0.1.0"
#addin "nuget:?package=Cake.StrongNameSigner&version=0.2.0"
using Cake.Common.Diagnostics;
using Cake.Git;
using System.Text.RegularExpressions;
Expand All @@ -21,7 +21,6 @@ var binariesNet45Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-net45-bina
var binariesNet461Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-net461-binaries.zip");
var binariesNetStandard2Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-netstandard2.0-binaries.zip");
var needSigning = false;

var packageVersion = "";

//////////////////////////////////////////////////////////////////////
Expand All @@ -30,7 +29,7 @@ var packageVersion = "";

Setup(context =>
{
if (BuildSystem.IsRunningOnAppVeyor && AppVeyor.Environment.PullRequest.IsPullRequest)
if (BuildSystem.IsRunningOnGitHubActions)
{
needSigning = false;
return;
Expand Down Expand Up @@ -72,7 +71,7 @@ Task("GenerateVersionInfo")
var tagVersion = GetVersionFromTag();
var clearVersion = ClearVersionTag(tagVersion) ?? "1.0.0";
var semanticVersionForNuget = GetSemanticVersionV1(clearVersion);
var semanticVersion = GetSemanticVersionV2(clearVersion) + dbgSuffix;
var semanticVersion = semanticVersionForNuget + dbgSuffix;

var versionParts = clearVersion.Split('.');
var majorVersion = 1;
Expand Down Expand Up @@ -271,21 +270,6 @@ Task("Nuget-Pack")
NuGetPack("./nuspec/DiadocApi.nuspec", nuGetPackSettings);
});

Task("PublishArtifactsToAppVeyor")
.IsDependentOn("Nuget-Pack")
.WithCriteria(x => BuildSystem.IsRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UploadArtifact(binariesNet35Zip);
AppVeyor.UploadArtifact(binariesNet45Zip);
AppVeyor.UploadArtifact(binariesNet461Zip);
AppVeyor.UploadArtifact(binariesNetStandard2Zip);
foreach (var upload in GetFiles(buildDir + "/*.nupkg"))
{
AppVeyor.UploadArtifact(upload);
}
});

Task("Test")
.IsDependentOn("Build")
.Does(() =>
Expand All @@ -301,9 +285,6 @@ Task("Test")
// TASK TARGETS
//////////////////////////////////////////////////////////////////////

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

Task("FullBuild")
.IsDependentOn("GenerateVersionInfo")
.IsDependentOn("Build");
Expand All @@ -313,13 +294,12 @@ Task("Rebuild")
.IsDependentOn("GenerateVersionInfo")
.IsDependentOn("Build");

Task("Appveyor")
Task("Default")
.IsDependentOn("PrepareBinaries")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Repack")
.IsDependentOn("Nuget-Pack")
.IsDependentOn("PublishArtifactsToAppVeyor");
.IsDependentOn("Nuget-Pack");

//////////////////////////////////////////////////////////////////////
// EXECUTION
Expand All @@ -335,12 +315,12 @@ public string GetVersionFromTag()
{
var lastestTag = "";

if (BuildSystem.IsRunningOnAppVeyor)
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
{
var tag = BuildSystem.AppVeyor.Environment.Repository.Tag;
if (tag.IsTag)
var workflow = BuildSystem.GitHubActions.Environment.Workflow;
if(EnvironmentVariable("github_ref_type") == "tag")
{
return tag.Name;
return workflow.Ref.Replace("refs/tags/", "");
}
}

Expand All @@ -361,49 +341,21 @@ public string GetVersionFromTag()

public string GetSemanticVersionV1(string clearVersion)
{
if (BuildSystem.IsRunningOnAppVeyor)
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
{
var tag = BuildSystem.AppVeyor.Environment.Repository.Tag;
if (tag.IsTag)
var workflow = BuildSystem.GitHubActions.Environment.Workflow;
if(EnvironmentVariable("github_ref_type") == "tag")
{
return clearVersion;
}

var buildNumber = BuildSystem.AppVeyor.Environment.Build.Number;
var buildNumber = workflow.RunNumber;
return $"{clearVersion}-CI{buildNumber}";
}

return $"{clearVersion}-dev";
}

public string GetSemanticVersionV2(string clearVersion)
{
if (BuildSystem.IsRunningOnAppVeyor)
{
var tag = BuildSystem.AppVeyor.Environment.Repository.Tag;
if (tag.IsTag)
{
return clearVersion;
}

return GetAppVeyorBuildVersion(clearVersion);
}
return $"{clearVersion}-dev";
}

public string GetAppVeyorBuildVersion(string clearVersion)
{
if (BuildSystem.IsRunningOnAppVeyor)
{
var buildNumber = BuildSystem.AppVeyor.Environment.Build.Number;
clearVersion += $"-CI.{buildNumber}";
return (AppVeyor.Environment.PullRequest.IsPullRequest
? clearVersion += $"-PR.{AppVeyor.Environment.PullRequest.Number}"
: clearVersion += "-" + AppVeyor.Environment.Repository.Branch);
}
return clearVersion;
}

public static string ClearVersionTag(string lastestTag)
{
if (string.IsNullOrEmpty(lastestTag))
Expand All @@ -418,4 +370,4 @@ public static string ClearVersionTag(string lastestTag)
return match.Success
? match.Value
: lastestTag;
}
}

0 comments on commit 04df7dc

Please sign in to comment.