From ed3e58af6c55f7fb7227cb1b7040cd376f257170 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 26 Jun 2024 11:32:20 -0400 Subject: [PATCH] Update publishing to cooler version --- Test/Test.csproj | 15 ++++++- publish-nix.sh | 115 ++++++++++++++++++++++++++++++----------------- publish-win.ps1 | 98 ++++++++++++++++++++++++---------------- 3 files changed, 149 insertions(+), 79 deletions(-) diff --git a/Test/Test.csproj b/Test/Test.csproj index ca51e921..50bb4688 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -2,7 +2,6 @@ net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 - win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 Exe false false @@ -11,6 +10,20 @@ true true + + + + win-x86;win-x64 + + + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 + + + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 + + + net6.0;net7.0;net8.0 + diff --git a/publish-nix.sh b/publish-nix.sh index cc524235..3b94aab1 100644 --- a/publish-nix.sh +++ b/publish-nix.sh @@ -12,9 +12,8 @@ USE_ALL=false NO_BUILD=false NO_ARCHIVE=false -while getopts "uba" OPTION -do - case $OPTION in +while getopts "uba" OPTION; do + case $OPTION in u) USE_ALL=true ;; @@ -35,29 +34,34 @@ done BUILD_FOLDER=$PWD # Set the current commit hash -COMMIT=`git log --pretty=%H -1` +COMMIT=$(git log --pretty=%H -1) + +# Output the selected options +echo "Selected Options:" +echo " Use all frameworks (-u) $USE_ALL" +echo " No build (-b) $NO_BUILD" +echo " No archive (-a) $NO_ARCHIVE" +echo " " # Create the build matrix arrays FRAMEWORKS=("net8.0") -RUNTIMES=("win-x86" "win-x64" "linux-x64" "osx-x64") +RUNTIMES=("win-x86" "win-x64" "win-arm64" "linux-x64" "linux-arm64" "osx-x64" "osx-arm64") # Use expanded lists, if requested -if [ $USE_ALL = true ] -then +if [ $USE_ALL = true ]; then FRAMEWORKS=("net20" "net35" "net40" "net452" "net462" "net472" "net48" "netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0") - RUNTIMES=("win-x86" "win-x64" "win-arm64" "linux-x64" "linux-arm64" "osx-x64") fi # Create the filter arrays SINGLE_FILE_CAPABLE=("net5.0" "net6.0" "net7.0" "net8.0") +VALID_APPLE_FRAMEWORKS=("net6.0" "net7.0" "net8.0") VALID_CROSS_PLATFORM_FRAMEWORKS=("netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0") VALID_CROSS_PLATFORM_RUNTIMES=("win-arm64" "linux-x64" "linux-arm64" "osx-x64") NON_DLL_FRAMEWORKS=("net20" "net35" "net40") -NON_DLL_RUNTIMES=("win-x64" "win-arm64" "linux-x64" "linux-arm64" "osx-x64") +NON_DLL_RUNTIMES=("win-x64" "win-arm64" "linux-x64" "linux-arm64" "osx-x64" "osx-arm64") # Only build if requested -if [ $NO_BUILD = false ] -then +if [ $NO_BUILD = false ]; then # Restore Nuget packages for all builds echo "Restoring Nuget packages" dotnet restore @@ -66,23 +70,39 @@ then dotnet pack BinaryObjectScanner/BinaryObjectScanner.csproj --output $BUILD_FOLDER # Build Test - for FRAMEWORK in "${FRAMEWORKS[@]}" - do - for RUNTIME in "${RUNTIMES[@]}" - do + for FRAMEWORK in "${FRAMEWORKS[@]}"; do + for RUNTIME in "${RUNTIMES[@]}"; do + # Output the current build + echo "===== Build Test - $FRAMEWORK, $RUNTIME =====" + # If we have an invalid combination of framework and runtime - if [ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ] && [ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ] - then - continue + if [[ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then + if [[ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then + echo "Skipped due to invalid combination" + continue + fi + fi + + # If we have Apple silicon but an unsupported framework + if [[ ! $(echo ${VALID_APPLE_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then + if [ $RUNTIME = "osx-arm64" ]; then + echo "Skipped due to no Apple Silicon support" + continue + fi fi # Only .NET 5 and above can publish to a single file - if [[ $(echo ${SINGLE_FILE_CAPABLE[@]} | fgrep -w $FRAMEWORK) ]] - then - dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true + if [[ $(echo ${SINGLE_FILE_CAPABLE[@]} | fgrep -w $FRAMEWORK) ]]; then + # Only include Debug if building all + if [ $USE_ALL = true ]; then + dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true + fi dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false else - dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT + # Only include Debug if building all + if [ $USE_ALL = true ]; then + dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT + fi dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false fi done @@ -90,29 +110,44 @@ then fi # Only create archives if requested -if [ $NO_ARCHIVE = false ] -then +if [ $NO_ARCHIVE = false ]; then # Create Test archives - for FRAMEWORK in "${FRAMEWORKS[@]}" - do - for RUNTIME in "${RUNTIMES[@]}" - do + for FRAMEWORK in "${FRAMEWORKS[@]}"; do + for RUNTIME in "${RUNTIMES[@]}"; do + # Output the current build + echo "===== Archive Test - $FRAMEWORK, $RUNTIME =====" + # If we have an invalid combination of framework and runtime - if [ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ] && [ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ] - then - continue + if [[ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then + if [[ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then + echo "Skipped due to invalid combination" + continue + fi fi - cd $BUILD_FOLDER/Test/bin/Debug/${FRAMEWORK}/${RUNTIME}/publish/ - if [ $(echo ${NON_DLL_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ] || [ $(echo ${NON_DLL_RUNTIMES[@]} | fgrep -w $RUNTIME) ] - then - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' - else - zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . + # If we have Apple silicon but an unsupported framework + if [[ ! $(echo ${VALID_APPLE_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then + if [ $RUNTIME = "osx-arm64" ]; then + echo "Skipped due to no Apple Silicon support" + continue + fi + fi + + # Only include Debug if building all + if [ $USE_ALL = true ]; then + cd $BUILD_FOLDER/Test/bin/Debug/${FRAMEWORK}/${RUNTIME}/publish/ + if [[ $(echo ${NON_DLL_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then + zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' + elif [[ $(echo ${NON_DLL_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then + zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' + else + zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip . + fi fi cd $BUILD_FOLDER/Test/bin/Release/${FRAMEWORK}/${RUNTIME}/publish/ - if [ $(echo ${NON_DLL_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ] || [ $(echo ${NON_DLL_RUNTIMES[@]} | fgrep -w $RUNTIME) ] - then + if [[ $(echo ${NON_DLL_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then + zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' + elif [[ $(echo ${NON_DLL_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip . -x 'CascLib.dll' -x 'mspack.dll' -x 'StormLib.dll' else zip -r $BUILD_FOLDER/BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip . @@ -122,4 +157,4 @@ then # Reset the directory cd $BUILD_FOLDER -fi \ No newline at end of file +fi diff --git a/publish-win.ps1 b/publish-win.ps1 index a66531e8..9da9d537 100644 --- a/publish-win.ps1 +++ b/publish-win.ps1 @@ -27,27 +27,32 @@ $BUILD_FOLDER = $PSScriptRoot # Set the current commit hash $COMMIT = git log --pretty=format:"%H" -1 +# Output the selected options +Write-Host "Selected Options:" +Write-Host " Use all frameworks (-UseAll) $USE_ALL" +Write-Host " No build (-NoBuild) $NO_BUILD" +Write-Host " No archive (-NoArchive) $NO_ARCHIVE" +Write-Host " " + # Create the build matrix arrays $FRAMEWORKS = @('net8.0') -$RUNTIMES = @('win-x86', 'win-x64', 'linux-x64', 'osx-x64') +$RUNTIMES = @('win-x86', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64') # Use expanded lists, if requested -if ($USE_ALL.IsPresent) -{ +if ($USE_ALL.IsPresent) { $FRAMEWORKS = @('net20', 'net35', 'net40', 'net452', 'net462', 'net472', 'net48', 'netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0') - $RUNTIMES = @('win-x86', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64') } # Create the filter arrays $SINGLE_FILE_CAPABLE = @('net5.0', 'net6.0', 'net7.0', 'net8.0') +$VALID_APPLE_FRAMEWORKS = @('net6.0', 'net7.0', 'net8.0') $VALID_CROSS_PLATFORM_FRAMEWORKS = @('netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0') $VALID_CROSS_PLATFORM_RUNTIMES = @('win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64') $NON_DLL_FRAMEWORKS = @('net20', 'net35', 'net40') -$NON_DLL_RUNTIMES = @('win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64') +$NON_DLL_RUNTIMES = @('win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64') # Only build if requested -if (!$NO_BUILD.IsPresent) -{ +if (!$NO_BUILD.IsPresent) { # Restore Nuget packages for all builds Write-Host "Restoring Nuget packages" dotnet restore @@ -56,25 +61,36 @@ if (!$NO_BUILD.IsPresent) dotnet pack BinaryObjectScanner\BinaryObjectScanner.csproj --output $BUILD_FOLDER # Build Test - foreach ($FRAMEWORK in $FRAMEWORKS) - { - foreach ($RUNTIME in $RUNTIMES) - { + foreach ($FRAMEWORK in $FRAMEWORKS) { + foreach ($RUNTIME in $RUNTIMES) { + # Output the current build + Write-Host "===== Build Test - $FRAMEWORK, $RUNTIME =====" + # If we have an invalid combination of framework and runtime - if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) - { + if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) { + Write-Host "Skipped due to invalid combination" + continue + } + + # If we have Apple silicon but an unsupported framework + if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') { + Write-Host "Skipped due to no Apple Silicon support" continue } # Only .NET 5 and above can publish to a single file - if ($SINGLE_FILE_CAPABLE -contains $FRAMEWORK) - { - dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true + if ($SINGLE_FILE_CAPABLE -contains $FRAMEWORK) { + # Only include Debug if building all + if ($USE_ALL.IsPresent) { + dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true + } dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false } - else - { - dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT + else { + # Only include Debug if building all + if ($USE_ALL.IsPresent) { + dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT + } dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false } } @@ -82,35 +98,41 @@ if (!$NO_BUILD.IsPresent) } # Only create archives if requested -if (!$NO_ARCHIVE.IsPresent) -{ +if (!$NO_ARCHIVE.IsPresent) { # Create Test archives - foreach ($FRAMEWORK in $FRAMEWORKS) - { - foreach ($RUNTIME in $RUNTIMES) - { + foreach ($FRAMEWORK in $FRAMEWORKS) { + foreach ($RUNTIME in $RUNTIMES) { + # Output the current build + Write-Host "===== Archive Test - $FRAMEWORK, $RUNTIME =====" + # If we have an invalid combination of framework and runtime - if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) - { + if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) { + Write-Host "Skipped due to invalid combination" continue } - Set-Location -Path $BUILD_FOLDER\Test\bin\Debug\${FRAMEWORK}\${RUNTIME}\publish\ - if ($NON_DLL_FRAMEWORKS -contains $FRAMEWORK -or $NON_DLL_RUNTIMES -contains $RUNTIME) - { - 7z a -tzip -x'!CascLib.dll' -x'!mspack.dll' -x'!StormLib.dll' $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip * + # If we have Apple silicon but an unsupported framework + if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') { + Write-Host "Skipped due to no Apple Silicon support" + continue } - else - { - 7z a -tzip $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip * + + # Only include Debug if building all + if ($USE_ALL.IsPresent) { + Set-Location -Path $BUILD_FOLDER\Test\bin\Debug\${FRAMEWORK}\${RUNTIME}\publish\ + if ($NON_DLL_FRAMEWORKS -contains $FRAMEWORK -or $NON_DLL_RUNTIMES -contains $RUNTIME) { + 7z a -tzip -x'!CascLib.dll' -x'!mspack.dll' -x'!StormLib.dll' $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip * + } + else { + 7z a -tzip $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_debug.zip * + } } + Set-Location -Path $BUILD_FOLDER\Test\bin\Release\${FRAMEWORK}\${RUNTIME}\publish\ - if ($NON_DLL_FRAMEWORKS -contains $FRAMEWORK -or $NON_DLL_RUNTIMES -contains $RUNTIME) - { + if ($NON_DLL_FRAMEWORKS -contains $FRAMEWORK -or $NON_DLL_RUNTIMES -contains $RUNTIME) { 7z a -tzip -x'!CascLib.dll' -x'!mspack.dll' -x'!StormLib.dll' $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip * } - else - { + else { 7z a -tzip $BUILD_FOLDER\BinaryObjectScanner_${FRAMEWORK}_${RUNTIME}_release.zip * } }