Skip to content
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
143 changes: 143 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Build
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
release:
types: [published]

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget

jobs:
build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarQube Cloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarQube Cloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Cache .Net Tools
id: cache-dotnet-tools
uses: actions/cache@v4
with:
path: ~\.dotnet\tools
key: ${{ runner.os }}-dotnet
restore-keys: ${{ runner.os }}-dotnet
- name: Install dotnet-coverage
shell: powershell
run: dotnet tool install --global dotnet-coverage
- name: Install SonarQube Cloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"retroandchill_SourceGenerators" /o:"fcorso2016" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/example/**/*,**/examples/**/*"
dotnet build
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

create_nuget:
name: Create Nuget Package
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4

- name: Package Nuget Package
run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}

- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg

validate_nuget:
name: Validate Nuget Package
runs-on: windows-latest
needs: [ create_nuget ]
steps:
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4

# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

- name: Install nuget validator
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global

# Validate metadata and content of the NuGet package
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
# If some rules are not applicable, you can disable them
# using the --excluded-rules or --excluded-rule-ids option
- name: Validate package
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")

deploy:
name: Publish Nuget Package
# Publish only when creating a GitHub Release
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# You can update this logic if you want to manage releases differently
if: github.event_name == 'release'
runs-on: windows-latest
needs: [ validate_nuget, build ]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET Core
uses: actions/setup-dotnet@v4

# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish NuGet package
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Retro.AutoCommandLine.Core.Attributes;
using Retro.AutoCommandLine.Attributes;
using Retro.AutoCommandLine.Core.Handlers;
namespace Retro.AutoCommandLine.Sample.Commands;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Retro.AutoCommandLine.Core;
using Retro.AutoCommandLine.Core.Attributes;
using Retro.AutoCommandLine.Core.Handlers;
using Retro.AutoCommandLine.Attributes;
namespace Retro.AutoCommandLine.Sample.Commands;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<RootNamespace>Retro.AutoCommandLine.Sample</RootNamespace>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,4 +21,8 @@
<Compile Remove="Handlers\CommandHandlerAdapter.cs" />
</ItemGroup>

<ItemGroup>
<Folder Include="Attributes\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
#if AUTO_COMMAND_LINE_GENERATOR
using RhoMicro.CodeAnalysis;
#endif

namespace Retro.AutoCommandLine.Attributes;

[AttributeUsage(AttributeTargets.Property)]
#if AUTO_COMMAND_LINE_GENERATOR
[IncludeFile]
#endif
internal class ArgumentAttribute(string? name = null) : CliParameterAttribute {

public string? Name { get; } = name;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Immutable;
#if AUTO_COMMAND_LINE_GENERATOR
using RhoMicro.CodeAnalysis;
#endif

namespace Retro.AutoCommandLine.Attributes;

#if AUTO_COMMAND_LINE_GENERATOR
[IncludeFile]
#endif
internal abstract class CliParameterAttribute : Attribute {

public string? Description { get; init; }

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using System;
namespace Retro.AutoCommandLine.Core.Attributes;
#if AUTO_COMMAND_LINE_GENERATOR
using RhoMicro.CodeAnalysis;
#endif

namespace Retro.AutoCommandLine.Attributes;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)]
public class CommandAttribute(string? name = null) : Attribute {
#if AUTO_COMMAND_LINE_GENERATOR
[IncludeFile]
#endif
internal class CommandAttribute(string? name = null) : Attribute {
public string? Name { get; } = name;

public string? Description { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
#if AUTO_COMMAND_LINE_GENERATOR
using RhoMicro.CodeAnalysis;
#endif

namespace Retro.AutoCommandLine.Attributes;

[AttributeUsage(AttributeTargets.Method)]
#if AUTO_COMMAND_LINE_GENERATOR
[IncludeFile]
#endif
internal class CommandHandlerAttribute : Attribute;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
#if AUTO_COMMAND_LINE_GENERATOR
using RhoMicro.CodeAnalysis;
#endif

namespace Retro.AutoCommandLine.Attributes;

[AttributeUsage(AttributeTargets.Class)]
#if AUTO_COMMAND_LINE_GENERATOR
[IncludeFile]
#endif
internal class CommandLineContextAttribute(Type rootCommand) : Attribute {

public Type RootCommand { get; } = rootCommand;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Immutable;
#if AUTO_COMMAND_LINE_GENERATOR
using RhoMicro.CodeAnalysis;
#endif

namespace Retro.AutoCommandLine.Attributes;

[AttributeUsage(AttributeTargets.Property)]
#if AUTO_COMMAND_LINE_GENERATOR
[IncludeFile]
#endif
internal class OptionAttribute(params string[] aliases) : CliParameterAttribute {

public ImmutableArray<string> Aliases { get; } = [..aliases];

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Retro.AutoCommandLine.Core.Attributes;
using Retro.AutoCommandLine.Model;
using Retro.AutoCommandLine.Attributes;
using Retro.AutoCommandLine.Model.Attributes;
using Retro.AutoCommandLine.Model.Commands;
using Retro.AutoCommandLine.Properties;
using Retro.AutoCommandLine.Utils;
using Retro.SourceGeneratorUtilities.Utilities;
namespace Retro.AutoCommandLine.Generators;

[Generator]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.CodeAnalysis;
using RhoMicro.CodeAnalysis.Generated;
namespace Retro.AutoCommandLine.Generators;

/// <summary>
/// Represents a source generator that facilitates copying files for use in code generation tasks.
/// </summary>
[Generator]
internal class CopyFilesGenerator : IIncrementalGenerator {

/// <inheritdoc/>
public void Initialize(IncrementalGeneratorInitializationContext context) {
IncludedFileSources.RegisterToContext(context);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Immutable;
using Retro.AutoCommandLine.Core.Attributes;
using Retro.AutoCommandLine.Attributes;
using Retro.SourceGeneratorUtilities.Utilities.Attributes;
namespace Retro.AutoCommandLine.Model.Attributes;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Immutable;
using Retro.AutoCommandLine.Core.Attributes;
using Retro.AutoCommandLine.Attributes;
using Retro.SourceGeneratorUtilities.Utilities.Attributes;
namespace Retro.AutoCommandLine.Model.Attributes;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Retro.AutoCommandLine.Core.Attributes;
using Retro.AutoCommandLine.Attributes;
using Retro.SourceGeneratorUtilities.Utilities.Attributes;
namespace Retro.AutoCommandLine.Model.Attributes;

Expand Down
Loading
Loading