An open source design system that's fully customizable and agent ready
TypeScript
ci: install dependencies without the Actions cache (#9048)
Cindy Zhang7a94199e861c
diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.ymlindex ae43b2f89f..6a1290662e 100644--- a/.github/actions/setup/action.yml+++ b/.github/actions/setup/action.yml@@ -2,9 +2,9 @@name: 'Setup Node and pnpm'description: >-- Install pnpm, set up Node from .nvmrc with the pnpm store cached, and- optionally install workspace dependencies. Requires actions/checkout to have- run first — .nvmrc and the composite action itself are read from the+ Install pnpm, set up Node from .nvmrc, and optionally install workspace+ dependencies from the registry (no Actions cache). Requires actions/checkout+ to have run first — .nvmrc and the composite action itself are read from thechecked-out tree.inputs:@@ -22,9 +22,8 @@ inputs:runs:using: compositesteps:- # pnpm has to be on PATH before setup-node, otherwise `cache: pnpm` cannot- # resolve the store path. The version comes from package.json's- # `packageManager` field — never pin it here as well.+ # The pnpm version comes from package.json's `packageManager` field —+ # never pin it here as well.## SHA-pinned like the repo's other third-party actions (crowdin,# peter-evans): this composite also runs inside the npm publish jobs, so a@@ -35,10 +34,16 @@ runs:# .nvmrc is the single source of truth for the Node version, shared with# local nvm / fnm / mise. The 24.x line also bundles npm >= 11.5.1, which# release.yml requires for OIDC trusted publishing.+ #+ # No dependency cache. The pnpm store is ~245 MB and nearly every job+ # restored it, so one pull request run pulled several GB from the Actions+ # cache and hit its egress limit; a refused or throttled restore then+ # stalled setup for up to ten minutes. A cold `pnpm install` from the+ # registry takes about 13 s, so the cache saved little even when it worked.- uses: actions/setup-node@v7with:node-version-file: .nvmrc- cache: pnpm+ package-manager-cache: falseregistry-url: ${{ inputs.registry-url }}- if: inputs.install == 'true'diff --git a/.github/scripts/ci-no-dependency-cache.test.mjs b/.github/scripts/ci-no-dependency-cache.test.mjsnew file mode 100644index 0000000000..1799fed9d8--- /dev/null+++ b/.github/scripts/ci-no-dependency-cache.test.mjs@@ -0,0 +1,63 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Contract: CI jobs install dependencies without the Actions cache.+ * @input .github/actions/setup/action.yml and every workflow under .github/workflows+ * @output Each setup-node use and actions/cache use against the no-cache rule+ * @position Node contract for the repository's Actions cache egress+ *+ * The pnpm store is ~245 MB and nearly every job restored it, so one pull+ * request run pulled several GB from the Actions cache. That hit the cache's+ * egress limit; a refused or throttled restore then stalled job setup for up to+ * ten minutes, pushing jobs past their time budget. A cold `pnpm install` from+ * the registry takes about 13 s, so jobs install without a dependency cache.+ */++import fs from 'node:fs';+import path from 'node:path';+import {describe, expect, it} from 'vitest';+import yaml from 'yaml';++const root = path.resolve(import.meta.dirname, '../..');+const read = rel => yaml.parse(fs.readFileSync(path.join(root, rel), 'utf8'));++const workflowDir = path.join(root, '.github/workflows');+const workflowFiles = fs+ .readdirSync(workflowDir)+ .filter(name => name.endsWith('.yml') || name.endsWith('.yaml'))+ .map(name => `.github/workflows/${name}`);++/** Every step of every job in a workflow, or of a composite action. */+function stepsOf(doc) {+ if (doc.runs?.steps) {+ return doc.runs.steps;+ }+ return Object.values(doc.jobs ?? {}).flatMap(job => job.steps ?? []);+}++const sources = ['.github/actions/setup/action.yml', ...workflowFiles];++describe('dependency cache', () => {+ it('turns off setup-node package caching in the shared setup action', () => {+ const setupNode = stepsOf(read('.github/actions/setup/action.yml')).find(+ step => String(step.uses ?? '').startsWith('actions/setup-node@'),+ );+ expect(setupNode).toBeDefined();+ expect(setupNode.with?.cache).toBeUndefined();+ expect(setupNode.with?.['package-manager-cache']).toBe(false);+ });++ it.each(sources)('%s restores no dependency cache', rel => {+ for (const step of stepsOf(read(rel))) {+ const uses = String(step.uses ?? '');+ if (uses.startsWith('actions/setup-node@')) {+ expect(step.with?.cache, `${rel}: setup-node cache`).toBeUndefined();+ }+ expect(+ uses.startsWith('actions/cache@') ||+ uses.startsWith('actions/cache/restore@'),+ `${rel}: actions/cache step`,+ ).toBe(false);+ }+ });+});