diff --git a/azure-pipelines-ext.cs b/azure-pipelines-ext.cs deleted file mode 100644 index 1e8142b09..000000000 --- a/azure-pipelines-ext.cs +++ /dev/null @@ -1,34 +0,0 @@ -// This file is used in the Azure Pipelines PowerShell scripts via: -// Add-Type -Path "azure-pipelines-ext.cs" - -// Note that this file is restricted to C# 5.0 - -using System; -using System.IO; -using System.Text; -using System.Security.Cryptography; -using System.Globalization; -using System.Net; -using System.IO.Compression; -using System.Collections.Generic; -using System.Text.RegularExpressions; -using System.Linq; -using System.Reflection; - -public class EverestPS { - - class ZipPathEncoder : UTF8Encoding { - public ZipPathEncoder() - : base(true) { - } - public override byte[] GetBytes(string s) { - return base.GetBytes(s.Replace("\\", "/")); - } - } - public static UTF8Encoding ZipPathEncoding = new ZipPathEncoder(); - - public static void Zip(string dir, string file) { - ZipFile.CreateFromDirectory(dir, file, CompressionLevel.Optimal, false, ZipPathEncoding); - } - -} diff --git a/azure-pipelines-postbuild.ps1 b/azure-pipelines-postbuild.ps1 index f08735c78..8f37ac3cf 100644 --- a/azure-pipelines-postbuild.ps1 +++ b/azure-pipelines-postbuild.ps1 @@ -1,7 +1,6 @@ Add-Type -AssemblyName System.IO.Compression.FileSystem -Add-Type -Path "azure-pipelines-ext.cs" -ReferencedAssemblies "System.IO.Compression.FileSystem" -$OLYMPUS="$env:Build_ArtifactStagingDirectory/olympus/" +$OLYMPUS="$env:BUILD_ARTIFACTSTAGINGDIRECTORY/olympus/" if ($OLYMPUS -eq "/olympus/") { $OLYMPUS = "./tmp-olympus/" } @@ -15,9 +14,46 @@ New-Item -ItemType "directory" -Path $OLYMPUS/meta New-Item -ItemType "directory" -Path $OLYMPUS/build Write-Output "Building Olympus build artifact" -# Azure Pipelines apparently hates to write to the artifact staging dir directly. -[EverestPS]::Zip("$env:Build_ArtifactStagingDirectory/main", "olympus-build.zip") -Move-Item -Path "olympus-build.zip" -Destination $ZIP +$compress = @{ + Path = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/main" + CompressionLevel = "Optimal" + DestinationPath = "$ZIP" +} +Compress-Archive @compress Write-Output "Building Olympus metadata artifact" Write-Output (Get-Item -Path $ZIP).length | Out-File -FilePath $OLYMPUS/meta/size.txt + +# lib-stripped setup +if ([string]::IsNullOrEmpty("$env:BIN_URL") -or ($env:BIN_URL -eq '$(BIN_URL)')) { + Write-Output "Skipping lib-stripped artifact" + Exit 0 +} + +$LIB_STRIPPED="$env:BUILD_ARTIFACTSTAGINGDIRECTORY/lib-stripped" +if ($LIB_STRIPPED -eq "/lib-stripped") { + $LIB_STRIPPED = "./tmp-lib-stripped" +} + +Write-Output "Creating lib-stripped artifact directories" +Remove-Item -ErrorAction Ignore -Recurse -Force -Path $LIB_STRIPPED +New-Item -ItemType "directory" -Path $LIB_STRIPPED +New-Item -ItemType "directory" -Path $LIB_STRIPPED/build + +Write-Output "Downloading Celeste package" +$creds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($env:BIN_USERNAME):$($env:BIN_PASSWORD)")) +$headers = @{'Authorization'= "Basic $creds"} +Invoke-WebRequest -URI "$env:BIN_URL/Celeste_Linux.zip" -OutFile "$env:AGENT_TEMPDIRECTORY/Celeste.zip" -Headers $headers +Expand-Archive -Path "$env:AGENT_TEMPDIRECTORY/Celeste.zip" -DestinationPath $LIB_STRIPPED + +Write-Output "Applying Everest patch" +Copy-Item -Path "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/main/*" -Destination $LIB_STRIPPED +Start-Process -FilePath "mono" -ArgumentList "$LIB_STRIPPED/MiniInstaller.exe" -WorkingDirectory $LIB_STRIPPED -Wait + +Write-Output "Generating stripped files" +$files = Get-ChildItem -Path "$LIB_STRIPPED/*" -Include *.dll,*.exe +foreach ($dll in $files) { + mono-cil-strip -q $dll +} +Copy-Item $files -Destination "$LIB_STRIPPED/build" +Write-Host "##vso[task.setvariable variable=lib_stripped]True" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f240e39e4..5a50922d6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -4,7 +4,7 @@ # https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net pool: - vmImage: 'windows-latest' + vmImage: 'ubuntu-latest' variables: solution: '**/*.sln' @@ -54,10 +54,15 @@ steps: # Post-build steps. - task: PowerShell@2 + name: PostBuild condition: succeeded() displayName: 'Run azure-pipelines-postbuild.ps1' inputs: filePath: 'azure-pipelines-postbuild.ps1' + env: + BIN_URL: $(BIN_URL) + BIN_USERNAME: $(BIN_USERNAME) + BIN_PASSWORD: $(BIN_PASSWORD) # Create and "publish" Olympus artifacts. - task: PublishBuildArtifacts@1 @@ -77,9 +82,19 @@ steps: artifactName: 'olympus-build' publishLocation: 'Container' +# Create and "publish" mono-cil-strip binary artifacts +- task: PublishBuildArtifacts@1 + condition: eq(variables['PostBuild.lib_stripped'], 'True') + displayName: 'Publish lib-stripped artifact' + continueOnError: true + inputs: + pathtoPublish: '$(Build.ArtifactStagingDirectory)/lib-stripped/build/' + artifactName: 'lib-stripped' + publishLocation: 'Container' + # Announce new stable versions on Discord (#modding_updates). - script: | - set /a "BUILD_NUMBER=$(Build.BuildId)+$(Build.BuildIdOffset)" - curl -H "Content-Type: application/json" -d "{\"content\": \"**A new Everest stable was just released!**\nThe latest stable version is now **%BUILD_NUMBER%**.\"}" $(WEBHOOK_URL) + declare -i BUILD_NUMBER=$(Build.BuildId)+$(Build.BuildIdOffset) + curl -H "Content-Type: application/json" -d "{\"content\": \"**A new Everest stable was just released!**\nThe latest stable version is now **$BUILD_NUMBER**.\"}" $(WEBHOOK_URL) displayName: 'Celeste Discord webhook' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/stable'))