-
Notifications
You must be signed in to change notification settings - Fork 78
80 lines (68 loc) · 2.97 KB
/
engine-compat.yml
File metadata and controls
80 lines (68 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Node Packages Engine Compatibility Check
on:
workflow_call:
inputs:
node-versions:
description: 'Comma-separated Node.js versions, e.g. 22.20.0, 22, 24.0.0, 24'
required: true
type: string
permissions:
contents: read
pull-requests: write
jobs:
engine-compat:
name: Engine compatibility
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Check engines and report
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_VERSIONS: ${{ inputs.node-versions }}
run: |
# Load nvm (pre-installed on GitHub runners)
export NVM_DIR="$HOME/.nvm" && . "$NVM_DIR/nvm.sh"
PR="${{ github.event.pull_request.number }}"
MARKER="<!-- engine-compat -->"
FAILED=false
TABLE="| Node | Result | Incompatible Packages |\n|---|---|---|"
# Loop through each requested Node version
IFS=',' read -ra VERSIONS <<< "$NODE_VERSIONS"
for V in "${VERSIONS[@]}"; do
V=$(echo "$V" | xargs) # trim whitespace
nvm install "$V" --no-progress > /dev/null 2>&1
nvm use "$V" > /dev/null 2>&1
VER=$(node --version)
# Dry-run install to collect EBADENGINE warnings without actually installing.
# awk extracts "package@version (node range)" from multi-line warning blocks.
# sort -u deduplicates (npm may warn about the same package multiple times).
PKGS=$(npm ci --dry-run 2>&1 \
| awk -F"'" '/EBADENGINE.*package:/{pkg=$2} /EBADENGINE.*node:/{if(pkg){print pkg" (node "$2")"; pkg=""}}' \
| sort -u | tr '\n' ',' | sed 's/,$//' | sed 's/,/, /g')
if [ -n "$PKGS" ]; then
FAILED=true
# Escape pipe characters so they don't break the markdown table
SAFE=$(echo "$PKGS" | sed 's/|/\\|/g')
TABLE="$TABLE\n| $VER | ❌ Fail | $SAFE |"
else
TABLE="$TABLE\n| $VER | ✅ Pass | — |"
fi
done
# Build the comment body
if [ "$FAILED" = true ]; then ICON="❌"; else ICON="✅"; fi
printf '%s\n## %s Engine Compatibility\n\n%b\n' "$MARKER" "$ICON" "$TABLE" > /tmp/comment.md
# Update existing comment (matched by HTML marker) or create a new one
OLD=$(gh api "repos/${{ github.repository }}/issues/${PR}/comments" \
--jq "[.[] | select(.body | contains(\"$MARKER\"))][0].id" 2>/dev/null || true)
if [ -n "$OLD" ] && [ "$OLD" != "null" ]; then
gh api --method PATCH "repos/${{ github.repository }}/issues/comments/$OLD" -F body=@/tmp/comment.md
else
gh pr comment "$PR" --body-file /tmp/comment.md
fi
# Add "blocked" label on failure, remove it on success
if [ "$FAILED" = true ]; then
gh label create blocked --color D93F0B 2>/dev/null || true
gh pr edit "$PR" --add-label blocked
else
gh pr edit "$PR" --remove-label blocked 2>/dev/null || true
fi