Skip to content

Commit 66910f1

Browse files
committed
Cleanup and improve scripts
1 parent e0f8af0 commit 66910f1

File tree

7 files changed

+59
-71
lines changed

7 files changed

+59
-71
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ concurrency:
2323
env:
2424
DOTNET_NOLOGO: true
2525
DOTNET_CLI_TELEMETRY_OPTOUT: true
26+
SOLUTION_FILE: JsonApiDotNetCore.sln
2627

2728
jobs:
2829
build-and-test:
@@ -124,12 +125,11 @@ jobs:
124125
# This contains the git tag name on release; in that case, we build the docs without publishing them.
125126
DOCFX_SOURCE_BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
126127
run: |
128+
$ErrorActionPreference = "Stop"
129+
$PSNativeCommandUseErrorActionPreference = $true
127130
cd docs
128131
& ./generate-examples.ps1
129132
dotnet docfx docfx.json --warningsAsErrors true
130-
if ($LastExitCode -ne 0) {
131-
Write-Error "docfx failed with exit code $LastExitCode."
132-
}
133133
Copy-Item CNAME _site/CNAME
134134
Copy-Item home/*.html _site/
135135
Copy-Item home/*.ico _site/
@@ -171,7 +171,7 @@ jobs:
171171
$inspectCodeOutputPath = Join-Path $env:RUNNER_TEMP 'jetbrains-inspectcode-results.xml'
172172
Write-Output "INSPECT_CODE_OUTPUT_PATH=$inspectCodeOutputPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
173173
dotnet jb inspectcode --version
174-
dotnet jb inspectcode JsonApiDotNetCore.sln --build --dotnetcoresdk=$(dotnet --version) --output="$inspectCodeOutputPath" --format="xml" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --properties:ContinuousIntegrationBuild=false --properties:RunAnalyzers=false --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal
174+
dotnet jb inspectcode $env:SOLUTION_FILE --build --dotnetcoresdk=$(dotnet --version) --output="$inspectCodeOutputPath" --format="xml" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --properties:ContinuousIntegrationBuild=false --properties:RunAnalyzers=false --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal
175175
- name: Upload output to artifacts
176176
uses: actions/upload-artifact@v4
177177
with:
@@ -241,14 +241,14 @@ jobs:
241241
242242
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash in pull request."
243243
dotnet jb cleanupcode --version
244-
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
244+
dotnet regitlint -s $env:SOLUTION_FILE --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
245245
- name: CleanupCode (on branch)
246246
if: ${{ github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch' }}
247247
shell: pwsh
248248
run: |
249249
Write-Output 'Running code cleanup on all files.'
250250
dotnet jb cleanupcode --version
251-
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN --fail-on-diff --print-diff
251+
dotnet regitlint -s $env:SOLUTION_FILE --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN --fail-on-diff --print-diff
252252
253253
publish:
254254
timeout-minutes: 60

Build.ps1

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
function VerifySuccessExitCode {
2-
if ($LastExitCode -ne 0) {
3-
throw "Command failed with exit code $LastExitCode."
4-
}
5-
}
1+
#Requires -Version 7.4
2+
$ErrorActionPreference = "Stop"
3+
$PSNativeCommandUseErrorActionPreference = $true
64

75
Write-Host "$(pwsh --version)"
86
Write-Host ".NET SDK $(dotnet --version)"
@@ -11,16 +9,7 @@ Remove-Item -Recurse -Force artifacts -ErrorAction SilentlyContinue
119
Remove-Item -Recurse -Force * -Include coverage.cobertura.xml
1210

1311
dotnet tool restore
14-
VerifySuccessExitCode
15-
1612
dotnet build --configuration Release
17-
VerifySuccessExitCode
18-
1913
dotnet test --no-build --configuration Release --verbosity quiet --collect:"XPlat Code Coverage"
20-
VerifySuccessExitCode
21-
2214
dotnet reportgenerator -reports:**\coverage.cobertura.xml -targetdir:artifacts\coverage -filefilters:-*.g.cs
23-
VerifySuccessExitCode
24-
2515
dotnet pack --no-build --configuration Release --output artifacts/packages
26-
VerifySuccessExitCode

cleanupcode.ps1

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Version 7.0
1+
#Requires -Version 7.4
22

33
# This script reformats (part of) the codebase to make it compliant with our coding guidelines.
44

@@ -7,41 +7,31 @@ param(
77
[string] $revision
88
)
99

10-
function VerifySuccessExitCode {
11-
if ($LastExitCode -ne 0) {
12-
throw "Command failed with exit code $LastExitCode."
13-
}
14-
}
10+
$ErrorActionPreference = "Stop"
11+
$PSNativeCommandUseErrorActionPreference = $true
1512

1613
dotnet tool restore
17-
VerifySuccessExitCode
18-
1914
dotnet restore
20-
VerifySuccessExitCode
15+
16+
$solutionFile = 'JsonApiDotNetCore.sln'
2117

2218
if ($revision) {
2319
$headCommitHash = git rev-parse HEAD
24-
VerifySuccessExitCode
25-
2620
$baseCommitHash = git rev-parse $revision
27-
VerifySuccessExitCode
2821

2922
if ($baseCommitHash -eq $headCommitHash) {
3023
Write-Output "Running code cleanup on staged/unstaged files."
3124
dotnet jb cleanupcode --version
32-
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f staged,modified
33-
VerifySuccessExitCode
25+
dotnet regitlint -s $solutionFile --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f staged,modified
3426
}
3527
else {
3628
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash, including staged/unstaged files."
3729
dotnet jb cleanupcode --version
38-
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash
39-
VerifySuccessExitCode
30+
dotnet regitlint -s $solutionFile --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash
4031
}
4132
}
4233
else {
4334
Write-Output "Running code cleanup on all files."
4435
dotnet jb cleanupcode --version
45-
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN
46-
VerifySuccessExitCode
36+
dotnet regitlint -s $solutionFile --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN
4737
}

docs/build-dev.ps1

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,64 @@
1-
#Requires -Version 7.3
1+
#Requires -Version 7.4
22

33
# This script builds the documentation website, starts a web server and opens the site in your browser. Intended for local development.
44

55
param(
66
# Specify -NoBuild to skip code build and examples generation. This runs faster, so handy when only editing Markdown files.
7-
[switch] $NoBuild=$False,
8-
# Specify -NoOpen to skip opening the documentation website in a web browser.
9-
[switch] $NoOpen=$False
7+
[switch] $NoBuild=$false,
8+
# Specify -NoOpen to skip opening the documentation website in a web browser (still starts the web server).
9+
[switch] $NoOpen=$false
1010
)
1111

12-
function VerifySuccessExitCode {
13-
if ($LastExitCode -ne 0) {
14-
throw "Command failed with exit code $LastExitCode."
15-
}
16-
}
12+
$ErrorActionPreference = "Stop"
13+
$PSNativeCommandUseErrorActionPreference = $true
14+
15+
# Workaround for bug at https://github.com/PowerShell/PowerShell/issues/23875#issuecomment-2672336383
16+
$PSDefaultParameterValues['Remove-Item:ProgressAction'] = 'SilentlyContinue'
1717

1818
function EnsureHttpServerIsInstalled {
1919
if ((Get-Command "npm" -ErrorAction SilentlyContinue) -eq $null) {
2020
throw "Unable to find npm in your PATH. please install Node.js first."
2121
}
2222

23-
# If this command fails with ENOENT after installing Node.js on Windows, manually create the directory %APPDATA%\npm.
24-
npm list --depth 1 --global httpserver >$null
23+
$global:hasHttpServerInstalled = $true
24+
25+
& {
26+
$PSNativeCommandUseErrorActionPreference = $false
27+
28+
# Workaround for error ENOENT returned from npm list, after installing Node.js on Windows.
29+
# See https://stackoverflow.com/questions/25093276/node-js-windows-error-enoent-stat-c-users-rt-appdata-roaming-npm
30+
if ($IsWindows) {
31+
New-Item -ItemType Directory -Force -Path $env:APPDATA\npm >$null
32+
}
2533

26-
if ($LastExitCode -eq 1) {
34+
npm list --depth 1 --global httpserver >$null
35+
36+
if ($LastExitCode -eq 1) {
37+
Write-Host "httpserver not found."
38+
$global:hasHttpServerInstalled = $false
39+
}
40+
}
41+
42+
if ($global:hasHttpServerInstalled -eq $false) {
43+
Write-Host "Installing httpserver."
2744
npm install -g httpserver
2845
}
2946
}
3047

3148
EnsureHttpServerIsInstalled
32-
VerifySuccessExitCode
3349

3450
if (-Not $NoBuild -Or -Not (Test-Path -Path _site)) {
3551
Remove-Item _site\* -Recurse -ErrorAction Ignore
36-
37-
dotnet build .. --configuration Release
38-
VerifySuccessExitCode
39-
52+
dotnet build .. --configuration Release /p:RunAnalyzers=false
4053
Invoke-Expression ./generate-examples.ps1
4154
} else {
4255
Remove-Item _site\* -Recurse -ErrorAction Ignore
4356
}
4457

4558
dotnet tool restore
46-
VerifySuccessExitCode
4759

4860
$env:DOCFX_SOURCE_BRANCH_NAME="dev"
49-
dotnet docfx ./docfx.json --warningsAsErrors true
50-
VerifySuccessExitCode
61+
dotnet docfx docfx.json --warningsAsErrors true
5162

5263
Copy-Item -Force home/*.html _site/
5364
Copy-Item -Force home/*.ico _site/
@@ -63,7 +74,7 @@ if (-Not $NoOpen) {
6374
}
6475

6576
Write-Host ""
66-
Write-Host "Web server started. Press Enter to close."
77+
Write-Host "Web server started. Site is available at http://localhost:8080. Press Enter to stop web server."
6778
$key = [Console]::ReadKey()
6879

6980
Stop-Job -Id $webServerJob.Id

docs/generate-examples.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#Requires -Version 7.3
1+
#Requires -Version 7.4
2+
$ErrorActionPreference = "Stop"
3+
$PSNativeCommandUseErrorActionPreference = $false
24

35
# This script generates HTTP response files (*.json) for .ps1 files in ./request-examples
46

inspectcode.ps1

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
#Requires -Version 7.0
1+
#Requires -Version 7.4
2+
$ErrorActionPreference = "Stop"
3+
$PSNativeCommandUseErrorActionPreference = $true
24

35
# This script runs code inspection and opens the results in a web browser.
46

57
dotnet tool restore
68

7-
if ($LastExitCode -ne 0) {
8-
throw "Tool restore failed with exit code $LastExitCode"
9-
}
10-
9+
$solutionFile = 'JsonApiDotNetCore.sln'
1110
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
1211
$resultPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.html')
13-
dotnet jb inspectcode --version
14-
dotnet jb inspectcode JsonApiDotNetCore.sln --dotnetcoresdk=$(dotnet --version) --build --output="$outputPath" --format="xml" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --properties:RunAnalyzers=false --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal
1512

16-
if ($LastExitCode -ne 0) {
17-
throw "Code inspection failed with exit code $LastExitCode"
18-
}
13+
dotnet jb inspectcode --version
14+
dotnet jb inspectcode $solutionFile --dotnetcoresdk=$(dotnet --version) --build --output="$outputPath" --format="xml" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --properties:RunAnalyzers=false --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal
1915

2016
[xml]$xml = Get-Content "$outputPath"
2117
if ($xml.report.Issues -and $xml.report.Issues.Project) {

run-docker-postgres.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# To connect to pgAdmin, open http://localhost:5050 and login with user "admin@admin.com", password "postgres". Use hostname "db" when registering the server.
66

77
param(
8-
[switch] $UI=$False
8+
[switch] $UI=$false
99
)
1010

1111
docker container stop jsonapi-postgresql-db

0 commit comments

Comments
 (0)