diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff83d868..7d8aee9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,34 +1,42 @@ -name: 'ci' - on: - push: - branches: [master] - pull_request: - branches: [master] + pull_request: {} + push: {} jobs: + # The ci-matrix job ends up as multiple jobs and therefore as multiple checks. + # Each check's name ends up with the node version appended. + # If we were to use those checks as required checks, we would have to occasionally bump them. + # This job allows us to have a single check that we don't have to bump. ci: - runs-on: 'ubuntu-latest' + needs: ci-matrix + runs-on: ubuntu-latest steps: - - uses: 'actions/checkout@v3' - - - name: 'Use Node.js' - uses: 'actions/setup-node@v3' + - run: exit 0 + ci-matrix: + needs: get-supported-node-versions + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ${{ fromJson(needs.get-supported-node-versions.outputs.versions) }} + steps: + - uses: actions/checkout@v3 with: - node-version: 'lts/*' - - - name: 'Cache Node dependencies' - uses: 'actions/cache@v3.0.1' + fetch-depth: 0 # for commit linting + - uses: actions/setup-node@v3 with: - path: '~/.npm' - key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: 'Install dependencies' - run: 'npm install' - + node-version: ${{ matrix.node-version }} + - run: npm --global install npm@latest + - run: npm ci - uses: wagoid/commitlint-github-action@v5 - - - name: 'Run tests' - run: 'npm test' + - run: npm test + get-supported-node-versions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - id: get + run: | + set -euxo pipefail + active_versions=$(bash get-node-supported-versions.sh) + echo "active=$active_versions" >> "$GITHUB_OUTPUT" + outputs: + versions: ${{ steps.get.outputs.active }} diff --git a/get-node-supported-versions.sh b/get-node-supported-versions.sh new file mode 100755 index 00000000..78315717 --- /dev/null +++ b/get-node-supported-versions.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euxo pipefail +url=https://raw.githubusercontent.com/nodejs/Release/master/schedule.json +release_schedule=$(curl -s $url) +today=$(date "+%Y-%m-%d") +active_versions=$(echo $release_schedule | jq -s "[ .[] | to_entries[] | select(.value.start <= \"$today\" and .value.end >= \"$today\") | .key[1:] ]") +echo $active_versions