Skip to content

Commit

Permalink
Enable SkipForked
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Dec 18, 2024
1 parent a395540 commit 8c36f4c
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 48 deletions.
3 changes: 3 additions & 0 deletions Build/.nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
"allOf": [
{
"properties": {
"EnableForkedRepository": {
"type": "boolean"
},
"Folder": {
"type": "string"
},
Expand Down
21 changes: 20 additions & 1 deletion Build/IShowGitVersion.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Nuke.Common;
using Nuke.Common.Git;
using ricaun.Nuke.Components;
using ricaun.Nuke.Extensions;

public interface IShowGitVersion : IHazGitVersion, IHazChangelog, IClean, ICompile
public interface IShowGitVersion : IHazGitVersion, IHazGitRepository, IHazChangelog, IClean, ICompile
{
Target ShowGitVersion => _ => _
.TriggeredBy(Clean)
Expand All @@ -23,5 +24,23 @@ public interface IShowGitVersion : IHazGitVersion, IHazChangelog, IClean, ICompi
System.IO.Path.Combine(BuildAssemblyDirectory, $"latest.json"));
}
catch { }


Serilog.Log.Information("Commit = {Value}", GitRepository.Commit);
Serilog.Log.Information("Branch = {Value}", GitRepository.Branch);
Serilog.Log.Information("Tags = {Value}", GitRepository.Tags);
Serilog.Log.Information("Head = {Value}", GitRepository.Head);
Serilog.Log.Information("Identifier = {Value}", GitRepository.Identifier);

Serilog.Log.Information("IsForked = {Value}", GitRepository.IsForked());

Serilog.Log.Information("main branch = {Value}", GitRepository.IsOnMainBranch());
Serilog.Log.Information("main/master branch = {Value}", GitRepository.IsOnMainOrMasterBranch());
Serilog.Log.Information("release/* branch = {Value}", GitRepository.IsOnReleaseBranch());
Serilog.Log.Information("hotfix/* branch = {Value}", GitRepository.IsOnHotfixBranch());

Serilog.Log.Information("Https URL = {Value}", GitRepository.HttpsUrl);
Serilog.Log.Information("SSH URL = {Value}", GitRepository.SshUrl);

});
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Features
- Enable sign files using `Azure Key Vault`.
- Enable `IAssetRelease` to release assets before `GitRelease` and `GitPreRelease`.
- Enable `SkipForked` to skip release if forked repository.
### Build
- Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed.
- Add `ILocalAssetRelease` to test `AssetRelease` assets before release.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.9.0-beta.9</Version>
<Version>1.9.0-rc</Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion ricaun.Nuke.Example.Tests/ricaun.Nuke.Example.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions ricaun.Nuke/Components/IGitPreRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public bool HasPreReleaseFilter(string version)
.OnlyWhenStatic(() => GitHubToken.SkipEmpty())
.OnlyWhenStatic(() => IsServerBuild)
.OnlyWhenDynamic(() => GitRepository.IsOnDevelopBranch())
.OnlyWhenDynamic(() => SkipForked())
.Executes(() =>
{
var project = MainProject;
Expand Down
1 change: 1 addition & 0 deletions ricaun.Nuke/Components/IGitRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHaz
.OnlyWhenStatic(() => GitHubToken.SkipEmpty())
.OnlyWhenStatic(() => IsServerBuild)
.OnlyWhenDynamic(() => GitRepository.IsOnMainOrMasterBranch())
.OnlyWhenDynamic(() => SkipForked())
.Executes(() =>
{
var project = MainProject;
Expand Down
117 changes: 72 additions & 45 deletions ricaun.Nuke/Components/IHazGitRepository.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,72 @@
using Nuke.Common;
using Nuke.Common.Git;

namespace ricaun.Nuke.Components
{
/// <summary>
/// IHazGitRepository
/// </summary>
public interface IHazGitRepository : INukeBuild
{
/// <summary>
/// GitHubToken
/// </summary>
[Secret][Parameter] public string GitHubToken => TryGetValue(() => GitHubToken);

/// <summary>
/// GitRepository
/// </summary>
[GitRepository] GitRepository GitRepository => TryGetValue(() => GitRepository);

/// <summary>
/// GetGitRepositoryPackageUrl (default: https://nuget.pkg.github.com/repository_owner/index.json)
/// </summary>
/// <returns></returns>
public string GetGitRepositoryPackageUrl()
{
if (GitRepository == null)
{
Serilog.Log.Warning($"GitRepository not found.");
return "";
}
return $@"https://nuget.pkg.github.com/{GetGitRepositoryOwner()}/index.json";
}

/// <summary>
/// GetGitRepositoryOwner based on the GitRepository.Identifier
/// </summary>
/// <returns></returns>
public string GetGitRepositoryOwner()
{
if (GitRepository == null) return "";
return GitRepository.Identifier?.Split("/")[0];
}
}
}
using Nuke.Common;
using Nuke.Common.Git;
using ricaun.Nuke.Extensions;

namespace ricaun.Nuke.Components
{
/// <summary>
/// IHazGitRepository
/// </summary>
public interface IHazGitRepository : INukeBuild
{
/// <summary>
/// GitHubToken
/// </summary>
[Secret][Parameter] public string GitHubToken => TryGetValue(() => GitHubToken);

/// <summary>
/// GitRepository
/// </summary>
[GitRepository] GitRepository GitRepository => TryGetValue(() => GitRepository);

/// <summary>
/// GetGitRepositoryPackageUrl (default: https://nuget.pkg.github.com/repository_owner/index.json)
/// </summary>
/// <returns></returns>
public string GetGitRepositoryPackageUrl()
{
if (GitRepository == null)
{
Serilog.Log.Warning($"GitRepository not found.");
return "";
}
return $@"https://nuget.pkg.github.com/{GetGitRepositoryOwner()}/index.json";
}

/// <summary>
/// GetGitRepositoryOwner based on the GitRepository.Identifier
/// </summary>
/// <returns></returns>
public string GetGitRepositoryOwner()
{
if (GitRepository == null) return "";
return GitRepository.Identifier?.Split("/")[0];
}

/// <summary>
/// Indicates whether the forked repository is enabled.
/// </summary>
[Parameter]
bool EnableForkedRepository => TryGetValue<bool?>(() => EnableForkedRepository) ?? false;

/// <summary>
/// Determines if the forked repository should be skipped.
/// </summary>
/// <returns>True if the forked repository should be skipped; otherwise, false.</returns>
public bool SkipForked()
{
if (EnableForkedRepository)
return false;

return IsGitRepositoryForked();
}
/// <summary>
/// IsGitRepositoryForked
/// </summary>
/// <returns></returns>
public bool IsGitRepositoryForked()
{
return GitRepository.IsForked();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ricaun.Nuke/Components/IPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public interface IPack : IHazPack, IGitRelease
.OnlyWhenStatic(() => NugetApiKey.SkipEmpty())
.OnlyWhenStatic(() => IsServerBuild)
.OnlyWhenDynamic(() => GitRepository.IsOnMainOrMasterBranch())
.OnlyWhenDynamic(() => SkipForked())
.Executes(() =>
{
var releaseDirectory = GetReleaseDirectory(MainProject);
Expand Down
1 change: 1 addition & 0 deletions ricaun.Nuke/Components/IPrePack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface IPrePack : IPack, IGitPreRelease
.OnlyWhenStatic(() => NugetApiKey.SkipEmpty())
.OnlyWhenStatic(() => IsServerBuild)
.OnlyWhenDynamic(() => GitRepository.IsOnDevelopBranch())
.OnlyWhenDynamic(() => SkipForked())
.Executes(() =>
{
var version = MainProject.GetInformationalVersion();
Expand Down
22 changes: 22 additions & 0 deletions ricaun.Nuke/Extensions/GitHubExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nuke.Common;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.Tools.GitHub;
using Octokit;
Expand All @@ -14,6 +15,27 @@ namespace ricaun.Nuke.Extensions
/// </summary>
public static class GitHubExtension
{
/// <summary>
/// Determines whether the specified Git repository is a fork.
/// </summary>
/// <param name="gitRepository">The Git repository to check.</param>
/// <returns>
/// <c>true</c> if the specified Git repository is a fork; otherwise, <c>false</c>.
/// </returns>
public static bool IsForked(this GitRepository gitRepository)
{
if (gitRepository is null)
return false;

var gitHubOwner = gitRepository.GetGitHubOwner();
var gitHubName = gitRepository.GetGitHubName();
var repository = GitHubTasks.GitHubClient.Repository
.Get(gitHubOwner, gitHubName)
.Result;

return repository.Fork;
}

#region GitHubUtil
/// <summary>
/// Check if Tags already exists.
Expand Down

0 comments on commit 8c36f4c

Please sign in to comment.