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

♻️ Upgrade connorjs tools + refactor #7

Merged
merged 3 commits into from
Aug 11, 2024
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
24 changes: 8 additions & 16 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,13 @@ jobs:

- name: Use pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'pnpm'

- name: Use Java
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 21

- name: Install SonarQube scanner
run: dotnet tool install --global dotnet-sonarscanner

Expand All @@ -50,7 +42,7 @@ jobs:
-d:sonar.host.url='https://sonarcloud.io'
-d:sonar.test.inclusions='**/*-test/**/*.cs,**/*.test.ts'
-d:sonar.exclusions='**/*.json,**/*.props'
-d:sonar.coverageReportPaths='TestResults/report/SonarQube.xml'
-d:sonar.coverageReportPaths='artifacts/test-results/report/SonarQube.xml'
-k:connorjs_dotnet-with-esproj-example -o:connorjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
Expand All @@ -69,22 +61,22 @@ jobs:
- name: Fix JS package names
shell: pwsh
run: |
Get-ChildItem TestResults -Filter *.cobertura.xml -Name | Foreach-Object {
Get-ChildItem artifacts/test-results -Filter *.cobertura.xml -Name | Foreach-Object {
$projectName = $_ -replace ".{14}$"
(Get-Content TestResults/$_).replace("package name=`"main`"", "package name=`"${projectName}`"") | Set-Content TestResults/$_
(Get-Content artifacts/test-results/$_).replace("package name=`"main`"", "package name=`"${projectName}`"") | Set-Content artifacts/test-results/$_
}

- name: ReportGenerator
uses: danielpalme/[email protected]
with:
reports: TestResults/*.cobertura.xml
targetdir: TestResults/report
reports: artifacts/test-results/*.cobertura.xml
targetdir: artifacts/test-results/report
reporttypes: Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub;SonarQube

- name: Check coverage thresholds
shell: pwsh
run: |
$coverage = Get-Content -Raw TestResults/report/Summary.json | ConvertFrom-Json
$coverage = Get-Content -Raw artifacts/test-results/report/Summary.json | ConvertFrom-Json
if ($coverage.summary.linecoverage -lt 80 -or $coverage.summary.branchcoverage -lt 80 -or $coverage.summary.methodcoverage -lt 80) {
Write-Error "Coverage does not meet threshold.`n`nCI build failed."; Exit 1
}
Expand All @@ -99,15 +91,15 @@ jobs:

- name: Publish coverage in build summary
if: always() # Still publish coverage if tests failed
run: cat TestResults/report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
run: cat artifacts/test-results/report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY

- name: Upload coverage report to Codecov
if: always() # Still upload to CodeCov if tests failed
uses: codecov/codecov-action@v4
with:
disable_search: true
fail_ci_if_error: true
files: TestResults/*.cobertura.xml
files: artifacts/test-results/*.cobertura.xml
flags: unittests
plugins: noop
token: ${{ secrets.CODECOV_TOKEN }}
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
## Solution ##

# Build
artifacts/
dist/
node_modules/

# Test
TestResults/

## IDE ##

# Rider/JetBrains
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
22
10 changes: 5 additions & 5 deletions ci-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ function Write-Color($color) {
}

# Clean coverage directory
Remove-Item -Recurse -Force TestResults -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force artifacts/test-results -ErrorAction SilentlyContinue

# Run the build
dotnet restore --verbosity $verbosity
dotnet build --verbosity $verbosity --configuration Release --no-restore
dotnet test --verbosity $verbosity --configuration Release --no-build
Get-ChildItem TestResults -Filter *.cobertura.xml -Name | Foreach-Object {
Get-ChildItem artifacts/test-results -Filter *.cobertura.xml -Name | Foreach-Object {
$projectName = $_ -replace ".{14}$"
(Get-Content TestResults/$_).replace("package name=`"main`"", "package name=`"${projectName}`"") | Set-Content TestResults/$_
(Get-Content artifacts/test-results/$_).replace("package name=`"main`"", "package name=`"${projectName}`"") | Set-Content artifacts/test-results/$_
}
reportgenerator -reports:"TestResults/*.cobertura.xml" -targetdir:TestResults/report -reporttypes:"Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub;SonarQube" -verbosity:Warning
reportgenerator -reports:"artifacts/test-results/*.cobertura.xml" -targetdir:artifacts/test-results/report -reporttypes:"Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub;SonarQube" -verbosity:Warning

# Output coverage information
$coverage = Get-Content -Raw TestResults/report/Summary.json | ConvertFrom-Json
$coverage = Get-Content -Raw artifacts/test-results/report/Summary.json | ConvertFrom-Json
$coverage.coverage.assemblies | Format-Table @{ L = ' Project '; E = { "$($_.name)" }; A = 'center' }, @{ L = ' Line '; E = { "$($_.coverage.toString() )%" }; A = 'center' }, @{ L = ' Branch '; E = { "$( $_.branchcoverage )%" }; A = 'center' }, @{ L = ' Method '; E = { "$( $_.methodcoverage )%" }; A = 'center' }
if ($coverage.summary.linecoverage -lt 80 -or $coverage.summary.branchcoverage -lt 80 -or $coverage.summary.methodcoverage -lt 80) {
Write-Color red "Coverage does not meet threshold.`n`nCI build failed."; Exit 1
Expand Down
12 changes: 6 additions & 6 deletions client/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

<!-- Debug build command arguments (auto-fix, used in local dev) -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<EslintArgs>$(EslintArgs) --fix</EslintArgs>
<PrettierArgs>$(PrettierArgs) --write</PrettierArgs>
<EslintArgs>--fix</EslintArgs>
<PrettierArgs>--list-different --write</PrettierArgs>
</PropertyGroup>

<!-- Build: eslint -->
<Target Name="eslint" AfterTargets="Build">
<Exec
Command="pnpm exec eslint --format pretty . $(EslintArgs)"
Command="pnpm exec eslint --format pretty $(EslintArgs) ."
StandardOutputImportance="normal"
/>
</Target>

<!-- Build: prettier -->
<Target Name="prettier" AfterTargets="Build">
<Exec
Command="pnpm exec prettier . $(PrettierArgs)"
Command="pnpm exec prettier --ignore-unknown $(PrettierArgs) ."
StandardOutputImportance="normal"
/>
</Target>
Expand All @@ -38,8 +38,8 @@

<!-- Test: vitest -->
<Target Name="vitest" AfterTargets="VSTest"
Inputs="$([MSBuild]::GetPathOfFileAbove('vitest.config.js'));@(ProjectFiles)"
Outputs="$(WorkspaceRoot)TestResults/$(ProjectName).cobertura.xml"
Inputs="$([MSBuild]::GetPathOfFileAbove('vitest.config.ts'));@(ProjectFiles)"
Outputs="$(WorkspaceRoot)artifacts/test-results/$(ProjectName).cobertura.xml"
>
<!-- Add output similar to .NET VSTest -->
<Message Text="Run tests: '$(ProjectRoot)' [vitest]" Importance="high" />
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion client/hello-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"baseUrl": ".",
"outDir": "../../artifacts/tsc/hello-js"
},
"extends": "@connorjs/tsconfig/base/tsconfig.json"
"extends": "../tsconfig.json"
}
1 change: 1 addition & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "@connorjs/tsconfig/base/tsconfig.json" }
8 changes: 6 additions & 2 deletions client/vitest.config.js → client/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import path from "node:path";
import { defineConfig } from "vitest/config";

const workspaceRoot = path.resolve(import.meta.dirname, `..`);
const artifactsRoot = path.join(workspaceRoot, `artifacts`);
const projectRoot = process.cwd();
const projectName = path.basename(projectRoot);

export default defineConfig({
cacheDir: path.join(artifactsRoot, `vite`, projectName),
test: {
coverage: {
all: true,
clean: false, // Workspace-wide coverage directory; do not clean
provider: `v8`,
// Coverage reporter
reporter: [[`cobertura`, { file: `${projectName}.cobertura.xml` }]],
reportsDirectory: `${workspaceRoot}/TestResults`,
reportsDirectory: path.join(artifactsRoot, `test-results`),
thresholds: {
branches: 80,
functions: 80,
Expand All @@ -23,7 +25,9 @@ export default defineConfig({
},
},
// Unit test reporter (not coverage)
reporters: process.env.GITHUB_ACTIONS ? ["dot", "github-actions"] : ["dot"],
reporters: process.env[`GITHUB_ACTIONS`]
? [`dot`, `github-actions`]
: [`dot`],
restoreMocks: true,
},
});
5 changes: 3 additions & 2 deletions dotnet-with-esproj-example.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "client", "client", "{B459F9
.node-version = .node-version
client\Directory.Build.props = client\Directory.Build.props
client\Directory.Build.targets = client\Directory.Build.targets
eslint.config.js = eslint.config.js
client\eslint.config.js = client\eslint.config.js
package.json = package.json
pnpm-lock.yaml = pnpm-lock.yaml
pnpm-workspace.yaml = pnpm-workspace.yaml
client\vitest.config.js = client\vitest.config.js
client\tsconfig.json = client\tsconfig.json
client\vitest.config.ts = client\vitest.config.ts
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "server", "server", "{8CE9A197-C77E-40CB-B19E-97DC0AA5D36E}"
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"private": true,
"type": "module",
"devDependencies": {
"@connorjs/tsconfig": "~0.2.0",
"@vitest/coverage-v8": "^2.0.4",
"eslint-config-connorjs": "1.0.0-beta.2",
"@connorjs/tsconfig": "^0.3.0",
"@types/node": "^22.2.0",
"@vitest/coverage-v8": "^2.0.5",
"eslint-config-connorjs": "^1.1.0",
"prettier": "^3.3.3",
"typescript": "^5.5.4",
"vitest": "^2.0.4"
}
"vitest": "^2.0.5"
},
"packageManager": "[email protected]+sha512.dc09430156b427f5ecfc79888899e1c39d2d690f004be70e05230b72cb173d96839587545d09429b55ac3c429c801b4dc3c0e002f653830a420fa2dd4e3cf9cf"
}
Loading