diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 00000000000..81a0baa4bcf --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,60 @@ +name: 'Setup Node.js' +description: 'Setup Node and install dependencies using cache' +inputs: + save-cache: + description: 'Save cache when needed' + required: false + default: 'false' + +runs: + using: 'composite' + + steps: + - name: ⚙️ Calculate `CACHE_KEY` + shell: bash + run: | + echo 'CACHE_KEY=node_modules-${{ + 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: .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 c23383d3260..7339a77285f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,10 +10,23 @@ concurrency: cancel-in-progress: true env: - NODE_VERSION: 20 RENOVATE_VERSION: 38.142.7 # renovate: datasource=docker depName=renovate packageName=ghcr.io/renovatebot/renovate 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 + commitlint: runs-on: ubuntu-latest if: ${{ github.event_name != 'pull_request' || github.repository_owner != github.event.pull_request.head.repo.owner.login }} @@ -31,6 +44,8 @@ jobs: continue-on-error: true lint: + needs: + - prepare runs-on: ubuntu-latest if: ${{ github.event_name != 'pull_request' || github.repository_owner != github.event.pull_request.head.repo.owner.login }} @@ -40,24 +55,15 @@ jobs: with: show-progress: false - - name: enable corepack - run: corepack enable - - - name: Setup node - 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: enable corepack - run: corepack enable - - - name: Install project - run: pnpm install --frozen-lockfile - name: Lint run: pnpm lint e2e: + needs: + - prepare runs-on: ubuntu-latest if: ${{ github.event_name != 'pull_request' || github.repository_owner != github.event.pull_request.head.repo.owner.login }} @@ -73,20 +79,8 @@ jobs: with: show-progress: false - - name: enable corepack - run: corepack enable - - - name: Setup node - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm - - - name: enable corepack - run: corepack enable - - - name: Install project - run: pnpm install --frozen-lockfile + - name: 📥 Setup Node.js + uses: ./.github/actions/setup-node - name: Build run: pnpm build @@ -121,7 +115,10 @@ jobs: docker-user: root release: - needs: [lint, commitlint, e2e] + needs: + - lint + - commitlint + - e2e runs-on: ubuntu-latest steps: - name: Setup Git user @@ -150,20 +147,8 @@ jobs: git merge --no-ff -Xtheirs -m 'skip: merge (${{ github.sha }}) [skip release]' ${{ github.sha }} commit=$(git rev-parse HEAD) - - name: enable corepack - run: corepack enable - - - name: Setup node - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm - - - name: enable corepack - run: corepack enable - - - name: Install project - run: pnpm install --frozen-lockfile + - name: 📥 Setup Node.js + uses: ./.github/actions/setup-node - name: Push release branch run: git push origin release:release diff --git a/.node-version b/.node-version new file mode 100644 index 00000000000..2a393af592b --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.18.0 diff --git a/package.json b/package.json index c515c029d61..4aa4441415d 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ }, "packageManager": "pnpm@9.12.3", "engines": { - "node": ">=20.9.0", + "node": "^20.9.0 || ^22.11.0", "pnpm": "^9.0.0" }, "pnpm": {