Skip to content

Commit

Permalink
🎉 Create new example (#1)
Browse files Browse the repository at this point in the history
Creates new example solution (project). Lays the groundwork for the repo.
  • Loading branch information
connorjs authored Jul 23, 2024
1 parent abcf981 commit e3760eb
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 2 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root = true

[*]
# Prettier default
charset = utf-8
insert_final_newline = true
end_of_line = lf
max_line_length = 80
trim_trailing_whitespace = true

# Custom
# Use tabs: https://alexandersandberg.com/articles/default-to-tabs-instead-of-spaces-for-an-accessible-first-environment/
indent_style = tab

[*.cs]
# CSharpier default is 100
max_line_length = 100

[*.{csproj,esproj,props}]
# Increase line length given .NET XML is whitespace sensitive
max_line_length = 999

[*.{yaml,yml}]
# YAML disallows tabs: https://yaml.org/spec/
indent_size = 2
indent_style = space
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text eol=lf
39 changes: 39 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Pipeline

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
Build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full depth (not shallow) for better relevancy of Sonar analysis

- name: Use .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

# Begin ci-build.ps1
- name: dotnet restore
run: dotnet restore

- name: dotnet build
run: dotnet build -c release --no-restore

- name: dotnet test
run: dotnet test -c release --no-build
# End ci-build.ps1

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Solution ##

# Build
artifacts/
dist/
node_modules/

# Test
coverage/
TestResults/

## IDE ##

# Rider/JetBrains
.idea/
*.user
47 changes: 47 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Project>
<!-- MSBuild properties (general) -->
<!-- https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-properties -->
<PropertyGroup>
<!-- Artifacts -->
<UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>

<!-- MSBuild properties (for .NET) -->
<!-- https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props -->
<PropertyGroup>
<!-- Framework properties -->
<TargetFramework>net8.0</TargetFramework>

<!-- Publish related -->
<IsPublishable>false</IsPublishable> <!-- Private -->

<!-- Reference -->
<DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences> <!-- Prefer explicit dependencies -->

<!-- Code generation -->
<ImplicitUsings>disable</ImplicitUsings> <!-- Prefer explicit usings -->
</PropertyGroup>

<!-- C# compiler options -->
<!-- https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/ -->
<PropertyGroup>
<!-- Language -->
<Nullable>enable</Nullable>

<!-- Code generation -->
<Deterministic>true</Deterministic>
</PropertyGroup>

<!-- Unit test coverage -->
<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('test'))">
<!-- Recommended to disable if no C++ native code. -->
<EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation>
<EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>
</PropertyGroup>

<!-- Unit test usings -->
<ItemGroup Condition="$(MSBuildProjectName.EndsWith('test'))">
<Using Include="FluentAssertions" />
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="connorjs-analyzers" Version="0.2.3" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# dotnet-with-esproj-example
Example repo with C# and JS/TS with build orchestration via `dotnet` (csproj + esproj)
# .NET with `.esproj` Example

Example repository with C# and JS/TS with build orchestration via `dotnet` (`.csproj` and `.esproj`).
8 changes: 8 additions & 0 deletions ci-build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try {
$env:CI = true
dotnet restore
dotnet build -c release --no-restore
dotnet test -c release --no-build
} finally {
$env:CI = $null
}
49 changes: 49 additions & 0 deletions dotnet-with-esproj-example.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hello-cs", "libs\hello-cs\hello-cs.csproj", "{CA70F551-74BE-49DB-B5CC-D64C0D321478}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{7592EEA2-3C6C-4ED0-9EB7-5EC6DBB51DE5}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
.github\workflows\pipeline.yaml = .github\workflows\pipeline.yaml
ci-build.ps1 = ci-build.ps1
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
global.json = global.json
LICENSE = LICENSE
README.md = README.md
sonar-project.properties = sonar-project.properties
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{2E75741F-092F-4C2C-A182-AAF9F38CEC58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hello-cs-test", "libs\hello-cs-test\hello-cs-test.csproj", "{2652DC61-0D21-423D-BF0E-FA67ED4A68F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CA70F551-74BE-49DB-B5CC-D64C0D321478}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA70F551-74BE-49DB-B5CC-D64C0D321478}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA70F551-74BE-49DB-B5CC-D64C0D321478}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA70F551-74BE-49DB-B5CC-D64C0D321478}.Release|Any CPU.Build.0 = Release|Any CPU
{2652DC61-0D21-423D-BF0E-FA67ED4A68F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2652DC61-0D21-423D-BF0E-FA67ED4A68F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2652DC61-0D21-423D-BF0E-FA67ED4A68F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2652DC61-0D21-423D-BF0E-FA67ED4A68F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CA70F551-74BE-49DB-B5CC-D64C0D321478} = {2E75741F-092F-4C2C-A182-AAF9F38CEC58}
{2652DC61-0D21-423D-BF0E-FA67ED4A68F7} = {2E75741F-092F-4C2C-A182-AAF9F38CEC58}
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"msbuild-sdks": {
"MSTest.Sdk": "3.5.0"
},
"sdk": {
"rollForward": "latestFeature",
"version": "8.0.300"
}
}
15 changes: 15 additions & 0 deletions libs/hello-cs-test/HelloUtilityTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Connorjs.DotNetWithEsprojExample.Hello;

[TestClass]
public class HelloUtilityTest
{
[DataTestMethod]
[DataRow(null, "Hello, world!")]
[DataRow("", "Hello, world!")]
[DataRow(" ", "Hello, !")]
[DataRow("Nx", "Hello, Nx!")]
public void Hello(string? name, string expected)
{
HelloUtility.Hello(name).Should().Be(expected);
}
}
13 changes: 13 additions & 0 deletions libs/hello-cs-test/hello-cs-test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="MSTest.Sdk">
<PropertyGroup>
<RootNamespace>Connorjs.DotNetWithEsprojExample.Hello</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\hello-cs\hello-cs.csproj" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions libs/hello-cs/HelloUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Connorjs.DotNetWithEsprojExample.Hello;

public static class HelloUtility
{
/// <summary>
/// Returns a hello string.
/// </summary>
/// <param name="name">The name to include. Optional.</param>
/// <returns>A hello string.</returns>
public static string Hello(string? name)
{
var nameToReturn = string.IsNullOrEmpty(name) ? "world" : name;
return $"Hello, {nameToReturn}!";
}
}
5 changes: 5 additions & 0 deletions libs/hello-cs/hello-cs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Connorjs.DotNetWithEsprojExample.Hello</RootNamespace>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sonar.projectKey=connorjs_dotnet-with-esproj-example
sonar.organization=connorjs

## Analysis scope - https://docs.sonarsource.com/sonarcloud/advanced-setup/analysis-scope/

# Define the same root directory for sources and tests
sonar.sources=libs
sonar.tests=libs

# Include test subdirectories and file patterns in test scope
sonar.test.inclusions=**/-test/**/*,**/*.test.*

# Exclude test subdirectories and file patterns from source scope
sonar.exclusions=**/-test/**/*,**/*.test.*

0 comments on commit e3760eb

Please sign in to comment.