diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 0000000..347d029 --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,69 @@ +name: 'Setup Node.js' +description: 'Setup Node and install dependencies using cache' +inputs: + node-version: + description: Set a specific node version instead of the default from `.node-version` file. + required: false + save-cache: + description: 'Save cache when needed' + required: false + default: 'false' + +runs: + using: 'composite' + + steps: + - name: ⚙️ Calculate `CACHE_KEY` + shell: bash + run: | + if [[ -z '${{ inputs.node-version }}' ]]; then + node_major=$(grep -E -o '^[0-9]+' .node-version) + else + node_major=$(echo '${{ inputs.node-version }}' | grep -E -o '^[0-9]+') + fi + echo "CACHE_KEY=node_modules-v${node_major}-${{ + hashFiles('.node-version', 'pnpm-lock.yaml') + }}" >> "$GITHUB_ENV" + + - name: ♻️ Restore `node_modules` + uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 + id: node-modules-restore + with: + path: node_modules + key: ${{ env.CACHE_KEY }} + enableCrossOsArchive: true + + - name: Calculate `CACHE_HIT` + shell: bash + run: | + echo 'CACHE_HIT=${{ + (steps.node-modules-restore.outputs.cache-hit == 'true') && 'true' || '' + }}' >> "$GITHUB_ENV" + + - name: ⚙️ Setup pnpm + uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 + with: + standalone: true + + - name: ⚙️ Setup Node.js ${{ inputs.node-version }} + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version-file: ${{ inputs.node-version == '' && '.node-version' || inputs.node-version }} + node-version: ${{ inputs.node-version }} + cache: ${{ env.CACHE_HIT != 'true' && 'pnpm' || '' }} + + - name: 📥 Install dependencies + if: env.CACHE_HIT != 'true' + shell: bash + run: pnpm install --frozen-lockfile + env: + # Other environment variables + HUSKY: '0' # By default do not run HUSKY install + + - name: ♻️ Write `node_modules` cache + if: inputs.save-cache == 'true' && env.CACHE_HIT != 'true' + uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 + with: + path: node_modules + key: ${{ env.CACHE_KEY }} + enableCrossOsArchive: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d073538..2305fe3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,16 +18,29 @@ concurrency: cancel-in-progress: ${{ github.ref_name != 'main' }} env: - GIT_EMAIL: bot+pep440@renovateapp.com DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} - NODE_VERSION: 20 # needs to be in sync with other versions below DRY_RUN: true permissions: contents: read jobs: + prepare: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + show-progress: false + + - name: 📥 Setup Node.js + uses: ./.github/actions/setup-node + with: + save-cache: true test: + needs: + - prepare name: ${{ matrix.node-version == 20 && format('test ({0})', matrix.os) || format('test ({0}, node-{1})', matrix.os, matrix.node-version) }} runs-on: ubuntu-latest @@ -37,30 +50,26 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - node-version: [18, 20] + node-version: [18, 20, 22] # exclude: # - os: windows-latest # node-version: 12 env: - coverage: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == 20 }} - NODE_VERSION: ${{ matrix.node-version }} + coverage: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == 22 }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: - fetch-depth: 2 + fetch-depth: 10 # required for coverage show-progress: false filter: blob:none # we don't need all blobs - - name: Enable corepack - run: corepack enable - - - name: Set up Node.js ${{ env.NODE_VERSION }} - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + - name: 📥 Setup Node.js + uses: ./.github/actions/setup-node with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm + node-version: ${{ matrix.node-version }} + save-cache: true - name: Init platform shell: bash @@ -70,9 +79,6 @@ jobs: echo 'Node $(node --version)' echo 'pnpm $(pnpm --version)' - - name: Installing dependencies - run: pnpm install - - name: Run tests run: pnpm jest --maxWorkers=2 --ci --coverage ${{ env.coverage }} --logHeapUsage @@ -90,6 +96,8 @@ jobs: if: env.coverage == 'true' lint: + needs: + - prepare runs-on: ubuntu-latest # lint shouldn't need more than 10 min @@ -98,18 +106,10 @@ jobs: steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: - fetch-depth: 2 show-progress: false - filter: blob:none # we don't need all blobs - - name: Enable corepack - run: corepack enable - - - name: Set up Node.js ${{ env.NODE_VERSION }} - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm + - name: 📥 Setup Node.js + uses: ./.github/actions/setup-node - name: Init platform run: | @@ -131,7 +131,9 @@ jobs: # run: pnpm type-check release: - needs: [lint, test] + needs: + - lint + - test runs-on: ubuntu-latest # tests shouldn't need more time @@ -149,21 +151,16 @@ jobs: show-progress: false filter: blob:none # we don't need all blobs - - name: Enable corepack - run: corepack enable - - - name: Set up Node.js ${{ env.NODE_VERSION }} - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm + - name: 📥 Setup Node.js + uses: ./.github/actions/setup-node - name: Init platform run: | git config --global core.autocrlf false git config --global core.symlinks true - git config --global user.email ${GIT_EMAIL} - git config --global user.name 'Renovate Bot' + # Use github action user for the commit + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - name: Check dry run run: | diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..7af24b7 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +22.11.0 diff --git a/package.json b/package.json index ac96adc..db3c705 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ }, "packageManager": "pnpm@8.15.9", "engines": { - "node": "^18.12.0 || >= 20.0.0", + "node": "^18.12.0 || ^20.0.0 || ^22.11.0", "pnpm": "^8.6.11" } }