Skip to content

choco download --internalize fails with 404 due to unresolved variable in download URL #3

@LucaMoor

Description

@LucaMoor

When attempting to internalize this package using choco download --internalize, the process fails with a 404 error:

The remote file either doesn't exist, is unauthorized, or is forbidden for url
'https://github.com/anomalyco/opencode/releases/download/v$env:chocolateyPackageVersion/opencode-windows-x64.zip'

The Chocolatey package internalizer works by doing a static text scan of the install script to find and download URLs — it does not execute the PowerShell. In tools/chocolateyinstall.ps1, the download URL is built using a runtime variable:

$version = $env:chocolateyPackageVersion
$url64 = "https://github.com/anomalyco/opencode/releases/download/v$version/opencode-windows-x64.zip"

Because $version is never resolved at scan time, the internalizer constructs the literal URL https://github.com/.../v$env:chocolateyPackageVersion/... and hits a 404.

The update.ps1 script already rewrites the checksum to a hardcoded value on each release. It should also rewrite the URL version to a literal string, so that each published .nupkg contains a fully resolved, static URL such as:
$url64 = 'https://github.com/anomalyco/opencode/releases/download/v1.14.29/opencode-windows-x64.zip'

This means adding a version replacement step in update.ps1 alongside the existing checksum replacement:

# Replace placeholder version in URL so published nupkg has a static, internalizable URL
$installScript = $installScript -replace 'releases/download/v[^/]+/opencode', "releases/download/v$latestVersion/opencode"

And updating tools/chocolateyinstall.ps1 to use a placeholder that update.ps1 can rewrite:
$url64 = 'https://github.com/anomalyco/opencode/releases/download/vPLACEHOLDER_VERSION/opencode-windows-x64.zip'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions