Added various NPM scripts.
This commit is contained in:
28
npm/npm-query-versions/action.yaml
Normal file
28
npm/npm-query-versions/action.yaml
Normal file
@@ -0,0 +1,28 @@
|
||||
name: npm-query-versions
|
||||
description: "Get all versions of an NPM package from a registry."
|
||||
inputs:
|
||||
name:
|
||||
description: "Name of the package."
|
||||
required: true
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: "https://npm.pkg.github.com"
|
||||
authToken:
|
||||
description: "Authentication token for the registry."
|
||||
required: true
|
||||
prerelease:
|
||||
description: "Include prerelease packages. Values: true, false."
|
||||
required: false
|
||||
default: "false"
|
||||
outputs:
|
||||
versions:
|
||||
description: "Newline-separated list of versions."
|
||||
value: ${{ steps.query.outputs.versions }}
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: "Query NPM registry for versions."
|
||||
id: query
|
||||
run: bash ${{ github.action_path }}/query_versions.sh "${{ inputs.name }}" "${{ inputs.registry }}" "${{ inputs.authToken }}" "${{ inputs.prerelease }}"
|
||||
shell: bash
|
||||
45
npm/npm-query-versions/query_versions.sh
Normal file
45
npm/npm-query-versions/query_versions.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
PACKAGE_NAME="$1"
|
||||
REGISTRY="$2"
|
||||
AUTH_TOKEN="$3"
|
||||
PRERELEASE="$4"
|
||||
|
||||
if [[ ! -f "$GITHUB_OUTPUT" ]]; then
|
||||
GITHUB_OUTPUT="/dev/fd/1"
|
||||
fi
|
||||
|
||||
# Construct the registry URL
|
||||
REGISTRY_URL="$REGISTRY"
|
||||
if [[ "$REGISTRY" == "https://npm.pkg.github.com" ]]; then
|
||||
# GitHub Packages uses a specific URL format
|
||||
REGISTRY_URL="$REGISTRY"
|
||||
fi
|
||||
|
||||
# Build curl headers
|
||||
CURL_HEADERS=(-H "Accept: application/vnd.npm.install-v1+json")
|
||||
if [[ -n "$AUTH_TOKEN" ]]; then
|
||||
CURL_HEADERS+=(-H "Authorization: Bearer $AUTH_TOKEN")
|
||||
fi
|
||||
|
||||
# Query the package metadata
|
||||
RESPONSE=$(curl -sL "${CURL_HEADERS[@]}" "$REGISTRY_URL/$PACKAGE_NAME" 2>/dev/null || echo "{}")
|
||||
|
||||
# Extract versions
|
||||
if [[ "$PRERELEASE" == "true" ]]; then
|
||||
# Get all versions
|
||||
VERSIONS=$(echo "$RESPONSE" | jq -r '.versions | keys[]' 2>/dev/null || echo "")
|
||||
else
|
||||
# Filter out prerelease versions (those with - in them)
|
||||
VERSIONS=$(echo "$RESPONSE" | jq -r '.versions | keys[] | select(contains("-") | not)' 2>/dev/null || echo "")
|
||||
fi
|
||||
|
||||
# Output versions separated by newlines
|
||||
if [[ -n "$VERSIONS" ]]; then
|
||||
echo "versions<<EOF" >> "$GITHUB_OUTPUT"
|
||||
echo "$VERSIONS" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "versions=" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
Reference in New Issue
Block a user