From dd198355782d2786d9c0d98b7c3b9775e065156b Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Fri, 1 Jul 2022 16:46:14 -0600 Subject: [PATCH 1/7] - New Makefile with common commands - Split build.bat into multiple smaller Batch scripts (allow to be run individually or via make) - Fix compile tests in F# and VB unit tests --- EasyPost.Tests.FSharp/FSharpCompileTest.fs | 8 ++- EasyPost.Tests.VB/VbCompileTest.vb | 19 ++----- Makefile | 55 ++++++++++++++++++++ scripts/build_project.bat | 23 ++++++++ build.bat => scripts/build_release_nuget.bat | 41 ++++----------- scripts/delete_old_assemblies.bat | 9 ++++ scripts/install_cert.bat | 26 +++++++++ scripts/pack_nuget.bat | 19 +++++++ scripts/sign_dlls.bat | 28 ++++++++++ scripts/sign_nuget.bat | 28 ++++++++++ 10 files changed, 204 insertions(+), 52 deletions(-) create mode 100644 Makefile create mode 100644 scripts/build_project.bat rename build.bat => scripts/build_release_nuget.bat (52%) create mode 100644 scripts/delete_old_assemblies.bat create mode 100644 scripts/install_cert.bat create mode 100644 scripts/pack_nuget.bat create mode 100644 scripts/sign_dlls.bat create mode 100644 scripts/sign_nuget.bat diff --git a/EasyPost.Tests.FSharp/FSharpCompileTest.fs b/EasyPost.Tests.FSharp/FSharpCompileTest.fs index 9a76f303a..5d3c3c23e 100644 --- a/EasyPost.Tests.FSharp/FSharpCompileTest.fs +++ b/EasyPost.Tests.FSharp/FSharpCompileTest.fs @@ -3,14 +3,12 @@ namespace EasyPost.Tests.FSharp -open System -open EasyPost open Microsoft.VisualStudio.TestTools.UnitTesting [] -type FSharpCompileTest () = +type FSharpCompileTest() = [] member this.TestCompile() = + let address = new Address() // The assert doesn't really do anything, but as long as this test can run, then the code is compiling correctly. - let result = Assert.ThrowsException(fun() -> Console.Write(CarrierType.All()); new obj()) - Assert.IsNotNull(result) + Assert.IsNotNull(address) diff --git a/EasyPost.Tests.VB/VbCompileTest.vb b/EasyPost.Tests.VB/VbCompileTest.vb index 2f9db75f5..eb0dbf431 100644 --- a/EasyPost.Tests.VB/VbCompileTest.vb +++ b/EasyPost.Tests.VB/VbCompileTest.vb @@ -6,22 +6,9 @@ Imports Microsoft.VisualStudio.TestTools.UnitTesting Public Class VbCompileTest Public Sub TestCompile() - 'API key is not set, so calling CarrierType.All() will produce an error. But if this runs, then the code compiled properly. - Assert.ThrowsException(Of ClientNotConfigured)(Function() CarrierType.All()) - End Sub - - - Public Sub TestAddress() - Dim addressData As New Dictionary(Of String, Object)() - - addressData.Add("name", "John Smith") - addressData.Add("street1", "123 Main St") - addressData.Add("city", "San Francisco") - addressData.Add("state", "CA") - addressData.Add("zip", "94107") - addressData.Add("country", "US") + Dim address = New Address() - 'Without an API key, this will throw an error. But as long as it's a ClientNotConfigured exception, it's a success. - Assert.ThrowsException(Of ClientNotConfigured)(Function() Address.Create(addressData)) + 'Do not need to actually assert anything here. If it runs, it means it compiled successfully. + Assert.IsNotNull(address) End Sub End Class diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..09e74fdca --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +## help - Display help about make targets for this Makefile +help: + @cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t + +## release - Build, sign and package the project for distribution, signing with the provided certificate (Windows only) +# @parameters: +# cert= - The certificate to use for signing the built assets. +# pass= - The password for the certificate. +release: + scripts/build_release_nuget EasyPost ${cert} ${pass} EasyPost "Release" "Any CPU" + +## build-dev - Build the project in Debug mode +build-dev: + dotnet msbuild -property:Configuration="Debug" -property:Platform="Any CPU" -target:Rebuild -restore + +## build - Build the project in Release mode +build: + dotnet msbuild -property:Configuration="Release" -property:Platform="Any CPU" -target:Rebuild -restore + +## install-cert - Install the PFX certificate to your system (Windows only) +# @parameters: +# cert= - The certificate to use for signing the built assets. +# pass= - The password for the certificate. +install-cert: + scripts/install_cert ${cert} ${pass} + +## sign - Sign all generated DLLs and NuGet packages with the provided certificate (Windows only) +# @parameters: +# cert= - The certificate to use for signing the built assets. +# pass= - The password for the certificate. +sign: + install-cert ${cert} ${pass} + scripts/sign_assemblies ${cert} ${pass} EasyPost + +## clean - Clean the project +clean: + dotnet clean + +## restore - Restore the project +restore: + dotnet restore + +## lint - Lint the project +lint: + dotnet format + +## lint-check - Check lint issues in the project (does not make any changes) +lint-check: + dotnet format --verify-no-changes + +## test - Test the project +test: + dotnet test + +.PHONY: help release build-dev build install-cert sign clean restore lint lint-check test diff --git a/scripts/build_project.bat b/scripts/build_project.bat new file mode 100644 index 000000000..2a8233022 --- /dev/null +++ b/scripts/build_project.bat @@ -0,0 +1,23 @@ +:: This script will restore and build a .NET project in a specified mode and platform. + +:: Requirements: +:: - dotnet is installed on the machine and is accessible everywhere (added to PATH) (might be in C:\Program Files\dotnet) + +@ECHO OFF + +:: Parse command line arguments +SET buildMode=%1 +SET buildPlatform=%2 + +:: Restore dependencies and build solution +@ECHO: +@ECHO Restoring and building project... +dotnet msbuild -property:Configuration="%buildMode%" -property:Platform="%buildPlatform%" -target:Rebuild -restore || GOTO :commandFailed + +:commandFailed +@ECHO Command failed. +GOTO :exitWithError + +:exitWithError +@ECHO Exiting... +EXIT /B 1 diff --git a/build.bat b/scripts/build_release_nuget.bat similarity index 52% rename from build.bat rename to scripts/build_release_nuget.bat index 1d04836cd..4647e4fad 100644 --- a/build.bat +++ b/scripts/build_release_nuget.bat @@ -13,54 +13,33 @@ SET projectName=%1 SET certFile=%2 SET certPass=%3 - -:: Constants -SET containerName=EasyPost -SET buildMode="Release" -SET buildPlatform="Any CPU" +SET containerName=%4 +SET buildMode=%5 +SET buildPlatform=%6 :: Delete old files -@ECHO: -@ECHO Cleaning old files... -@RD /S /Q lib -DEL /S /Q /F *.nupkg +CALL delete_old_assemblies.bat :: Install certificate (needed to automate signing later on) -@ECHO: -@ECHO (Re-)Installing certificate to system... -sn -d "%containerName%" -SnInstallPfx "%certFile%" "%certPass%" "%containerName%" || GOTO :commandFailed +CALL install_cert.bat "%certFile%" "%certPass%" "%containerName%" :: Restore dependencies and build solution -@ECHO: -@ECHO Restoring and building project... -dotnet msbuild -property:Configuration="%buildMode%" -property:Platform="%buildPlatform" -target:Rebuild -restore || GOTO :commandFailed +CALL build_project.bat "%buildMode%" "%buildPlatform%" :: Sign the DLLs -@ECHO: -@ECHO Signing DLLs with certificate... -FOR /R lib %%F IN (*.dll) DO ( - REM We need to run the DLLs through both sn.exe and signtool to get complete the signing process - sn -Rca "%%F" "%containerName%" || GOTO :commandFailed - signtool sign /f "%certFile%" /p "%certPass%" /v /tr http://timestamp.digicert.com?alg=sha256 /td SHA256 /fd SHA256 "%%F" || GOTO :commandFailed -) +CALL sign_dlls.bat "%certFile%" "%certPass%" "%containerName%" :: Package the DLLs in a NuGet package (will fail if DLLs are missing) -@ECHO: -@ECHO Generating NuGet package... -nuget pack %projectName%.nuspec || GOTO :commandFailed +CALL pack_nuget.bat "%projectName%" :: Sign the NuGet package -@ECHO: -@ECHO Signing NuGet package with certificate... -:: Should only be one .nupkg file at this point, since we deleted the old ones +CALL sign_nuget.bat "%certFile%" "%certPass%" SET nugetFileName= FOR /R %%F IN (*.nupkg) DO ( SET nugetFileName="%%F" - nuget sign "%%F" -Timestamper http://timestamp.digicert.com -CertificatePath "%certFile%" -CertificatePassword "%certPass%" || GOTO :commandFailed ) IF [%nugetFileName%]==[] ( - ECHO Could not find NuGet package to sign. + ECHO Could not find NuGet package. GOTO :exitWithError ) diff --git a/scripts/delete_old_assemblies.bat b/scripts/delete_old_assemblies.bat new file mode 100644 index 000000000..7fec9654c --- /dev/null +++ b/scripts/delete_old_assemblies.bat @@ -0,0 +1,9 @@ +:: This script will delete any DLLs and NuGet packages + +@ECHO OFF + +:: Delete old files +@ECHO: +@ECHO Cleaning old files... +@RD /S /Q lib +DEL /S /Q /F *.nupkg diff --git a/scripts/install_cert.bat b/scripts/install_cert.bat new file mode 100644 index 000000000..8d86fecce --- /dev/null +++ b/scripts/install_cert.bat @@ -0,0 +1,26 @@ +:: This script will install a provided PFX certificate to the system. + +:: Requirements: +:: - dotnet is installed on the machine and is accessible everywhere (added to PATH) (might be in C:\Program Files\dotnet) +:: - SnInstallPfx (https://github.com/honzajscz/SnInstallPfx) is installed on the machine and is accessible everywhere (added to PATH) + +@ECHO OFF + +:: Parse command line arguments +SET certFile=%1 +SET certPass=%2 +SET containerName=%3 + +:: Install certificate +@ECHO: +@ECHO (Re-)Installing certificate to system... +sn -d "%containerName%" +SnInstallPfx "%certFile%" "%certPass%" "%containerName%" || GOTO :commandFailed + +:commandFailed +@ECHO Command failed. +GOTO :exitWithError + +:exitWithError +@ECHO Exiting... +EXIT /B 1 diff --git a/scripts/pack_nuget.bat b/scripts/pack_nuget.bat new file mode 100644 index 000000000..06687c14d --- /dev/null +++ b/scripts/pack_nuget.bat @@ -0,0 +1,19 @@ +:: This script will generate a NuGet package according the the project's .nuspec file. + +:: Requirements: +:: - NuGet is installed on the machine and is accessible everywhere (added to PATH) + +@ECHO OFF + +:: Generate a NuGet package (will fail if assemblies are missing) +@ECHO: +@ECHO Generating NuGet package... +nuget pack %projectName%.nuspec || GOTO :commandFailed + +:commandFailed +@ECHO Command failed. +GOTO :exitWithError + +:exitWithError +@ECHO Exiting... +EXIT /B 1 diff --git a/scripts/sign_dlls.bat b/scripts/sign_dlls.bat new file mode 100644 index 000000000..9f01cd119 --- /dev/null +++ b/scripts/sign_dlls.bat @@ -0,0 +1,28 @@ +:: This script will find and sign any DLLs with a provided PFX certificate + +:: Requirements: +:: - dotnet is installed on the machine and is accessible everywhere (added to PATH) (might be in C:\Program Files\dotnet) + +@ECHO OFF + +:: Parse command line arguments +SET certFile=%1 +SET certPass=%2 +SET containerName=%3 + +:: Sign all DLLs found in the lib folder +@ECHO: +@ECHO Signing DLLs with certificate... +FOR /R lib %%F IN (*.dll) DO ( + REM We need to run the DLLs through both sn.exe and signtool to get complete the signing process + sn -Rca "%%F" "%containerName%" || GOTO :commandFailed + signtool sign /f "%certFile%" /p "%certPass%" /v /tr http://timestamp.digicert.com?alg=sha256 /td SHA256 /fd SHA256 "%%F" || GOTO :commandFailed +) + +:commandFailed +@ECHO Command failed. +GOTO :exitWithError + +:exitWithError +@ECHO Exiting... +EXIT /B 1 diff --git a/scripts/sign_nuget.bat b/scripts/sign_nuget.bat new file mode 100644 index 000000000..d01c152f3 --- /dev/null +++ b/scripts/sign_nuget.bat @@ -0,0 +1,28 @@ +:: This script will find and sign any NuGet packages with a provided PFX certificate + +:: Requirements: +:: - NuGet is installed on the machine and is accessible everywhere (added to PATH) + +@ECHO OFF + +:: Parse command line arguments +SET certFile=%1 +SET certPass=%2 + +:: Sign all NuGet packages found +@ECHO: +@ECHO Signing NuGet package with certificate... +:: Should only be one .nupkg file at this point, since we deleted the old ones +SET nugetFileName= +FOR /R %%F IN (*.nupkg) DO ( + SET nugetFileName="%%F" + nuget sign "%%F" -Timestamper http://timestamp.digicert.com -CertificatePath "%certFile%" -CertificatePassword "%certPass%" || GOTO :commandFailed +) + +:commandFailed +@ECHO Command failed. +GOTO :exitWithError + +:exitWithError +@ECHO Exiting... +EXIT /B 1 From 0000db83f98255cfee3fbad618d894c004aaba6a Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Fri, 1 Jul 2022 16:58:15 -0600 Subject: [PATCH 2/7] - Fix F# imports --- EasyPost.Tests.FSharp/FSharpCompileTest.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/EasyPost.Tests.FSharp/FSharpCompileTest.fs b/EasyPost.Tests.FSharp/FSharpCompileTest.fs index 5d3c3c23e..93375b3e8 100644 --- a/EasyPost.Tests.FSharp/FSharpCompileTest.fs +++ b/EasyPost.Tests.FSharp/FSharpCompileTest.fs @@ -3,6 +3,7 @@ namespace EasyPost.Tests.FSharp +open EasyPost open Microsoft.VisualStudio.TestTools.UnitTesting [] From b356cce9b4cfcae18f92b111e4d9d024b43580f5 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 5 Jul 2022 12:44:39 -0600 Subject: [PATCH 3/7] - Adjust Makefile and scripts accounting for scripts path - Fix quotes for Windows --- Makefile | 12 ++++++------ scripts/build_project.bat | 4 ++-- scripts/build_release_nuget.bat | 15 +++++++-------- scripts/install_cert.bat | 4 ++-- scripts/sign_dlls.bat | 4 ++-- scripts/sign_nuget.bat | 5 ++++- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 09e74fdca..0dc476b10 100644 --- a/Makefile +++ b/Makefile @@ -7,30 +7,30 @@ help: # cert= - The certificate to use for signing the built assets. # pass= - The password for the certificate. release: - scripts/build_release_nuget EasyPost ${cert} ${pass} EasyPost "Release" "Any CPU" + scripts\build_release_nuget.bat EasyPost ${cert} ${pass} EasyPost Release ## build-dev - Build the project in Debug mode build-dev: - dotnet msbuild -property:Configuration="Debug" -property:Platform="Any CPU" -target:Rebuild -restore + dotnet msbuild -property:Configuration="Debug" -target:Rebuild -restore ## build - Build the project in Release mode build: - dotnet msbuild -property:Configuration="Release" -property:Platform="Any CPU" -target:Rebuild -restore + dotnet msbuild -property:Configuration="Release" -target:Rebuild -restore ## install-cert - Install the PFX certificate to your system (Windows only) # @parameters: # cert= - The certificate to use for signing the built assets. # pass= - The password for the certificate. install-cert: - scripts/install_cert ${cert} ${pass} + scripts\install_cert.bat ${cert} ${pass} ## sign - Sign all generated DLLs and NuGet packages with the provided certificate (Windows only) # @parameters: # cert= - The certificate to use for signing the built assets. # pass= - The password for the certificate. sign: - install-cert ${cert} ${pass} - scripts/sign_assemblies ${cert} ${pass} EasyPost + install-cert cert=${cert} pass=${pass} + scripts\sign_assemblies.bat ${cert} ${pass} EasyPost ## clean - Clean the project clean: diff --git a/scripts/build_project.bat b/scripts/build_project.bat index 2a8233022..5c2b228da 100644 --- a/scripts/build_project.bat +++ b/scripts/build_project.bat @@ -7,12 +7,12 @@ :: Parse command line arguments SET buildMode=%1 -SET buildPlatform=%2 :: Restore dependencies and build solution @ECHO: @ECHO Restoring and building project... -dotnet msbuild -property:Configuration="%buildMode%" -property:Platform="%buildPlatform%" -target:Rebuild -restore || GOTO :commandFailed +@ECHO %buildMode% +dotnet msbuild -property:Configuration="%buildMode%" -target:Rebuild -restore || GOTO :commandFailed :commandFailed @ECHO Command failed. diff --git a/scripts/build_release_nuget.bat b/scripts/build_release_nuget.bat index 4647e4fad..b787371f8 100644 --- a/scripts/build_release_nuget.bat +++ b/scripts/build_release_nuget.bat @@ -15,25 +15,24 @@ SET certFile=%2 SET certPass=%3 SET containerName=%4 SET buildMode=%5 -SET buildPlatform=%6 :: Delete old files -CALL delete_old_assemblies.bat +CALL scripts\delete_old_assemblies.bat :: Install certificate (needed to automate signing later on) -CALL install_cert.bat "%certFile%" "%certPass%" "%containerName%" +CALL scripts\install_cert.bat %certFile% %certPass% %containerName% || GOTO :commandFailed :: Restore dependencies and build solution -CALL build_project.bat "%buildMode%" "%buildPlatform%" +CALL scripts\build_project.bat %buildMode% || GOTO :commandFailed :: Sign the DLLs -CALL sign_dlls.bat "%certFile%" "%certPass%" "%containerName%" +CALL scripts\sign_dlls.bat %certFile% %certPass% %containerName% || GOTO :commandFailed :: Package the DLLs in a NuGet package (will fail if DLLs are missing) -CALL pack_nuget.bat "%projectName%" +CALL scripts\pack_nuget.bat %projectName% || GOTO :commandFailed :: Sign the NuGet package -CALL sign_nuget.bat "%certFile%" "%certPass%" +CALL scripts\sign_nuget.bat %certFile% %certPass% || GOTO :commandFailed SET nugetFileName= FOR /R %%F IN (*.nupkg) DO ( SET nugetFileName="%%F" @@ -56,7 +55,7 @@ GOTO :eof GOTO :exitWithError :commandFailed -@ECHO Command failed. +@ECHO Step failed. GOTO :exitWithError :exitWithError diff --git a/scripts/install_cert.bat b/scripts/install_cert.bat index 8d86fecce..8896db041 100644 --- a/scripts/install_cert.bat +++ b/scripts/install_cert.bat @@ -14,8 +14,8 @@ SET containerName=%3 :: Install certificate @ECHO: @ECHO (Re-)Installing certificate to system... -sn -d "%containerName%" -SnInstallPfx "%certFile%" "%certPass%" "%containerName%" || GOTO :commandFailed +sn -d %containerName% +SnInstallPfx %certFile% %certPass% %containerName% || GOTO :commandFailed :commandFailed @ECHO Command failed. diff --git a/scripts/sign_dlls.bat b/scripts/sign_dlls.bat index 9f01cd119..519d33222 100644 --- a/scripts/sign_dlls.bat +++ b/scripts/sign_dlls.bat @@ -15,8 +15,8 @@ SET containerName=%3 @ECHO Signing DLLs with certificate... FOR /R lib %%F IN (*.dll) DO ( REM We need to run the DLLs through both sn.exe and signtool to get complete the signing process - sn -Rca "%%F" "%containerName%" || GOTO :commandFailed - signtool sign /f "%certFile%" /p "%certPass%" /v /tr http://timestamp.digicert.com?alg=sha256 /td SHA256 /fd SHA256 "%%F" || GOTO :commandFailed + sn -Rca "%%F" %containerName% || GOTO :commandFailed + signtool sign /f %certFile% /p %certPass% /v /tr http://timestamp.digicert.com?alg=sha256 /td SHA256 /fd SHA256 "%%F" || GOTO :commandFailed ) :commandFailed diff --git a/scripts/sign_nuget.bat b/scripts/sign_nuget.bat index d01c152f3..3a71d6067 100644 --- a/scripts/sign_nuget.bat +++ b/scripts/sign_nuget.bat @@ -9,9 +9,12 @@ SET certFile=%1 SET certPass=%2 +@ECHO %certFile% +@ECHO %certPass% + :: Sign all NuGet packages found @ECHO: -@ECHO Signing NuGet package with certificate... +@ECHO Signing NuGet package with %certFile%... :: Should only be one .nupkg file at this point, since we deleted the old ones SET nugetFileName= FOR /R %%F IN (*.nupkg) DO ( From a9c820b2e5b7778793757e3a9011aa4539dfc7d7 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 5 Jul 2022 17:31:41 -0600 Subject: [PATCH 4/7] - Fix Batch scripts - Makefile step to check Batch scripts - Checking Batch scripts added as CI step (won't fail) --- .github/workflows/ci.yml | 7 +++++++ Makefile | 6 +++++- scripts/build_release_nuget.bat | 12 ++++++------ scripts/check_scripts.bat | 32 ++++++++++++++++++++++++++++++++ scripts/sign_dlls.bat | 2 +- 5 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 scripts/check_scripts.bat diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afdc9c68c..c3280210b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,13 @@ jobs: - uses: actions/checkout@v3 - name: Check dotnet Style run: dotnet-format --check --exclude / + Validate_Scripts: + runs-on: windows-2022 + steps: + - uses: actions/checkout@v3 + - name: Validate Batch scripts + run: make validate-batch + continue-on-error: true NET_Tests: # derived from https://dev.to/felipetofoli/github-actions-for-net-full-framework-build-and-test-299h runs-on: windows-2022 diff --git a/Makefile b/Makefile index 0dc476b10..71dec2a1e 100644 --- a/Makefile +++ b/Makefile @@ -52,4 +52,8 @@ lint-check: test: dotnet test -.PHONY: help release build-dev build install-cert sign clean restore lint lint-check test +## validate-batch - Validate the Batch scripts (Windows only) +validate-batch: + scripts\check_scripts.bat + +.PHONY: help release build-dev build install-cert sign clean restore lint lint-check test validate-batch diff --git a/scripts/build_release_nuget.bat b/scripts/build_release_nuget.bat index b787371f8..6405d40cc 100644 --- a/scripts/build_release_nuget.bat +++ b/scripts/build_release_nuget.bat @@ -17,22 +17,22 @@ SET containerName=%4 SET buildMode=%5 :: Delete old files -CALL scripts\delete_old_assemblies.bat +CALL "scripts\delete_old_assemblies.bat" :: Install certificate (needed to automate signing later on) -CALL scripts\install_cert.bat %certFile% %certPass% %containerName% || GOTO :commandFailed +CALL "scripts\install_cert.bat" %certFile% %certPass% %containerName% || GOTO :commandFailed :: Restore dependencies and build solution -CALL scripts\build_project.bat %buildMode% || GOTO :commandFailed +CALL "scripts\build_project.bat" %buildMode% || GOTO :commandFailed :: Sign the DLLs -CALL scripts\sign_dlls.bat %certFile% %certPass% %containerName% || GOTO :commandFailed +CALL "scripts\sign_dlls.bat" %certFile% %certPass% %containerName% || GOTO :commandFailed :: Package the DLLs in a NuGet package (will fail if DLLs are missing) -CALL scripts\pack_nuget.bat %projectName% || GOTO :commandFailed +CALL "scripts\pack_nuget.bat" %projectName% || GOTO :commandFailed :: Sign the NuGet package -CALL scripts\sign_nuget.bat %certFile% %certPass% || GOTO :commandFailed +CALL "scripts\sign_nuget.bat" %certFile% %certPass% || GOTO :commandFailed SET nugetFileName= FOR /R %%F IN (*.nupkg) DO ( SET nugetFileName="%%F" diff --git a/scripts/check_scripts.bat b/scripts/check_scripts.bat new file mode 100644 index 000000000..7c854c14c --- /dev/null +++ b/scripts/check_scripts.bat @@ -0,0 +1,32 @@ +:: This script will install BatCodeCheck and run analysis on all Batch scripts in the "scripts" folder + + +:: Requirements: +:: - Chocolatey is installed on the machine and is accessible everywhere (added to PATH) +:: - 7Zip is installed on the machine and is accessible everywhere (added to PATH) +:: - Might need to run with elevated privileges + +@ECHO OFF + +:: Download BatCodeCheck +curl https://www.robvanderwoude.com/files/batcodecheck.zip --output batcodecheck.zip || GOTO :commandFailed + +:: Unzip BatCodeCheck +7z x batcodecheck.zip -y || GOTO :commandFailed + +:: Analyze all Batch files found in the scripts folder +:: May complain about double-%, this is fine +:: However, don't want to falsely throw an error, so this does not fail on error +@ECHO: +@ECHO Verifying Batch files... +FOR /R scripts %%F IN (*.bat) DO ( + BatCodeCheck.exe "%%F" /L /W +) + +:commandFailed +@ECHO Command failed. +GOTO :exitWithError + +:exitWithError +@ECHO Exiting... +EXIT /B 1 diff --git a/scripts/sign_dlls.bat b/scripts/sign_dlls.bat index 519d33222..86e13d8b0 100644 --- a/scripts/sign_dlls.bat +++ b/scripts/sign_dlls.bat @@ -13,7 +13,7 @@ SET containerName=%3 :: Sign all DLLs found in the lib folder @ECHO: @ECHO Signing DLLs with certificate... -FOR /R lib %%F IN (*.dll) DO ( +FOR /R "lib" %%F IN (*.dll) DO ( REM We need to run the DLLs through both sn.exe and signtool to get complete the signing process sn -Rca "%%F" %containerName% || GOTO :commandFailed signtool sign /f %certFile% /p %certPass% /v /tr http://timestamp.digicert.com?alg=sha256 /td SHA256 /fd SHA256 "%%F" || GOTO :commandFailed From 9f4da444a8a9d2d4b26ddc1bde40d2d667bcebf4 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 5 Jul 2022 17:34:22 -0600 Subject: [PATCH 5/7] - Fix script to check scripts --- scripts/check_scripts.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_scripts.bat b/scripts/check_scripts.bat index 7c854c14c..bac670752 100644 --- a/scripts/check_scripts.bat +++ b/scripts/check_scripts.bat @@ -20,7 +20,7 @@ curl https://www.robvanderwoude.com/files/batcodecheck.zip --output batcodecheck @ECHO: @ECHO Verifying Batch files... FOR /R scripts %%F IN (*.bat) DO ( - BatCodeCheck.exe "%%F" /L /W + BatCodeCheck.exe "%%F" /LS ) :commandFailed From 0abd79c6765e57eb06693dd976ace333bdb6dbdd Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Tue, 5 Jul 2022 17:58:50 -0600 Subject: [PATCH 6/7] - Remove CI step (BatCodeCheck can't run in a headless machine) - Makefile step still exists for manual run --- .github/workflows/ci.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3280210b..afdc9c68c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,13 +14,6 @@ jobs: - uses: actions/checkout@v3 - name: Check dotnet Style run: dotnet-format --check --exclude / - Validate_Scripts: - runs-on: windows-2022 - steps: - - uses: actions/checkout@v3 - - name: Validate Batch scripts - run: make validate-batch - continue-on-error: true NET_Tests: # derived from https://dev.to/felipetofoli/github-actions-for-net-full-framework-build-and-test-299h runs-on: windows-2022 From 0f6876dc696c373faa047a234f325ca2c32c9fc6 Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Wed, 6 Jul 2022 11:09:11 -0600 Subject: [PATCH 7/7] - Address feedback --- Makefile | 8 ++++---- scripts/{check_scripts.bat => lint_scripts.bat} | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) rename scripts/{check_scripts.bat => lint_scripts.bat} (90%) diff --git a/Makefile b/Makefile index 71dec2a1e..5ce70cfbf 100644 --- a/Makefile +++ b/Makefile @@ -52,8 +52,8 @@ lint-check: test: dotnet test -## validate-batch - Validate the Batch scripts (Windows only) -validate-batch: - scripts\check_scripts.bat +## lint-scripts - Lint and validate the Batch scripts (Windows only) +lint-scripts: + scripts\lint_scripts.bat -.PHONY: help release build-dev build install-cert sign clean restore lint lint-check test validate-batch +.PHONY: help release build-dev build install-cert sign clean restore lint lint-check test lint-scripts diff --git a/scripts/check_scripts.bat b/scripts/lint_scripts.bat similarity index 90% rename from scripts/check_scripts.bat rename to scripts/lint_scripts.bat index bac670752..ecd901e46 100644 --- a/scripts/check_scripts.bat +++ b/scripts/lint_scripts.bat @@ -2,7 +2,6 @@ :: Requirements: -:: - Chocolatey is installed on the machine and is accessible everywhere (added to PATH) :: - 7Zip is installed on the machine and is accessible everywhere (added to PATH) :: - Might need to run with elevated privileges