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

Feature/lint staged #998

Merged
merged 2 commits into from
Nov 20, 2023
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
22 changes: 19 additions & 3 deletions .build/Build.CI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
ExcludedTargets = new[] { nameof(ICanClean.Clean), nameof(ICanRestoreWithDotNetCore.DotnetToolRestore) },
Enhancements = new[] { nameof(CiMiddleware) }
)]
[GitHubActionsLint(
"lint",
GitHubActionsImage.UbuntuLatest,
AutoGenerate = false,
OnPullRequestTargetBranches = new[] { "master", "main", "next" },
Enhancements = new[] { nameof(LintStagedMiddleware) }
)]
[GitHubActionsSteps(
"inputs",
GitHubActionsImage.UbuntuLatest,
Expand Down Expand Up @@ -103,10 +110,19 @@ public static RocketSurgeonGitHubActionsConfiguration CiMiddleware(RocketSurgeon
.First(z => z.Name.Equals("Build", StringComparison.OrdinalIgnoreCase))
.UseDotNetSdks("6.0", "8.0")
.AddNuGetCache()
// .ConfigureForGitVersion()
// .ConfigureForGitVersion()
.ConfigureStep<CheckoutStep>(step => step.FetchDepth = 0)
.PublishLogs<Pipeline>()
.FailFast = false;
.PublishLogs<Pipeline>();

return configuration;
}

public static RocketSurgeonGitHubActionsConfiguration LintStagedMiddleware(RocketSurgeonGitHubActionsConfiguration configuration)
{
configuration
.Jobs.OfType<RocketSurgeonsGithubActionsJob>()
.First(z => z.Name.Equals("Build", StringComparison.OrdinalIgnoreCase))
.UseDotNetSdks("6.0", "8.0");

return configuration;
}
Expand Down
2 changes: 1 addition & 1 deletion .build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public partial class Pipeline : NukeBuild,
ICanPackWithDotNetCore,
IHaveDataCollector,
ICanClean,
ICanLintStagedFiles,
ICanDotNetFormat,
ICanPrettier,
IHavePublicApis,
ICanUpdateReadme,
IGenerateCodeCoverageReport,
IGenerateCodeCoverageSummary,
IGenerateCodeCoverageBadges,
ICanRegenerateBuildConfiguration,
IHaveConfiguration<Configuration>
{
/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/ci-ignore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ on:
- '.github/labels.yml'
- '.github/release.yml'
- '.github/renovate.json'
permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: none
issues: write
discussions: none
packages: none
pages: none
pull-requests: write
repository-projects: none
security-events: none
statuses: write

jobs:
build:
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,26 @@ on:
- '.github/labels.yml'
- '.github/release.yml'
- '.github/renovate.json'
permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: none
issues: write
discussions: none
packages: none
pages: none
pull-requests: write
repository-projects: none
security-events: none
statuses: write

jobs:
build:
env:
NUGET_PACKAGES: '${{ github.workspace }}/.nuget/packages'
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/inputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ on:
withOutputsISetAThing:
description: 'Some output value'
value: ${{ jobs.build.outputs.withOutputsISetAThing }}
permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: none
issues: write
discussions: none
packages: none
pages: none
pull-requests: write
repository-projects: none
security-events: none
statuses: write

jobs:
build:
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# This code was generated.
#
# - To turn off auto-generation set:
#
# [GitHubActionsLint (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_lint --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: lint

on:
pull_request_target:
branches:
- 'master'
- 'main'
- 'next'
permissions:
actions: read
checks: read
contents: write
deployments: read
id-token: none
issues: write
discussions: none
packages: none
pages: none
pull-requests: write
repository-projects: none
security-events: none
statuses: write

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
repository: '${{ github.event.pull_request.head.repo.full_name }}'
ref: '${{ github.event.pull_request.head.ref }}'
clean: 'false'
- name: 🔨 Use .NET Core 6.0 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- name: 🔨 Use .NET Core 8.0 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0.x'
- name: 🎁 dotnet tool restore
run: |
dotnet tool restore
- name: Regenerate Build Configurations
id: regenerateBuildConfigurations
run: |
dotnet nuke RegenerateBuildConfigurations --skip --thisisaothervariable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisanothervariable '${{ vars.THIS_IS_ANOTHER_VARIABLE }}' --this_is_a_variable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisaenv '${{ env.THIS_IS_A_ENV || 'test' }}' --thisisasecret '${{ secrets.THIS_IS_A_SECRET }}' --githubtoken '${{ secrets.GITHUB_TOKEN }}'
- name: Lint Staged
id: lintStaged
run: |
dotnet nuke LintStaged --skip --thisisaothervariable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisanothervariable '${{ vars.THIS_IS_ANOTHER_VARIABLE }}' --this_is_a_variable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisaenv '${{ env.THIS_IS_A_ENV || 'test' }}' --thisisasecret '${{ secrets.THIS_IS_A_SECRET }}' --githubtoken '${{ secrets.GITHUB_TOKEN }}'
- name: Add & Commit
uses: EndBug/add-and-commit@v9
with:
message: 'Automatically linting code'
7 changes: 1 addition & 6 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

dotnet nuke --help > /dev/null 2>&1 || true
export NUKE_INTERNAL_INTERCEPTOR=1
npx lint-staged -d -r
dotnet .build/bin/Debug/net6.0/.build.dll regenerate-build-configurations
git add .github/workflows/*.yml
git add .nuke/build.schema.json
dotnet nuke lint-staged
18 changes: 6 additions & 12 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
function forEachChunk(chunks, callback, chunkSize = 50) {
var mappedFiles = [];
var files = chunks.concat();
while (files.length > 0) {
var chunk = files.splice(0, chunkSize);
mappedFiles = mappedFiles.concat(callback(chunk));
}
return mappedFiles;
if (!process.env.NUKE_BUILD_ASSEMBLY) {
throw new Error("Environment variable 'NUKE_BUILD_ASSEMBLY' is not set.");
}

module.exports = {
'!(*verified|*received).cs': filenames => [`dotnet .build/bin/Debug/net6.0/.build.dll lint --lint-files ${filenames.join(' ')}`],
'*.{Shipped.txt,Unshipped.txt}': filenames => [`dotnet .build/bin/Debug/net6.0/.build.dll move-unshipped-to-shipped --lint-files ${filenames.join(' ')}`],
'*.{csproj,targets,props,xml}': filenames => forEachChunk(filenames, chunk => [`prettier --write '${chunk.join(`' '`)}'`]),
'*.{js,ts,jsx,tsx,json,yml,yaml}': filenames => forEachChunk(filenames, chunk => [`prettier --write '${chunk.join(`' '`)}'`]),
'!(*verified|*received).cs': filenames => [`dotnet ${process.env.NUKE_BUILD_ASSEMBLY} lint --lint-files ${filenames.join(' ')}`],
'*.{Shipped.txt,Unshipped.txt}': filenames => [`dotnet ${process.env.NUKE_BUILD_ASSEMBLY} move-unshipped-to-shipped --lint-files ${filenames.join(' ')}`],
'*.{csproj,targets,props,xml}': filenames => [`prettier --write '${filenames.join(`' '`)}`],
'*.{js,ts,jsx,tsx,json,yml,yaml}': filenames => [`prettier --write '${filenames.join(`' '`)}`],
};
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"JetBrainsCleanupCode",
"Lint",
"LintPublicApiAnalyzers",
"LintStaged",
"MoveUnshippedToShipped",
"Pack",
"PostLint",
Expand Down Expand Up @@ -147,6 +148,7 @@
"JetBrainsCleanupCode",
"Lint",
"LintPublicApiAnalyzers",
"LintStaged",
"MoveUnshippedToShipped",
"Pack",
"PostLint",
Expand Down
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.6.2" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Docfx.App" Version="2.74.0" />
<PackageVersion Include="Docfx.App" Version="2.73.2" />
<PackageVersion Include="Buildalyzer" Version="5.0.1" />
<PackageVersion Include="GitVersion.Tool" Version="5.12.0" />
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
Expand All @@ -38,9 +38,9 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.FakeItEasy" Version="8.0.3" />
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.XUnit" Version="8.0.3" />
<PackageVersion Include="xunit" Version="2.6.2" />
<PackageVersion Include="xunit.analyzers" Version="1.6.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.4" />
<PackageVersion Include="xunit" Version="2.6.1" />
<PackageVersion Include="xunit.analyzers" Version="1.5.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
<Import
Project="$(MSBuildThisFileDirectory)/Directory.Packages.support.props"
Expand Down
1 change: 1 addition & 0 deletions Nuke.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github/workflows/sync-labels.yml = .github/workflows/sync-labels.yml
.github/workflows/update-milestone.yml = .github/workflows/update-milestone.yml
.github/workflows/inputs.yml = .github/workflows/inputs.yml
.github/workflows/lint.yml = .github/workflows/lint.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".husky", ".husky", "{39F6D15D-2627-4749-9B1D-EB7C9C656465}"
Expand Down
36 changes: 36 additions & 0 deletions src/Nuke/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.ObjectModel;
using Nuke.Common.IO;
using Nuke.Common.Tools.ReportGenerator;
using Nuke.Common.Utilities.Collections;

namespace Rocket.Surgery.Nuke;

Expand Down Expand Up @@ -54,4 +56,38 @@
{
return toolSettings.SetReports(reports.Select(z => z.ToString()).ToArray());
}

/// <summary>
/// Add a value to the dictionary if it's missing
/// </summary>
/// <param name="dictionary"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <returns></returns>
public static IDictionary<TKey, TValue> AddIfMissing<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull

Check warning on line 69 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 69 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 69 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 69 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 69 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 69 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{

Check warning on line 70 in src/Nuke/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Nuke/Extensions.cs#L70

Added line #L70 was not covered by tests
if (dictionary.TryGetValue(key, out _)) return dictionary;
dictionary[key] = value;
return dictionary;
}

Check warning on line 74 in src/Nuke/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Nuke/Extensions.cs#L72-L74

Added lines #L72 - L74 were not covered by tests

/// <summary>
/// Add a value to the dictionary if it's missing
/// </summary>
/// <param name="dictionary"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <returns></returns>
public static IReadOnlyDictionary<TKey, TValue> AddIfMissing<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull

Check warning on line 85 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 85 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 85 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 85 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 85 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check warning on line 85 in src/Nuke/Extensions.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Symbol 'AddIfMissing<TKey, TValue>' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{

Check warning on line 86 in src/Nuke/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Nuke/Extensions.cs#L86

Added line #L86 was not covered by tests
if (dictionary.TryGetValue(key, out _)) return dictionary;

var newDictionary = dictionary.ToDictionary(z => z.Key, z => z.Value);
newDictionary[key] = value;
return new ReadOnlyDictionary<TKey, TValue>(newDictionary);
}

Check warning on line 92 in src/Nuke/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Nuke/Extensions.cs#L90-L92

Added lines #L90 - L92 were not covered by tests
}
Loading
Loading