Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
* release/1.1.0:
  Update 1.1.0 release notes
  Use preview LibGit2Sharp for all monikers
  Test ubuntu-18.04
  Add GitHub actions
  Update to LibGit2Sharp v0.27.0-preview-0102
  Added some tests.
  Added more basic configuration methods.
  Initial commit of the get config method.
  • Loading branch information
devlead committed Aug 9, 2021
2 parents 0935808 + 1f5e96c commit d3099d8
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 9 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build
on:
pull_request:
push:
branches:
- master
- develop
- hotfix/*

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

- name: Install .NET Core SDK 3.1.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

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

- if: matrix.os == 'windows-latest'
name: Run Cake script Windows
run: |
./build.ps1
- if: matrix.os != 'windows-latest'
name: Run Cake script Posix
run: |
./build.sh
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts

- name: Upload NuGet Package
uses: actions/upload-artifact@v2
with:
name: nuget
path: nuget
5 changes: 5 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### New in 1.1.0 (Released 2021/08/09)

* Update LibGit2Sharp to 0.27.0-preview-0102
* Add Basic Support for git Configuration Commands

### New in 1.0.1 (Released 2021/03/12)

* Add cake-addin tag to NuGet package
Expand Down
6 changes: 6 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ if (!isLocalBuild)
AppVeyor.UpdateBuildVersion(semVersion);
}
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
{
TaskSetup(context=> System.Console.WriteLine($"::group::{context.Task.Name.Quote()}"));
TaskTeardown(context=>System.Console.WriteLine("::endgroup::"));
}
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 3 additions & 4 deletions src/Cake.Git/Cake.Git.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net461' ">
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0096" />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0102" />
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.312" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0102" />
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.312" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
Expand Down
226 changes: 226 additions & 0 deletions src/Cake.Git/GitAliases.Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
using System;
using System.Collections.Generic;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.IO;
using Cake.Git.Extensions;
using LibGit2Sharp;

namespace Cake.Git
{
public static partial class GitAliases
{
/// <summary>
/// Gets the specified configuration value.
/// </summary>
///
/// <example>
/// <code>
/// var configValue = GitConfigGet&lt;string&gt;("user.email");
/// </code>
/// </example>
///
/// <param name="context">The context.</param>
/// <param name="repositoryDirectoryPath">Repository path.</param>
/// <param name="key">The configuration key.</param>
///
/// <typeparam name="T">The expected type of configuration.</typeparam>
///
/// <returns>The value of the specified configuration key.</returns>
///
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="KeyNotFoundException">Configuration value not found.</exception>
[CakeMethodAlias]
[CakeAliasCategory("Configuration")]
public static T GitConfigGet<T>(
this ICakeContext context,
DirectoryPath repositoryDirectoryPath,
string key)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (repositoryDirectoryPath is null)
{
throw new ArgumentException(nameof(repositoryDirectoryPath));
}

return context.UseRepository(
repositoryDirectoryPath,
repository =>
{
var config = repository.Config.Get<T>(key)
?? throw new KeyNotFoundException("Configuration not found.");
return config.Value;
});
}

/// <summary>
/// Gets the specified configuration value. If the specified value is not found it will return the specified
/// default value.
/// </summary>
///
/// <example>
/// <code>
/// var configValue = GitConfigGet("user.email", "[email protected]");
/// </code>
/// </example>
///
/// <param name="context">The context.</param>
/// <param name="repositoryDirectoryPath">Repository path.</param>
/// <param name="key">The configuration key.</param>
/// <param name="defaultValue">The default value to use if the configuration isn't present.</param>
///
/// <typeparam name="T">The expected type of configuration.</typeparam>
///
/// <returns>The value of the specified configuration key.</returns>
///
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
[CakeMethodAlias]
[CakeAliasCategory("Configuration")]
public static T GitConfigGet<T>(
this ICakeContext context,
DirectoryPath repositoryDirectoryPath,
string key,
T defaultValue)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (repositoryDirectoryPath is null)
{
throw new ArgumentException(nameof(repositoryDirectoryPath));
}

return context.UseRepository(
repositoryDirectoryPath,
repository => repository.Config.GetValueOrDefault<T>(key));
}

/// <summary>
/// Gets the specified configuration value. If the specified value is not found it will return the specified
/// default value.
/// </summary>
///
/// <example>
/// <code>
/// GitConfigSet("user.email", "[email protected]");
/// </code>
/// </example>
///
/// <param name="context">The context.</param>
/// <param name="repositoryDirectoryPath">Repository path.</param>
/// <param name="key">The configuration key.</param>
/// <param name="newValue">The new value.</param>
///
/// <typeparam name="T">The type of configuration.</typeparam>
///
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
[CakeMethodAlias]
[CakeAliasCategory("Configuration")]
public static void GitConfigSetLocal<T>(
this ICakeContext context,
DirectoryPath repositoryDirectoryPath,
string key,
T newValue)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (repositoryDirectoryPath is null)
{
throw new ArgumentException(nameof(repositoryDirectoryPath));
}

context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Set(key, newValue, ConfigurationLevel.Local));
}

/// <summary>
/// Unsets the specified local configuration key.
/// </summary>
///
/// <example>
/// <code>
/// GitConfigUnsetLocal("user.email", "[email protected]");
/// </code>
/// </example>
///
/// <param name="context">The context.</param>
/// <param name="repositoryDirectoryPath">Repository path.</param>
/// <param name="key">The configuration key.</param>
///
/// <returns>Whether the key was unset.</returns>
///
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
[CakeMethodAlias]
[CakeAliasCategory("Configuration")]
public static void GitConfigUnsetLocal(
this ICakeContext context,
DirectoryPath repositoryDirectoryPath,
string key)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (repositoryDirectoryPath is null)
{
throw new ArgumentException(nameof(repositoryDirectoryPath));
}

context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Unset(key));
}

/// <summary>
/// Returns whether a configuration value exists with the specifed key.
/// </summary>
///
/// <example>
/// <code>
/// if (GetConfigurationExists&lt;string&gt;("user.email")
/// {
/// //..
/// }
/// </code>
/// </example>
///
/// <param name="context">The context.</param>
/// <param name="repositoryDirectoryPath">Repository path.</param>
/// <param name="key">The configuration key.</param>
///
/// <typeparam name="T">The expected configuration type.</typeparam>
///
/// <returns>Whether a configuration exists with the specified key.</returns>
///
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
[CakeMethodAlias]
[CakeAliasCategory("Configuration")]
public static bool GitConfigExists<T>(this ICakeContext context, DirectoryPath repositoryDirectoryPath, string key)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (repositoryDirectoryPath is null)
{
throw new ArgumentException(nameof(repositoryDirectoryPath));
}

return context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Get<T>(key) != null);
}
}
}
6 changes: 3 additions & 3 deletions src/SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
[assembly: AssemblyDescription("Cake Git AddIn")]
[assembly: AssemblyCompany("WCOM AB")]
[assembly: AssemblyProduct("Cake.Git")]
[assembly: AssemblyVersion("1.0.1")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyCopyright("Copyright © WCOM AB 2021")]
[assembly: CLSCompliant(true)]

22 changes: 20 additions & 2 deletions test.cake
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,22 @@ Task("Git-Log-Tag")
}
});

Task("Git-Config")
.Does(() =>
{
GitConfigSetLocal(testInitalRepo, "user.email", "[email protected]");
if (GitConfigExists<string>(testInitalRepo, "user.email"))
{
string email = GitConfigGet<string>(testInitalRepo, "user.email");
if (!string.Equals("[email protected]", email))
{
throw new InvalidOperationException("Wrong email in configuration.");
}
}
});



Task("Git-Tag")
Expand Down Expand Up @@ -924,7 +940,8 @@ Task("Default-Tests")
.IsDependentOn("Git-AllTags")
.IsDependentOn("Git-AllTags-Annotated")
.IsDependentOn("Git-AllTags-Targets")
.IsDependentOn("Git-Clean");
.IsDependentOn("Git-Clean")
.IsDependentOn("Git-Config");

Task("Local-Tests")
.IsDependentOn("Git-Init")
Expand Down Expand Up @@ -960,7 +977,8 @@ Task("Local-Tests")
.IsDependentOn("Git-AllTags")
.IsDependentOn("Git-AllTags-Annotated")
.IsDependentOn("Git-AllTags-Targets")
.IsDependentOn("Git-Clean");
.IsDependentOn("Git-Clean")
.IsDependentOn("Git-Config");

///////////////////////////////////////////////////////////////////////////////
// EXECUTION
Expand Down

0 comments on commit d3099d8

Please sign in to comment.