Skip to content

fix: Handle undefined VERSION in installer script#1512

Merged
drager merged 2 commits intodrager:masterfrom
BrianHung:fix-installer-version-parameter
Jul 24, 2025
Merged

fix: Handle undefined VERSION in installer script#1512
drager merged 2 commits intodrager:masterfrom
BrianHung:fix-installer-version-parameter

Conversation

@BrianHung
Copy link
Contributor

Issue Description

The wasm-pack installer script fails in CI environments with the error:
./install.sh: line 18: VERSION: unbound variable

This occurs when running the standard installation command:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

Root Cause

The script uses 'set -u' on line 16, which causes bash to exit on undefined variables. Line 18 then references $VERSION before it's defined:
UPDATE_ROOT="https://github.com/rustwasm/wasm-pack/releases/download/$VERSION"

The script expects VERSION to be set as an environment variable, but this is not documented and is impractical in many CI environments where the command is piped directly to sh.

Affected Environments

  • GitHub Actions
  • GitLab CI
  • Jenkins
  • Any environment where setting env vars before piping is difficult

Fix

This commit adds proper VERSION handling:

  1. Check if VERSION is already set as an environment variable
  2. Parse --version from command line arguments
  3. Default to 'latest' if not specified
  4. Resolve 'latest' to actual version via GitHub API
  5. Ensure VERSION has 'v' prefix for download URLs

Compatibility

Maintains full backward compatibility:

  • VERSION=0.13.1 curl ... | sh (still works)
  • curl ... | sh -s -- --version 0.13.1 (new)
  • curl ... | sh (defaults to latest)

This allows the installer to work in all environments without requiring users to modify their CI scripts to set environment variables.

## Issue Description

The wasm-pack installer script fails in CI environments with the error:
  ./install.sh: line 18: VERSION: unbound variable

This occurs when running the standard installation command:
  curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

### Root Cause

The script uses 'set -u' on line 16, which causes bash to exit on undefined
variables. Line 18 then references $VERSION before it's defined:
  UPDATE_ROOT="https://github.com/rustwasm/wasm-pack/releases/download/$VERSION"

The script expects VERSION to be set as an environment variable, but this is
not documented and is impractical in many CI environments where the command
is piped directly to sh.

### Affected Environments

- GitHub Actions
- GitLab CI
- Jenkins
- Any environment where setting env vars before piping is difficult

### Fix

This commit adds proper VERSION handling:
1. Check if VERSION is already set as an environment variable
2. Parse --version from command line arguments
3. Default to 'latest' if not specified
4. Resolve 'latest' to actual version via GitHub API
5. Ensure VERSION has 'v' prefix for download URLs

### Compatibility

Maintains full backward compatibility:
- VERSION=0.13.1 curl ... | sh (still works)
- curl ... | sh -s -- --version 0.13.1 (new)
- curl ... | sh (defaults to latest)

This allows the installer to work in all environments without requiring
users to modify their CI scripts to set environment variables.
@BrianHung
Copy link
Contributor Author

Linux-stable test failing is unrelated to this PR. This PR only modifies the bash installer script and shouldn't affect cargo-test.


# Resolve "latest" to actual version number
if [ "$VERSION" = "latest" ]; then
VERSION=$(curl -s https://api.github.com/repos/rustwasm/wasm-pack/releases/latest | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will now result in a 404 since the rustwasm org no longer exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://blog.rust-lang.org/inside-rust/2025/07/21/sunsetting-the-rustwasm-github-org/
Ah ok I didn't see this blog post. Updated to point at this repository.. Feel free to take over this PR btw.

Copy link
Owner

@drager drager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@drager drager merged commit 1a0a851 into drager:master Jul 24, 2025
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants