act-runner-el/.forgejo/actions/check-nodejs-versions/action.yml
Tom Foster 18f8f1701c feat(docker): optimise Node.js installation to single version per image
Replace multi-version Node.js installations with targeted single-version approach
to reduce image size and eliminate unused binaries. Updates version detection logic
to provide three distinct categories: previous LTS, current LTS, and latest stable.

Each distribution variant now installs exactly one Node.js version aligned with
its maturity level, simplifying builds and creating more predictable environments.
2025-09-13 12:37:35 +01:00

98 lines
3.9 KiB
YAML

name: Check Node.js Versions
description: Find currently supported Node.js versions including LTS releases
author: Tom Foster
outputs:
node-previous:
description: Oldest supported LTS Node.js version
value: ${{ steps.check.outputs.previous }}
node-latest:
description: Newest supported LTS Node.js version
value: ${{ steps.check.outputs.latest }}
node-unstable:
description: Newest even-numbered Node.js version
value: ${{ steps.check.outputs.unstable }}
runs:
using: composite
steps:
- name: Check Node.js versions
id: check
shell: python
run: |
import json
import urllib.request
import os
import sys
def get_node_releases():
"""Fetch Node.js releases from official distribution index."""
url = "https://nodejs.org/dist/index.json"
with urllib.request.urlopen(url) as response:
return json.loads(response.read().decode())
def get_major_version(version_str):
"""Extract the major version number."""
# Handle 'v18.1.0' format
version = version_str.replace('v', '')
return int(version.split('.')[0])
# Main execution
print("🔍 Fetching Node.js release index from nodejs.org...")
print(f"::debug::Fetching Node.js release index")
try:
# Fetch Node.js release index
releases = get_node_releases()
print(f"✓ Fetched {len(releases)} releases")
# Extract versions that are in Active or Maintenance LTS status
lts_versions = []
for release in releases:
if release.get('lts') and release.get('lts') != False:
major = get_major_version(release['version'])
if major not in lts_versions:
lts_versions.append(major)
# Get all even-numbered stable versions
stable_versions = []
for release in releases:
major = get_major_version(release['version'])
# Only include even-numbered versions (stable releases)
if major % 2 == 0 and major not in stable_versions:
stable_versions.append(major)
# Sort versions
lts_versions.sort()
stable_versions.sort()
# Determine the three distinct versions
# Use the two most recent LTS versions for previous/latest, and newest stable for unstable
node_previous = str(lts_versions[-2]) if len(lts_versions) >= 2 else str(lts_versions[0]) if lts_versions else str(stable_versions[-2])
node_latest = str(lts_versions[-1]) if lts_versions else str(stable_versions[-2] if len(stable_versions) >= 2 else stable_versions[-1])
node_unstable = str(stable_versions[-1])
print(f"🎯 Detected Node.js versions:")
print(f" Previous (second newest LTS): {node_previous}")
print(f" Latest (newest LTS): {node_latest}")
print(f" Unstable (newest stable): {node_unstable}")
print(f"::debug::Previous: {node_previous}")
print(f"::debug::Latest: {node_latest}")
print(f"::debug::Unstable: {node_unstable}")
# Set outputs using GitHub Actions format
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"previous={node_previous}\n")
f.write(f"latest={node_latest}\n")
f.write(f"unstable={node_unstable}\n")
print(f"✓ Successfully set action outputs")
print(f"::notice::Previous Node.js version: {node_previous}")
print(f"::notice::Latest Node.js version: {node_latest}")
print(f"::notice::Unstable Node.js version: {node_unstable}")
except Exception as e:
print(f"::error::Failed to check Node.js versions: {e}")
sys.exit(1)