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
7 changes: 3 additions & 4 deletions EasyPost.Tests.FSharp/FSharpCompileTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

namespace EasyPost.Tests.FSharp

open System
open EasyPost
open Microsoft.VisualStudio.TestTools.UnitTesting

[<TestClass>]
type FSharpCompileTest () =
type FSharpCompileTest() =
[<TestMethod>]
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<ClientNotConfigured>(fun() -> Console.Write(CarrierType.All()); new obj())
Assert.IsNotNull(result)
Assert.IsNotNull(address)
19 changes: 3 additions & 16 deletions EasyPost.Tests.VB/VbCompileTest.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,9 @@ Imports Microsoft.VisualStudio.TestTools.UnitTesting
Public Class VbCompileTest
<TestMethod>
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

<TestMethod>
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
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## 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.bat EasyPost ${cert} ${pass} EasyPost Release

## build-dev - Build the project in Debug mode
build-dev:
dotnet msbuild -property:Configuration="Debug" -target:Rebuild -restore

## build - Build the project in Release mode
build:
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.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=${cert} pass=${pass}
scripts\sign_assemblies.bat ${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

## 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 lint-scripts
23 changes: 23 additions & 0 deletions scripts/build_project.bat
Original file line number Diff line number Diff line change
@@ -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

:: Restore dependencies and build solution
@ECHO:
@ECHO Restoring and building project...
@ECHO %buildMode%
dotnet msbuild -property:Configuration="%buildMode%" -target:Rebuild -restore || GOTO :commandFailed

:commandFailed
@ECHO Command failed.
GOTO :exitWithError

:exitWithError
@ECHO Exiting...
EXIT /B 1
42 changes: 10 additions & 32 deletions build.bat → scripts/build_release_nuget.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,32 @@
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

:: Delete old files
@ECHO:
@ECHO Cleaning old files...
@RD /S /Q lib
DEL /S /Q /F *.nupkg
CALL "scripts\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 "scripts\install_cert.bat" %certFile% %certPass% %containerName% || GOTO :commandFailed

:: 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 "scripts\build_project.bat" %buildMode% || GOTO :commandFailed

:: 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 "scripts\sign_dlls.bat" %certFile% %certPass% %containerName% || GOTO :commandFailed

:: 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 "scripts\pack_nuget.bat" %projectName% || GOTO :commandFailed

:: 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 "scripts\sign_nuget.bat" %certFile% %certPass% || GOTO :commandFailed
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
)

Expand All @@ -77,7 +55,7 @@ GOTO :eof
GOTO :exitWithError

:commandFailed
@ECHO Command failed.
@ECHO Step failed.
GOTO :exitWithError

:exitWithError
Expand Down
9 changes: 9 additions & 0 deletions scripts/delete_old_assemblies.bat
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions scripts/install_cert.bat
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions scripts/lint_scripts.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
:: This script will install BatCodeCheck and run analysis on all Batch scripts in the "scripts" folder


:: Requirements:
:: - 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" /LS
)

:commandFailed
@ECHO Command failed.
GOTO :exitWithError

:exitWithError
@ECHO Exiting...
EXIT /B 1
19 changes: 19 additions & 0 deletions scripts/pack_nuget.bat
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions scripts/sign_dlls.bat
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions scripts/sign_nuget.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
:: 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

@ECHO %certFile%
@ECHO %certPass%

:: Sign all NuGet packages found
@ECHO:
@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 (
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