|
| 1 | +name: Node.js Support Matrix |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, dev] |
| 6 | + pull_request: |
| 7 | + branches: [main, dev] |
| 8 | + |
| 9 | +jobs: |
| 10 | + node-support-matrix: |
| 11 | + name: Node.js ${{ matrix.node-version }} Compatibility |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + # NOTE: Node.js versions are automatically extracted by the compatibility-summary job |
| 17 | + # The summary report will dynamically reflect any changes made to this list |
| 18 | + node-version: ['18', '20'] |
| 19 | + fail-fast: false |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: ${{ matrix.node-version }} |
| 29 | + |
| 30 | + - name: Verify Node.js version meets requirements |
| 31 | + run: | |
| 32 | + echo "Node.js version:" |
| 33 | + node --version |
| 34 | + echo "npm version:" |
| 35 | + npm --version |
| 36 | + echo "Checking Node.js version compatibility..." |
| 37 | + node -e " |
| 38 | + const version = process.version; |
| 39 | + const major = parseInt(version.slice(1).split('.')[0]); |
| 40 | + const required = 16; |
| 41 | + console.log(\`Node.js \${version} (major: \${major})\`); |
| 42 | + if (major < required) { |
| 43 | + console.error(\`❌ Node.js \${major} is below minimum required version \${required}\`); |
| 44 | + process.exit(1); |
| 45 | + } else { |
| 46 | + console.log(\`✅ Node.js \${major} meets minimum requirement \${required}\`); |
| 47 | + } |
| 48 | + " |
| 49 | + |
| 50 | + - name: Enable Corepack for Yarn v4 |
| 51 | + run: | |
| 52 | + echo "Current Node.js version:" |
| 53 | + node --version |
| 54 | + echo "Enabling Corepack..." |
| 55 | + corepack enable |
| 56 | + echo "Preparing Yarn 4.9.2..." |
| 57 | + corepack prepare [email protected] --activate |
| 58 | + echo "Yarn setup complete" |
| 59 | + |
| 60 | + - name: Verify Yarn version |
| 61 | + run: | |
| 62 | + echo "Yarn version:" |
| 63 | + yarn --version |
| 64 | + echo "Checking package manager field..." |
| 65 | + node -e "console.log('packageManager:', require('./package.json').packageManager)" |
| 66 | + |
| 67 | + - name: Install dependencies |
| 68 | + run: | |
| 69 | + echo "Installing dependencies with Yarn v4..." |
| 70 | + echo "Current working directory: $(pwd)" |
| 71 | + echo "Files in directory:" |
| 72 | + ls -la |
| 73 | + echo "Installing..." |
| 74 | + yarn install --immutable |
| 75 | + echo "Dependencies installed successfully" |
| 76 | + |
| 77 | + - name: Verify installation |
| 78 | + run: | |
| 79 | + echo "Checking node_modules..." |
| 80 | + ls -la node_modules/ | head -10 |
| 81 | + echo "Checking TypeScript installation..." |
| 82 | + yarn tsc --version |
| 83 | + |
| 84 | + - name: TypeScript compilation check |
| 85 | + run: | |
| 86 | + echo "Running TypeScript compilation check..." |
| 87 | + yarn tsc --noEmit |
| 88 | + echo "✅ TypeScript compilation successful" |
| 89 | + |
| 90 | + - name: Run test suite (no coverage for compatibility test) |
| 91 | + run: | |
| 92 | + echo "Running test suite for Node.js ${{ matrix.node-version }}..." |
| 93 | + yarn test --watchAll=false --verbose=false --coverage=false |
| 94 | + echo "✅ Test suite passed" |
| 95 | + |
| 96 | + - name: Basic linting check |
| 97 | + run: | |
| 98 | + echo "Running ESLint checks..." |
| 99 | + yarn lint |
| 100 | + echo "✅ Linting passed" |
| 101 | + |
| 102 | + - name: Build verification |
| 103 | + run: | |
| 104 | + echo "Building project..." |
| 105 | + yarn build |
| 106 | + echo "Checking build output..." |
| 107 | + ls -la dist/ |
| 108 | + echo "✅ Build successful" |
| 109 | +
|
| 110 | + compatibility-summary: |
| 111 | + name: Node.js Compatibility Summary |
| 112 | + runs-on: ubuntu-latest |
| 113 | + needs: node-support-matrix |
| 114 | + if: always() |
| 115 | + |
| 116 | + steps: |
| 117 | + - name: Checkout code (for extracting matrix versions) |
| 118 | + uses: actions/checkout@v4 |
| 119 | + |
| 120 | + - name: Node.js Compatibility Report |
| 121 | + run: | |
| 122 | + echo "=== Node.js Compatibility Test Results ===" |
| 123 | + echo "Matrix job result: ${{ needs.node-support-matrix.result }}" |
| 124 | + echo "" |
| 125 | + |
| 126 | + # Extract Node.js versions from the workflow file dynamically |
| 127 | + echo "Extracting tested Node.js versions from workflow..." |
| 128 | + NODE_VERSIONS=($(grep "node-version: \[" .github/workflows/support.yml | sed "s/.*\[\(.*\)\].*/\1/" | tr "," "\n" | sed "s/[' ]//g" | sort -n)) |
| 129 | + echo "Detected versions: ${NODE_VERSIONS[*]}" |
| 130 | + echo "" |
| 131 | + |
| 132 | + if [[ "${{ needs.node-support-matrix.result }}" == "success" ]]; then |
| 133 | + echo "🎉 SUCCESS: All Node.js versions are fully compatible!" |
| 134 | + echo "" |
| 135 | + |
| 136 | + # Dynamically generate compatibility lines |
| 137 | + for version in "${NODE_VERSIONS[@]}"; do |
| 138 | + echo "✅ Node.js $version - Compatible" |
| 139 | + done |
| 140 | + |
| 141 | + echo "" |
| 142 | + echo "The log-engine library works correctly across all supported Node.js versions." |
| 143 | + |
| 144 | + # Generate minimum version requirement dynamically |
| 145 | + min_version=${NODE_VERSIONS[0]} |
| 146 | + echo "Users can safely install and use this package with Node.js ${min_version}+ environments." |
| 147 | + |
| 148 | + elif [[ "${{ needs.node-support-matrix.result }}" == "failure" ]]; then |
| 149 | + echo "❌ FAILURE: Some Node.js versions failed compatibility tests" |
| 150 | + echo "" |
| 151 | + echo "Tested versions:" |
| 152 | + for version in "${NODE_VERSIONS[@]}"; do |
| 153 | + echo " - Node.js $version" |
| 154 | + done |
| 155 | + echo "" |
| 156 | + echo "Please check the individual job logs above to see which versions failed and why." |
| 157 | + echo "Common issues:" |
| 158 | + echo "- Yarn/Corepack setup problems" |
| 159 | + echo "- TypeScript compilation issues" |
| 160 | + echo "- Test failures specific to Node.js version" |
| 161 | + echo "- Dependency compatibility problems" |
| 162 | + exit 1 |
| 163 | + else |
| 164 | + echo "⚠️ PARTIAL: Some tests were cancelled or skipped" |
| 165 | + echo "Result status: ${{ needs.node-support-matrix.result }}" |
| 166 | + echo "" |
| 167 | + echo "Tested versions:" |
| 168 | + for version in "${NODE_VERSIONS[@]}"; do |
| 169 | + echo " - Node.js $version" |
| 170 | + done |
| 171 | + exit 1 |
| 172 | + fi |
0 commit comments