Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add filesystem interface #736

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
branches: [ main ]
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]
tags: [ 'v[0-9]+.[0-9]+.[0-9]+', 'core/v[0-9]+.[0-9]+.[0-9]+' ]

jobs:
unit-tests:
Expand Down Expand Up @@ -133,10 +133,37 @@ jobs:
path: Artifacts/Packages
name: Packages

push_core:
name: "Push core"
if: ${{ startsWith(github.ref, 'refs/tags/core/v') }}
runs-on: macos-latest
environment: production
needs: [ pack ]
permissions:
contents: write
steps:
- name: Download packages
uses: actions/download-artifact@v4
with:
name: Packages
path: Artifacts/Packages
- name: Publish
run: |
echo "Found the following packages to push:"
search_dir=Artifacts/Packages
for entry in Artifacts/Packages/Core/*.nupkg
do
echo "- $entry"
done
for entry in Artifacts/Packages/Core/*.nupkg
do
nuget push $entry -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}} -SkipDuplicate
done

push:
name: "Push"
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
runs-on: macos-latest
environment: production
needs: [ pack ]
permissions:
Expand All @@ -151,11 +178,11 @@ jobs:
run: |
echo "Found the following packages to push:"
search_dir=Artifacts/Packages
for entry in Artifacts/Packages/*.nupkg
for entry in Artifacts/Packages/Main/*.nupkg
do
echo "- $entry"
done
for entry in Artifacts/Packages/*.nupkg
for entry in Artifacts/Packages/Main/*.nupkg
do
nuget push $entry -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}} -SkipDuplicate
done
Expand Down
4 changes: 1 addition & 3 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"CodeAnalysisEnd",
"CodeCoverage",
"Compile",
"DotNetFrameworkUnitTests",
"DotNetUnitTests",
"MutationComment",
"MutationTestPreparation",
Expand All @@ -41,8 +40,7 @@
"MutationTestsWindows",
"Pack",
"Restore",
"UnitTests",
"UpdateReadme"
"UnitTests"
]
},
"Verbosity": {
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Authors>Testably</Authors>
<Copyright>Copyright (c) 2024 Testably</Copyright>
<Copyright>Copyright (c) 2024- $([System.DateTime]::Now.ToString('yyyy')) Testably</Copyright>
<RepositoryUrl>https://github.com/Testably/Testably.Abstractions.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PackageVersion Include="System.Threading.Channels" Version="9.0.1"/>
</ItemGroup>
<ItemGroup>
<PackageVersion Include="MinVer" Version="6.0.0"/>
<PackageVersion Include="Nullable" Version="1.3.1"/>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Pipeline/Build.CodeAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ partial class Build
.SetProjectKey("Testably_Testably.Abstractions")
.AddVSTestReports(TestResultsDirectory / "*.trx")
.AddOpenCoverPaths(TestResultsDirectory / "reports" / "OpenCover.xml")
.SetPullRequestOrBranchName(GitHubActions, GitVersion)
.SetVersion(GitVersion?.SemVer)
.SetPullRequestOrBranchName(GitHubActions, BranchName)
.SetVersion(SemVer)
.SetToken(SonarToken));
});

Expand Down
154 changes: 149 additions & 5 deletions Pipeline/Build.Compile.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Utilities.Collections;
using Serilog;
using System;
using System.Linq;
using Nuke.Common.Utilities;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

// ReSharper disable AllUnderscoreLocalParameterName
Expand All @@ -14,13 +20,51 @@

partial class Build
{
string? BranchName;
AssemblyVersion? CoreVersion;
AssemblyVersion? MainVersion;
string? SemVer;
Project[] MainProjects = [];
Project[] CoreProjects = [];

Target CalculateNugetVersion => _ => _
.Unlisted()
.Executes(() =>
{
SemVer = GitVersion?.SemVer;
MainProjects =
[
Solution.Testably_Abstractions_Testing,
Solution.Testably_Abstractions_AccessControl,
Solution.Testably_Abstractions_Compression,
];

CoreProjects =
[
Solution.Testably_Abstractions,
Solution.Testably_Abstractions_Interface,
Solution.Testably_Abstractions_FileSystem_Interface,
];

CoreVersion = AssemblyVersion.FromGitVersion(GitVersionTasks.GitVersion(s => s
.SetFramework("net8.0")
.SetNoFetch(true)
.SetNoCache(true)
.DisableProcessOutputLogging()
.SetUpdateAssemblyInfo(false)
.AddProcessAdditionalArguments("/overrideconfig", "tag-prefix=core/v"))
.Result);

GitVersion gitVersion = GitVersionTasks.GitVersion(s => s
.SetFramework("net8.0")
.SetNoFetch(true)
.SetNoCache(true)
.DisableProcessOutputLogging()
.SetUpdateAssemblyInfo(false))
.Result;

MainVersion = AssemblyVersion.FromGitVersion(gitVersion);
SemVer = gitVersion.SemVer;
BranchName = gitVersion.BranchName;

if (GitHubActions?.IsPullRequest == true && GitVersion != null)
{
Expand Down Expand Up @@ -66,14 +110,114 @@
.WhenNotNull(SemVer, (summary, semVer) => summary
.AddPair("Version", semVer)));

foreach (var mainProject in MainProjects)
{
ClearNugetPackages(mainProject.Directory / "bin");
}

UpdateReadme(MainVersion.FileVersion, false);

Check warning on line 118 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / API tests

Dereference of a possibly null reference.

Check warning on line 118 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Static code analysis

Dereference of a possibly null reference.

Check warning on line 118 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Mutation tests (Linux)

Dereference of a possibly null reference.

Check warning on line 118 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Mutation tests (Windows)

Dereference of a possibly null reference.

Check warning on line 118 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 118 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Unit tests (windows-latest)

Dereference of a possibly null reference.

Check warning on line 118 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Unit tests (macos-latest)

Dereference of a possibly null reference.
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.EnableNoLogo()
.EnableNoRestore()
.SetVersion(SemVer)
.SetAssemblyVersion(GitVersion?.AssemblySemVer)
.SetFileVersion(GitVersion?.AssemblySemFileVer)
.SetInformationalVersion(GitVersion?.InformationalVersion));
.SetVersion(MainVersion!.FileVersion)
.SetAssemblyVersion(MainVersion!.FileVersion)
.SetFileVersion(MainVersion!.FileVersion));

UpdateReadme(CoreVersion.FileVersion, true);

Check warning on line 128 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / API tests

Dereference of a possibly null reference.

Check warning on line 128 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Static code analysis

Dereference of a possibly null reference.

Check warning on line 128 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Mutation tests (Linux)

Dereference of a possibly null reference.

Check warning on line 128 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Mutation tests (Windows)

Dereference of a possibly null reference.

Check warning on line 128 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 128 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Unit tests (windows-latest)

Dereference of a possibly null reference.

Check warning on line 128 in Pipeline/Build.Compile.cs

View workflow job for this annotation

GitHub Actions / Unit tests (macos-latest)

Dereference of a possibly null reference.
foreach (var coreProject in CoreProjects)
{
ClearNugetPackages(coreProject.Directory / "bin");
DotNetBuild(s => s
.SetProjectFile(coreProject)
.SetConfiguration(Configuration)
.EnableNoLogo()
.EnableNoRestore()
.SetProcessAdditionalArguments($"/p:SolutionDir={RootDirectory}/")
.SetVersion(CoreVersion!.FileVersion)
.SetAssemblyVersion(CoreVersion!.FileVersion)
.SetFileVersion(CoreVersion!.FileVersion));
}
});

public record AssemblyVersion(string FileVersion, string InformationalVersion)
{
[return: NotNullIfNotNull(nameof(gitVersion))]
public static AssemblyVersion? FromGitVersion(GitVersion gitVersion)
{
if (gitVersion is null)
{
return null;
}

return new AssemblyVersion(gitVersion.AssemblySemVer, gitVersion.InformationalVersion);
}
}

private void UpdateReadme(string fileVersion, bool forCore)

Check warning on line 158 in Pipeline/Build.Compile.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Pipeline/Build.Compile.cs#L158

Remove this unused method parameter 'forCore'.
{
string version;
if (GitHubActions?.Ref.StartsWith("refs/tags/", StringComparison.OrdinalIgnoreCase) == true)
{
version = GitHubActions.Ref.Substring("refs/tags/".Length);
}
else
{
version = string.Join('.', fileVersion.Split('.').Take(3));
if (version.IndexOf('-') != -1)
{
version = "v" + version.Substring(0, version.IndexOf('-'));
}
}

Log.Information("Update readme using '{Version}' as version", version);

StringBuilder sb = new();
string[] lines = File.ReadAllLines(Solution.Directory / "README.md");
sb.AppendLine(lines[0]);
sb.AppendLine(
$"[![Changelog](https://img.shields.io/badge/Changelog-v{version}-blue)](https://github.com/Testably/Testably.Abstractions/releases/tag/v{version})");
foreach (string line in lines.Skip(1))
{
if (line.StartsWith(
"[![Build](https://github.com/Testably/Testably.Abstractions/actions/workflows/build.yml") ||
line.StartsWith(
"[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure"))
{
continue;
}

if (line.StartsWith(
"[![Coverage](https://sonarcloud.io/api/project_badges/measure"))
{
sb.AppendLine(line
.Replace(")", $"&branch=release/v{version})"));
continue;
}

if (line.StartsWith("[![Mutation testing badge](https://img.shields.io/endpoint"))
{
sb.AppendLine(line
.Replace("%2Fmain)", $"%2Frelease%2Fv{version})")
.Replace("/main)", $"/release/v{version})"));
continue;
}

sb.AppendLine(line);
}

File.WriteAllText(ArtifactsDirectory / "README.md", sb.ToString());
}

private static void ClearNugetPackages(string binPath)
{
if (Directory.Exists(binPath))
{
foreach (string package in Directory.EnumerateFiles(binPath, "*nupkg", SearchOption.AllDirectories))
{
File.Delete(package);
}
}
}
}
Loading
Loading