From 39d38a95a82ea8cc8f4469315cf0a19a13b0d47a Mon Sep 17 00:00:00 2001 From: Amaury Chamayou Date: Wed, 26 Aug 2026 14:59:54 +0100 Subject: [PATCH] Cache npm packages in CI Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../actions/install-ci-dependencies/action.yml | 17 ++++++++++++++--- .github/workflows/README.md | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/actions/install-ci-dependencies/action.yml b/.github/actions/install-ci-dependencies/action.yml index d6ef6bc43d9..f1c203c77a3 100644 --- a/.github/actions/install-ci-dependencies/action.yml +++ b/.github/actions/install-ci-dependencies/action.yml @@ -1,10 +1,10 @@ name: Install Azure Linux CI dependencies -description: Restore and populate the Azure Linux package cache +description: Restore and populate the Azure Linux RPM and npm package caches runs: using: composite steps: - - name: Configure package cache + - name: Configure RPM package cache id: configure shell: bash run: | @@ -73,7 +73,7 @@ runs: echo "package-manager=$package_manager" >> "$GITHUB_OUTPUT" echo "setup-script=$setup_script" >> "$GITHUB_OUTPUT" - - name: Restore package cache + - name: Restore RPM package cache continue-on-error: true uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: @@ -83,6 +83,17 @@ runs: azure-linux-${{ steps.configure.outputs.package-manager }}-rpms-${{ runner.arch }}-${{ hashFiles('scripts/setup-ci*.sh') }}- azure-linux-${{ steps.configure.outputs.package-manager }}-rpms-${{ runner.arch }}- + - name: Restore npm package cache + continue-on-error: true + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: /github/home/.npm + key: azure-linux-npm-packages-${{ runner.arch }}-${{ hashFiles('**/package.json', 'scripts/prettier-checks.sh') }}-${{ github.job }}-${{ steps.configure.outputs.cache-week }} + restore-keys: | + azure-linux-npm-packages-${{ runner.arch }}-${{ hashFiles('**/package.json', 'scripts/prettier-checks.sh') }}-${{ github.job }}- + azure-linux-npm-packages-${{ runner.arch }}-${{ hashFiles('**/package.json', 'scripts/prettier-checks.sh') }}- + azure-linux-npm-packages-${{ runner.arch }}- + - name: Install dependencies shell: bash env: diff --git a/.github/workflows/README.md b/.github/workflows/README.md index de28b876a81..2e5e3435d2c 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -4,9 +4,9 @@ Documents the various GitHub Actions workflows, the role they fulfill and 3rd pa ## Azure Linux CI dependencies -The local composite action in `.github/actions/install-ci-dependencies/action.yml` installs Azure Linux 3 and 4 CI dependencies and caches downloaded RPMs. Its cache key separates package managers and runner architectures, includes a hash of `scripts/setup-ci*.sh`, and includes the date of the most recent Sunday at midnight UTC. The weekly date makes GitHub Actions create a refreshed immutable cache each week. +The local composite action in `.github/actions/install-ci-dependencies/action.yml` installs Azure Linux 3 and 4 CI dependencies and caches downloaded RPM and npm packages. Cache keys separate runner architectures, hash the relevant dependency inputs, and include the date of the most recent Sunday at midnight UTC. The RPM key also separates package managers, while the npm key separates jobs so each job can save the packages it downloads. The weekly date makes GitHub Actions create refreshed immutable caches each week. -At a weekly rollover, restore keys first reuse the latest cache for the same dependency scripts and then fall back to any cache for the same package manager and architecture. The package manager refreshes repository metadata and downloads only missing or updated RPMs. `actions/cache` saves the populated directory automatically after a successful job when the exact weekly key was not restored. +At a weekly rollover, restore keys first reuse the latest cache for the same dependency inputs and then fall back to a compatible cache for the same architecture. The package managers refresh registry metadata and download only missing or updated packages. `actions/cache` saves each populated directory automatically after a successful job when the exact weekly key was not restored. # Maintained