Added various NPM scripts.

This commit is contained in:
2026-01-01 13:44:23 -08:00
parent c178cfcb95
commit 20a18c8fff
8 changed files with 385 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
name: npm-install
description: "Download the desired NPM package tarball."
inputs:
name:
description: "Name of the package."
required: true
version:
description: "Version of the package."
required: false
default: ""
prerelease:
description: "Install prerelease packages. Values: true, false."
required: false
default: "false"
outputDirectory:
description: "Directory for the output file."
required: true
default: "."
registry:
description: "NPM registry URL."
required: false
default: "https://npm.pkg.github.com"
authToken:
description: "Authentication token for the registry."
required: true
outputs:
tgz:
description: "The path to the .tgz file."
value: ${{ steps.download.outputs.tgz }}
runs:
using: "composite"
steps:
- name: "Download the package."
id: download
run: bash ${{ github.action_path }}/download_package.sh "${{ inputs.name }}" "${{ inputs.version }}" "${{ inputs.registry }}" "${{ inputs.authToken }}" "${{ inputs.outputDirectory }}"
shell: bash

View File

@@ -0,0 +1,65 @@
#!/bin/bash
set -e
PACKAGE_NAME="$1"
VERSION="$2"
REGISTRY="$3"
AUTH_TOKEN="$4"
OUTPUT_DIR="${5:-.}"
if [[ ! -f "$GITHUB_OUTPUT" ]]; then
GITHUB_OUTPUT="/dev/fd/1"
fi
# Ensure version is provided
if [[ -z "$VERSION" ]]; then
echo "Error: VERSION is required"
exit 1
fi
# Download the tarball
TARBALL_URL="$REGISTRY/$PACKAGE_NAME/-/$PACKAGE_NAME-$VERSION.tgz"
TGZ_NAME="$PACKAGE_NAME-$VERSION.tgz"
mkdir -p "$OUTPUT_DIR"
TGZ_PATH="$OUTPUT_DIR/$TGZ_NAME"
echo "Downloading $TARBALL_URL"
CURL_HEADERS=()
if [[ -n "$AUTH_TOKEN" ]]; then
CURL_HEADERS+=(-H "Authorization: Bearer $AUTH_TOKEN")
fi
# Download and capture HTTP status separately
# Temporarily disable 'exit on error' to capture status
set +e
HTTP_CODE=$(curl -sL -w "%{http_code}" -o "$TGZ_PATH" "${CURL_HEADERS[@]}" "$TARBALL_URL")
CURL_EXIT=$?
set -e
# Check if curl command itself failed (network issues, DNS, etc)
if [[ $CURL_EXIT -ne 0 ]]; then
echo "Error: curl failed with exit code $CURL_EXIT (network error or invalid URL)"
rm -f "$TGZ_PATH"
exit 1
fi
# Check HTTP status code
if [[ "$HTTP_CODE" != "200" ]]; then
echo "Error: Failed to download package (HTTP $HTTP_CODE)"
if [[ -f "$TGZ_PATH" ]]; then
echo "Response preview:"
head -c 500 "$TGZ_PATH"
echo ""
rm -f "$TGZ_PATH"
fi
exit 1
fi
if [[ ! -f "$TGZ_PATH" ]]; then
echo "Error: Download failed - file not created"
exit 1
fi
echo "tgz=$TGZ_PATH" >> "$GITHUB_OUTPUT"
echo "Downloaded $TGZ_NAME"