flcdrg / au-packages

David's Chocolatey Automatic Packages
MIT License
18 stars 53 forks source link

Issue with Chocolatey 4 Business - Jenkins Internalize from Community Repository #128

Closed stefan-brun closed 2 years ago

stefan-brun commented 2 years ago

Hi found a Problem with your Package and Chocolatey C4B.

https://github.com/flcdrg/au-packages/blob/6ee6db82d55acedf93c912d9f26e4c4f468c4e5a/PDFXchangeEditor/tools/chocolateyInstall.ps1#L15 and https://github.com/flcdrg/au-packages/blob/6ee6db82d55acedf93c912d9f26e4c4f468c4e5a/PDFXchangeEditor/tools/chocolateyInstall.ps1#L16

i opened a Case at chocolatey, they told me i should do a pull request to ask you to fix the URL references to not invoke variables within URL path in the chocolateyinstall.ps1 script.

here is the LOG from Jenkins:

Started by user admin Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\Internalize packages from the Community Repository@2 [Pipeline] { [Pipeline] powershell Created temporary directory 'C:\Windows\TEMP\054d5a72-dada-4af2-8b83-108550fb0679'. Chocolatey v1.1.0 Business Downloading existing package(s) to C:\Windows\TEMP\054d5a72-dada-4af2-8b83-108550fb0679\download

PDFXchangeEditor v9.3.361.0 (forced) [Approved] Found internalizable Chocolatey functions. Inspecting values for remote resources. Found 'https://downloads.pdf-xchange.com/EditorV9.x86.msi' for replacement. Found 'https://downloads.pdf-xchange.com/EditorV9.x64.msi' for replacement. Unable to find value for variable '$version'. May not be able to download resource from url 'https://builds-archive.tracker-software.com/$version/$filename'. Found 'https://builds-archive.tracker-software.com/$version/EditorV9.x86.msi' for replacement. Unable to find value for variable '$version'. May not be able to download resource from url 'https://builds-archive.tracker-software.com/$version/$filename64'. Found 'https://builds-archive.tracker-software.com/$version/EditorV9.x64.msi' for replacement.

Unable to find value for variable '$lastModified'. May not be able to download resource from url 'HTTP Last Modified : $lastModified'. Found 'HTTP Last Modified : $lastModified' for replacement. Encountered error downloading package pdfxchangeeditor v: System.UriFormatException: Invalid URI: The URI scheme is not valid. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at chocolatey.licensed.infrastructure.app.commandresources.RemoteDownloader.get_remote_file_name(String url, String userAgent, String defaultName, PSHost host) at chocolatey.licensed.infrastructure.app.commands.ProChocolateyDownloadCommand.process_downloaded_package(IPackage package, String downloadLocation, ChocolateyConfiguration configuration) at chocolatey.infrastructure.app.nuget.NugetCommon.<>cDisplayClass14.b11(Object s, PackageOperationEventArgs e) at NuGet.PackageManager.OnInstalled(PackageOperationEventArgs e) at NuGet.PackageManager.Execute(IPackage package, IPackageOperationResolver resolver) at NuGet.PackageManager.InstallPackage(IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions) at chocolatey.licensed.infrastructure.app.commands.ProChocolateyDownloadCommand.download_packages(String packageName, String packageVersion, String downloadLocation, ChocolateyConfiguration configuration) Failed to download package 'pdfxchangeeditor' [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE

flcdrg commented 2 years ago

Hi Stefan, thanks for creating the issue - I'm a bit confused as to why it is trying to parse the script like that. The script is valid PowerShell and obviously works fine in normal use. If you can suggest an alternate way to write the script I'm open to suggestions.

stefan-brun commented 2 years ago

Hey David, i'm new to Chocolatey and our Costumer has an C4B installation. Which you have the possibility to internalize Community Packages to our own Repo. For this Process we can use the Jenkins which automates the task around internalize und pushing Packages to our Repo. So i'm not really see behind these Scripts :)

I have some Infos from Chocolatey Support Comment from Ryan Richter -> ryanrichter94

The reason package internalizer will not work on the package is because of the way the pdfxchangeeditor package maintainer has chosen to use variables within the URL path defined in the package's chocolateyinstall.ps1 file.

The URLS are defined in the script as the following:

$url = "https://builds-archive.tracker-software.com/$version/$filename" $url64 = "https://builds-archive.tracker-software.com/$version/$filename64" Because of this package internalizer is trying to go to https://builds-archive.tracker-software.com/$version/$filename and https://builds-archive.tracker-software.com/$version/$filename64 and getting a 404 as these are not valid URL paths to download the package binary.

I see only other chocolateyinstall.ps1 they don't do it as you do with variables.

flcdrg commented 2 years ago

I reached out on the Chocolatey Discord server and got a response from @gep13 which provided a bit more information

https://discord.com/channels/778552361454141460/897095556466372629/972077441071874068

and pointed to https://github.com/chocolatey-community/chocolatey-packages/pull/1724 as another example of a package to be compatible with C4B.

I see only other chocolateyinstall.ps1 they don't do it as you do with variables. Chocolatey packages can vary depending on how the original software author created their software (and installer) and how they publish the software.

What this package is currently doing is absolutely fine. However C4B is making some particular assumptions that get it confused, so if we can tweak this package a bit, hopefully we can "have our cake and eat it too" 😃

flcdrg commented 2 years ago

https://github.com/flcdrg/au-packages/commit/77efb051641f1aff871c17960c78ac342169beb4

flcdrg commented 2 years ago

I've pushed new versions of the PDF packages - 9.3.361.20220508

I don't have C4B, but according to @gep13's post to Discord, you should be able to run something like this with the new version:

choco download PDFXchangeEditor --internalize version="9.3.361.20220508" 
stefan-brun commented 2 years ago

Same error with the package, tested it today. I think it's not the C4B the Problem. It's the Jenkins Automation AUTOMATE PACKAGE INTERNALIZER (MSP/C4B)

It this Jenkins Job which fails: Jenkins Job Details: Internalize Package

flcdrg commented 2 years ago

I think you'll have to go back to the Chocolatey folks on this. If you find out any more then feel free to post back here

gep13 commented 2 years ago

@stefan-brun I agree that there is still an error in the internalization process, I don't agree that it is the same one.

Using the suggested command, the error is the following:

image
Encountered error downloading package PDFXchangeEditor v:
System.Exception: The remote file either doesn't exist, is unauthorized, or is forbidden for url 'https://builds-archive.tracker-software.com/9.3.361.20220508/EditorV9.x86.msi'.
  The remote server returned an error: (404) Not Found.
   at chocolatey.licensed.infrastructure.app.commandresources.RemoteDownloader.download_file(String url, String filePath, String userAgent, Boolean showProgress)
   at chocolatey.licensed.infrastructure.app.commands.ProChocolateyDownloadCommand.process_downloaded_package(IPackage package, String downloadLocation, ChocolateyConfiguration configuration)
   at chocolatey.infrastructure.app.nuget.NugetCommon.<>c__DisplayClass14.<GetPackageManager>b__11(Object s, PackageOperationEventArgs e)
   at NuGet.PackageManager.OnInstalled(PackageOperationEventArgs e)
   at NuGet.PackageManager.Execute(IPackage package, IPackageOperationResolver resolver)
   at NuGet.PackageManager.InstallPackage(IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)
   at chocolatey.licensed.infrastructure.app.commands.ProChocolateyDownloadCommand.download_packages(String packageName, String packageVersion, String downloadLocation, ChocolateyConfiguration configuration)

Looks like the fallback URL is causing problems here 😢

I am honestly not sure what the best approach is here...

flcdrg commented 2 years ago

ah.. thanks for the stack trace. Yeah, the fallback URL is wrong. The logic should be replacing the 'date fix notation' version with zero, but it isn't. I'll take a look at that.

flcdrg commented 2 years ago

Hmm.. I'm curious do you get any different response if you use this? I think the fallback URL could be tricking C4B

choco download PDFXchangeEditor --internalize version="9.3.361.0"
gep13 commented 2 years ago

@flcdrg I can confirm that this command does indeed work, however...

The resulting internalized package has four copies of the msi though (since it has no way of knowing which one is which). The chocolateyInstall.ps1 file, then has:

image

You can see that there is a files\3\EditorV9.x86.msi and files\4\EditorV9.x64.msi

flcdrg commented 2 years ago

I noticed that Tracker seem to have some newer URLs for downloading, so it may be I can modify the script to just use a regular single download URL rather than have to do the fallback thing. I'll need to do some investigating.

flcdrg commented 2 years ago

Just reviewed the download URLs and actually I was wrong. The 'fallback' URLs are still the same and are a lot slower that the 'primary' URL download. That's why I wrote the chocolateyInstall.ps1 the way it is. I'd prefer not to change this as just using the fallback URLs will result in a poorer experience for most people.

My suggestion would be that you might be better off creating your own internal version of the package that just uses the fallback URLs.