Update dependencies and workflows #440
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: [push, pull_request] | |
| jobs: | |
| resolve-node-versions: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - id: set-matrix | |
| run: | | |
| node <<'EOF' >> $GITHUB_OUTPUT | |
| const https = require('https'); | |
| function compareSemver(a, b) { | |
| const pa = a.split('.').map(Number); | |
| const pb = b.split('.').map(Number); | |
| for (let i = 0; i < 3; i++) { | |
| if (pa[i] !== pb[i]) return pb[i] - pa[i]; | |
| } | |
| return 0; | |
| } | |
| https.get('https://nodejs.org/dist/index.json', res => { | |
| let data = ''; | |
| res.on('data', chunk => data += chunk); | |
| res.on('end', () => { | |
| const releases = JSON.parse(data); | |
| const lts = releases | |
| .filter(r => r.lts) | |
| .map(r => r.version.replace(/^v/, '')); | |
| const byMajor = {}; | |
| for (const v of lts) { | |
| const major = v.split('.')[0]; | |
| if (!byMajor[major]) byMajor[major] = []; | |
| byMajor[major].push(v); | |
| } | |
| const latestPerMajor = Object.entries(byMajor) | |
| .map(([major, versions]) => { | |
| versions.sort(compareSemver); | |
| return versions[0]; | |
| }); | |
| latestPerMajor.sort(compareSemver); | |
| const final = latestPerMajor.slice(0, 4); | |
| const matrix = { "node-version": final }; | |
| console.log(`matrix=${JSON.stringify(matrix)}`); | |
| }); | |
| }); | |
| EOF | |
| test: | |
| needs: resolve-node-versions | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.resolve-node-versions.outputs.matrix) }} | |
| name: Node ${{ matrix.node-version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Enable Corepack | |
| run: corepack enable | |
| - name: Detect Yarn version | |
| id: yarn-version | |
| run: | | |
| YARN_VERSION=$(node -p " | |
| try { | |
| const pm = require('./package.json').packageManager ?? ''; | |
| const match = pm.match(/^yarn@(\d+)/); | |
| match ? match[1] : ''; | |
| } catch { '' } | |
| ") | |
| if [ -z "$YARN_VERSION" ]; then | |
| YARN_VERSION=$(yarn --version | cut -d. -f1) | |
| fi | |
| echo "major=$YARN_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Detected Yarn major version: $YARN_VERSION" | |
| - name: Install dependencies | |
| run: | | |
| if [ "${{ steps.yarn-version.outputs.major }}" = "1" ]; then | |
| yarn install --frozen-lockfile --non-interactive --prefer-offline | |
| else | |
| yarn install --immutable | |
| fi | |
| - name: Lint | |
| run: yarn lint | |
| - name: Test | |
| run: yarn test |