diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 985db7b3f..a891a2892 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -90,10 +90,6 @@ stages: artifactName: WinVS2017x64Binaries targetPath: WinVS2017x64Binaries displayName: Download WinVS2017x64Binaries - - powershell: | - .\extra\chocolatey\generatePackage.ps1 $(NEKO_VERSION) - Get-ChildItem extra\chocolatey\out - displayName: Prepare Chocolatey Package - powershell: | $commitSha = git rev-parse --short HEAD $commitTime = git show -s --format=%cI HEAD @@ -102,9 +98,8 @@ stages: $chocoVersion = If ($sourceBranch.StartsWith('refs/tags/v')) {'$(NEKO_VERSION)'} Else {"$(NEKO_VERSION)-SNAP$commitTime"} echo "##vso[task.setvariable variable=chocoVersion]$chocoVersion" displayName: Format package version string - - powershell: choco pack --version $env:chocoVersion -Out ..\pack - workingDirectory: extra/chocolatey/out/ - displayName: choco pack + - powershell: .\extra\chocolatey\Build-Package.ps1 -Version $(NEKO_VERSION) -LongVersion $env:chocoVersion + displayName: Create chocolatey package - task: PublishPipelineArtifact@0 inputs: artifactName: Chocolatey diff --git a/extra/chocolatey/.gitignore b/extra/chocolatey/.gitignore new file mode 100644 index 000000000..f71923efd --- /dev/null +++ b/extra/chocolatey/.gitignore @@ -0,0 +1,2 @@ +neko +pack diff --git a/extra/chocolatey/Build-Package.ps1 b/extra/chocolatey/Build-Package.ps1 new file mode 100644 index 000000000..a834e45fa --- /dev/null +++ b/extra/chocolatey/Build-Package.ps1 @@ -0,0 +1,43 @@ +param ([string] $version, [string] $longVersion) +$ErrorActionPreference = "Stop" + +If ( $version -eq "" ) { + Write-Error "No version parameter was passed in." + Exit 1 +} +If ( $longVersion -eq "" ) { + Write-Error "No longVersion parameter was passed in." + Exit 1 +} + +$DIR = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" + +# Create chocolatey template + +$TEMPLATE_DIR = "$env:ChocolateyInstall\templates\neko-template" + +If ( Test-Path -Path $TEMPLATE_DIR) { + Get-ChildItem -Path $TEMPLATE_DIR -File | foreach { $_.Delete()} +} Else { + New-Item -Path $TEMPLATE_DIR -ItemType "directory" -Force > $null +} + +Copy-Item -Path $DIR\* -Recurse -Include neko.nuspec,tools -Destination $TEMPLATE_DIR -Force +Copy-Item .\LICENSE $TEMPLATE_DIR\tools\LICENSE + +# Create package contents from template + +$file32 = ".\WinVS2017Binaries\neko-$version-win.zip" +$file64 = ".\WinVS2017x64Binaries\neko-$version-win64.zip" + +$checksum32 = (Get-FileHash $file32).Hash.ToLower() +$checksum64 = (Get-FileHash $file64).Hash.ToLower() + +choco new neko -t neko-template --version $longVersion --out $DIR --force Checksum32=$checksum32 Checksum64=$checksum64 ShortVersion=$version +Copy-Item -Path $file32,$file64 -Destination $DIR\neko + +# Package everything + +$OUTPUT = "$DIR\pack" +New-Item -Path $OUTPUT -ItemType "directory" -Force > $null +choco pack --version $longVersion $DIR\neko\neko.nuspec -Out $OUTPUT diff --git a/extra/chocolatey/chocolateyInstall.ps1.template b/extra/chocolatey/chocolateyInstall.ps1.template deleted file mode 100644 index 860515457..000000000 --- a/extra/chocolatey/chocolateyInstall.ps1.template +++ /dev/null @@ -1,24 +0,0 @@ -$packDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" - -Install-ChocolateyZipPackage ` - -PackageName 'neko' ` - -UnzipLocation "$packDir" ` - -Url "$packDir\neko-*-win.zip" ` - -Checksum '::CHECKSUM32::' ` - -ChecksumType 'sha256' ` - -Url64bit "$packDir\neko-*-win64.zip" ` - -Checksum64 '::CHECKSUM64::' ` - -ChecksumType64 'sha256' - -$nekoDir = "$(Get-Item "$packDir/neko-*-win*" -Exclude "*.zip")" - -# Install the dll files to C:\ProgramData\chocolatey\bin -# It is because they are loaded by other neko binaries, e.g. haxelib.exe -$chocoBin = Join-Path $env:ChocolateyInstall 'bin' -$dllFiles = @('gcmt-dll.dll', 'neko.dll') -foreach ($file in $dllFiles) { - Copy-Item "$nekoDir/$file" "$chocoBin" -} - -# Set NEKOPATH such that the ndll files can be loaded. -Install-ChocolateyEnvironmentVariable -VariableName NEKOPATH -VariableValue $nekoDir diff --git a/extra/chocolatey/generatePackage.ps1 b/extra/chocolatey/generatePackage.ps1 deleted file mode 100644 index dab8a6e5a..000000000 --- a/extra/chocolatey/generatePackage.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -param ([string] $version) -$ErrorActionPreference = "Stop" - -$SOURCE = ".\extra\chocolatey" -$OUTPUT = "$SOURCE\out" - -If ( $version -eq "" ) { - Write-Error "No version parameter was passed in." - Exit 1 -} - -# Create empty -If ( Test-Path -Path $OUTPUT) { - Get-ChildItem -Path $OUTPUT -File | foreach { $_.Delete()} -} Else { - New-Item -Path $OUTPUT -ItemType "directory" -Force > $null -} - -Function Copy-File { - param ([string] $file) - Write-Host "Copying $file" - Copy-Item $file $OUTPUT -} - -# Copy over zipped up binaries - -$file32 = "neko-$version-win.zip" -$file64 = "neko-$version-win64.zip" - -ForEach ($file in @(".\WinVS2017Binaries\$file32", ".\WinVS2017x64Binaries\$file64")) { - If ( ! (Test-Path -Path $file -PathType Leaf) ) { - Write-Error "File $file missing" - Exit 2 - } - Copy-File $file -} - -# Generate install script -Write-Host "Generating install script" - -# Load template -$template = (Get-Content -Path "$source\chocolateyInstall.ps1.template" -Raw) - -# Get checksums -$checksum32 = (Get-FileHash $OUTPUT\$file32).Hash.ToLower() -$checksum64 = (Get-FileHash $OUTPUT\$file64).Hash.ToLower() - -# Generate install script with correct checksums -$installScript = $template -Replace '::CHECKSUM32::',$checksum32 -Replace '::CHECKSUM64::',$checksum64 - -Out-File -FilePath "$OUTPUT\chocolateyInstall.ps1" -InputObject $installScript -NoNewline - -# Copy over general files -$toCopy = @(".\LICENSE", "$SOURCE\VERIFICATION.txt", "$SOURCE\neko.nuspec","$SOURCE\chocolateyUninstall.ps1") - -ForEach ($item in $toCopy) { - Copy-File $item -} diff --git a/extra/chocolatey/neko.nuspec b/extra/chocolatey/neko.nuspec index a5b30865e..62a861a6a 100644 --- a/extra/chocolatey/neko.nuspec +++ b/extra/chocolatey/neko.nuspec @@ -2,7 +2,7 @@ neko - 0.0.0 + [[PackageVersion]] Neko Haxe Foundation Haxe Foundation @@ -23,4 +23,9 @@ + + + + + diff --git a/extra/chocolatey/VERIFICATION.txt b/extra/chocolatey/tools/VERIFICATION.txt similarity index 66% rename from extra/chocolatey/VERIFICATION.txt rename to extra/chocolatey/tools/VERIFICATION.txt index 140b6dc8b..9c298130a 100644 --- a/extra/chocolatey/VERIFICATION.txt +++ b/extra/chocolatey/tools/VERIFICATION.txt @@ -1,3 +1,3 @@ Packager (Andy Li) is a member of the Haxe Foundation. - -The files included in this package are the "Windows Binaries" available at https://github.com/HaxeFoundation/neko/releases. \ No newline at end of file + +The files included in this package are the "Windows Binaries" available at https://github.com/HaxeFoundation/neko/releases. diff --git a/extra/chocolatey/tools/chocolateyInstall.ps1 b/extra/chocolatey/tools/chocolateyInstall.ps1 new file mode 100644 index 000000000..ff143cbdf --- /dev/null +++ b/extra/chocolatey/tools/chocolateyInstall.ps1 @@ -0,0 +1,31 @@ +$ErrorActionPreference = "Stop" +# set variables +$shortVersion = '[[ShortVersion]]' + +$packDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition | Split-Path -Parent)" + +$packageArgs = @{ + PackageName = 'neko' + UnzipLocation = "$packDir" + Url = "$packDir\neko-$shortVersion-win.zip" + Checksum = '[[Checksum32]]' + ChecksumType = 'sha256' + Url64bit = "$packDir\neko-$shortVersion-win64.zip" + Checksum64 = '[[Checksum64]]' + ChecksumType64 = 'sha256' +} + +Install-ChocolateyZipPackage @packageArgs + +$nekoDir = "$(Get-Item "$packDir/neko-$shortVersion-win*" -Exclude "*.zip")" + +# Install the dll files to C:\ProgramData\chocolatey\bin +# It is because they are loaded by other neko binaries, e.g. haxelib.exe +$chocoBin = Join-Path $env:ChocolateyInstall 'bin' +$dllFiles = @('gcmt-dll.dll', 'neko.dll') +foreach ($file in $dllFiles) { + Copy-Item "$nekoDir\$file" "$chocoBin" +} + +# Set NEKOPATH such that the ndll files can be loaded. +Install-ChocolateyEnvironmentVariable -VariableName NEKOPATH -VariableValue $nekoDir diff --git a/extra/chocolatey/chocolateyUninstall.ps1 b/extra/chocolatey/tools/chocolateyUninstall.ps1 similarity index 100% rename from extra/chocolatey/chocolateyUninstall.ps1 rename to extra/chocolatey/tools/chocolateyUninstall.ps1