🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
👷 ci(deps): cache the pnpm store for every workflow through setup-env (#23368)
Inneid1dbfdbb822d
diff --git a/.github/actions/desktop-build-setup/action.yml b/.github/actions/desktop-build-setup/action.ymlindex 4d8c306c539..5ebc1bfb963 100644--- a/.github/actions/desktop-build-setup/action.yml+++ b/.github/actions/desktop-build-setup/action.yml@@ -121,17 +121,9 @@ runs:echo "CLOUD_DESKTOP=1" >> "$GITHUB_ENV"echo "✅ Cloud repository $resolved_cloud_ref overlaid at $cloud_root"- # Shared with the isolated desktop install below. The root `pnpm-lock.yaml` is- # gitignored, so hash the tracked dependency declarations — hashing an absent- # file would pin one key forever and stop the store from ever taking new tarballs.- - name: Cache pnpm store- uses: actions/cache@v4- with:- path: ${{ runner.temp }}/pnpm-store- key: pnpm-store-${{ runner.os }}-v1-${{ hashFiles('package.json', 'pnpm-workspace.yaml', 'apps/*/package.json', 'packages/*/package.json', 'patches/*.patch', 'apps/desktop/pnpm-lock.yaml') }}- restore-keys: |- pnpm-store-${{ runner.os }}-v1--+ # The pnpm store is cached by setup-env. The root `pnpm-lock.yaml` is gitignored+ # and the overlay root has none, so the merged workspace is re-resolved on every+ # run; the store is what saves the tarball downloads.- name: Install dependenciesshell: bashrun: |@@ -139,7 +131,7 @@ runs:if [ "${CLOUD_DESKTOP:-}" = "1" ]; thencd ..fi- pnpm install --node-linker=hoisted --store-dir "$RUNNER_TEMP/pnpm-store" --prefer-offline+ pnpm install --node-linker=hoisted# 移除国内 electron 镜像配置,GitHub Actions 使用官方源更快- name: Remove China electron mirror from .npmrc@@ -154,10 +146,6 @@ runs:- name: Install deps on Desktopshell: bash- env:- # Reuse the store restored above instead of the ephemeral global one.- # pnpm reads its own `pnpm_config_*` env namespace, not `npm_config_*`.- pnpm_config_store_dir: ${{ runner.temp }}/pnpm-storerun: |set -euo pipefailif [ "${CLOUD_DESKTOP:-}" = "1" ]; thendiff --git a/.github/actions/overlay-type-check/action.yml b/.github/actions/overlay-type-check/action.ymlindex 8b90d50dd01..631fdbf2b80 100644--- a/.github/actions/overlay-type-check/action.yml+++ b/.github/actions/overlay-type-check/action.yml@@ -36,21 +36,13 @@ runs:overlay-ref: ${{ inputs.overlay-ref }}overlay-token: ${{ inputs.overlay-token }}- # The overlay root ships no lockfile, so pnpm resolves from package.json ranges- # on every run. The root `pnpm-lock.yaml` is gitignored, so the key hashes the- # tracked dependency declarations instead — hashing an absent file would pin one- # key forever and stop the store from ever taking new tarballs.- - name: Cache pnpm store- uses: actions/cache@v4- with:- path: ${{ runner.temp }}/pnpm-store- key: pnpm-store-${{ runner.os }}-v1-${{ hashFiles('package.json', 'pnpm-workspace.yaml', 'apps/*/package.json', 'packages/*/package.json', 'patches/*.patch', 'apps/desktop/pnpm-lock.yaml') }}- restore-keys: |- pnpm-store-${{ runner.os }}-v1--+ # The pnpm store is cached by setup-env, which caches the default store this+ # install uses. The overlay root ships no lockfile, so pnpm resolves from the+ # package.json ranges on every run; the content-addressed store is what saves+ # the tarball downloads.- name: Install dependenciesshell: bash- run: cd .. && pnpm install --node-linker=hoisted --store-dir "$RUNNER_TEMP/pnpm-store" --prefer-offline+ run: cd .. && pnpm install --node-linker=hoisted- name: Type check overlaid sourcesshell: bashdiff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.ymlindex 8e2544f12ec..9914a574582 100644--- a/.github/actions/setup-env/action.yml+++ b/.github/actions/setup-env/action.yml@@ -6,10 +6,6 @@ inputs:description: Node.js versionrequired: falsedefault: '24.11.1'- package-manager-cache:- description: Pass-through to actions/setup-node package-manager-cache- required: false- default: 'false'bun-version:description: Bun versionrequired: false@@ -28,8 +24,19 @@ runs:with:bun-version: ${{ inputs.bun-version }}+ # setup-node only caches pnpm when `cache` is set explicitly; its automatic+ # caching covers npm alone. The root `pnpm-lock.yaml` is gitignored, so the+ # dependency path has to name the tracked declarations — a missing file makes+ # the action fail rather than cache nothing.- name: Setup Node.jsuses: actions/setup-node@v6with:+ cache: pnpm+ cache-dependency-path: |+ package.json+ pnpm-workspace.yaml+ apps/*/package.json+ packages/*/package.json+ patches/*.patch+ apps/desktop/pnpm-lock.yamlnode-version: ${{ inputs.node-version }}- package-manager-cache: ${{ inputs.package-manager-cache }}diff --git a/.github/scripts/desktop-overlay-type-check.test.mjs b/.github/scripts/desktop-overlay-type-check.test.mjsindex 9051094bb5b..28a29515a65 100644--- a/.github/scripts/desktop-overlay-type-check.test.mjs+++ b/.github/scripts/desktop-overlay-type-check.test.mjs@@ -1,25 +1,11 @@import assert from 'node:assert/strict';-import { execFileSync } from 'node:child_process';import { readFile } from 'node:fs/promises';import { test } from 'node:test';-import { fileURLToPath } from 'node:url';import { parse } from 'yaml';const load = async (path) => parse(await readFile(new URL(path, import.meta.url), 'utf8'));-const repoRoot = fileURLToPath(new URL('../..', import.meta.url));--/** CI only checks out tracked files, so a gitignored file hashes to nothing there. */-const isIgnored = (file) => {- try {- execFileSync('git', ['check-ignore', '--quiet', file], { cwd: repoRoot });- return true;- } catch {- return false;- }-};-const needsOf = (job) => [job.needs ?? []].flat();const stepUsing = (job, action) => job.steps.find((step) => step.uses === action);@@ -100,39 +86,3 @@ test('every pull request gets the overlay check, not only desktop builds', asyncassert.doesNotMatch(String(job.if ?? ''), /trigger:build-desktop|release\//);assert.ok([workflow.on.pull_request.types].flat().includes('opened'));});--for (const path of [- '../actions/overlay-type-check/action.yml',- '../actions/desktop-build-setup/action.yml',-]) {- test(`${path} installs from a cached pnpm store`, async () => {- const { runs } = await load(path);- const cache = stepUsing(runs, 'actions/cache@v4');- const install = runs.steps.find((step) =>- /pnpm install --node-linker=hoisted/.test(step.run ?? ''),- );-- assert.ok(cache, 'the store is cached');- assert.match(String(cache.with.path), /pnpm-store/);- assert.ok(- runs.steps.indexOf(cache) < runs.steps.indexOf(install),- 'the store is restored before install',- );- // The overlay root has no lockfile, so the store path must be passed explicitly.- assert.match(String(install.run), /--store-dir "\$RUNNER_TEMP\/pnpm-store"/);- assert.match(String(install.run), /--prefer-offline/);-- const hashed = String(cache.with.key)- .match(/hashFiles\(([^)]*)\)/)[1]- .split(',')- .map((entry) => entry.trim().replaceAll("'", ''));-- assert.ok(- hashed.some((entry) => entry.includes('package.json')),- 'the key follows dependency declarations',- );- for (const file of hashed.filter((entry) => !entry.includes('*'))) {- assert.ok(!isIgnored(file), `${file} is gitignored, so CI would hash nothing`);- }- });-}diff --git a/.github/scripts/setup-env-cache.test.mjs b/.github/scripts/setup-env-cache.test.mjsnew file mode 100644index 00000000000..e9c97642089--- /dev/null+++ b/.github/scripts/setup-env-cache.test.mjs@@ -0,0 +1,59 @@+import assert from 'node:assert/strict';+import { execFileSync } from 'node:child_process';+import { readFile } from 'node:fs/promises';+import { test } from 'node:test';+import { fileURLToPath } from 'node:url';++import { parse } from 'yaml';++const load = async (path) => parse(await readFile(new URL(path, import.meta.url), 'utf8'));++const repoRoot = fileURLToPath(new URL('../..', import.meta.url));++const dependencyPaths = (node) =>+ String(node.with['cache-dependency-path'] ?? '')+ .split('\n')+ .map((line) => line.trim())+ .filter(Boolean);++/** CI only checks out tracked files, so a gitignored file hashes to nothing there. */+const isIgnored = (file) => {+ try {+ execFileSync('git', ['check-ignore', '--quiet', file], { cwd: repoRoot });+ return true;+ } catch {+ return false;+ }+};++test('setup-env caches the pnpm store from files CI actually checks out', async () => {+ const { runs } = await load('../actions/setup-env/action.yml');+ const node = runs.steps.find((step) => step.uses === 'actions/setup-node@v6');+ const paths = dependencyPaths(node);++ // setup-node caches pnpm only when `cache` is set; its automatic caching is npm-only.+ assert.equal(node.with.cache, 'pnpm');+ assert.ok(+ paths.some((path) => path.endsWith('package.json')),+ 'the key follows dependency declarations',+ );+ for (const file of paths.filter((path) => !path.includes('*'))) {+ assert.ok(!isIgnored(file), `${file} is gitignored, so CI would hash nothing`);+ }+});++test('the overlay composites leave the store cache to setup-env', async () => {+ for (const action of ['overlay-type-check', 'desktop-build-setup']) {+ const { runs } = await load(`../actions/${action}/action.yml`);+ const ownCache = runs.steps.find((step) => String(step.uses ?? '').startsWith('actions/cache'));+ const storeDir = runs.steps.find((step) => String(step.run ?? '').includes('--store-dir'));++ assert.ok(+ runs.steps.some((step) => step.uses === './.github/actions/setup-env'),+ `${action} must set up the environment that caches the store`,+ );+ // A second cache step or store override would cache the same content twice.+ assert.equal(ownCache, undefined, `${action} must not cache its own store`);+ assert.equal(storeDir, undefined, `${action} must use the cached default store`);+ }+});diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex bf215cf406a..56f81b03ee4 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -89,7 +89,7 @@ jobs:run: node --test .github/scripts/hotfixWorkflow.test.mjs- name: Verify desktop release workflows- run: node --test .github/scripts/desktop-publish-s3.test.mjs .github/scripts/release-desktop-canary.test.mjs .github/scripts/desktop-overlay-type-check.test.mjs .github/scripts/overlayTypeErrors.test.mjs+ run: node --test .github/scripts/desktop-publish-s3.test.mjs .github/scripts/release-desktop-canary.test.mjs .github/scripts/desktop-overlay-type-check.test.mjs .github/scripts/overlayTypeErrors.test.mjs .github/scripts/setup-env-cache.test.mjs- name: Test CLI build configuration, bundle and model-facing docsrun: bunx vitest run --config vitest.config.mts --silent='passed-only' tsdown.config.test.ts bundle.test.ts src/modelFacingDocs.test.ts