Skip to content

Commit b0f026b

Browse files
authored
ci: improve cache keys, observability, and node_modules caching strategy (RocketChat#39709)
1 parent dd55029 commit b0f026b

File tree

4 files changed

+82
-34
lines changed

4 files changed

+82
-34
lines changed

.github/actions/meteor-build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inputs:
2222
type: string
2323
source-hash:
2424
required: true
25-
description: 'Source code hash'
25+
description: 'RC cache id (e.g. packages-build-cache-key + meteor apps/meteor archive hash from CI)'
2626
type: string
2727

2828
runs:

.github/actions/setup-node/action.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,48 @@ outputs:
3333
node-version:
3434
description: 'Node version'
3535
value: ${{ steps.node-version.outputs.node-version }}
36+
cache-deno-hit:
37+
description: 'Exact key hit for Deno cache'
38+
value: ${{ steps.cache-deno.outputs.cache-hit }}
3639

3740
runs:
3841
using: composite
3942

4043
steps:
41-
- name: Cache Node Modules & Deno
44+
# Turbo local cache: use rharkor/caching-for-turbo in workflows — not stored here to avoid huge redundant keys.
45+
- name: Cache Deno (apps-engine)
4246
if: inputs.cache-modules
43-
id: cache-node-modules
47+
id: cache-deno
4448
uses: actions/cache@v5
4549
with:
46-
# We need to cache node_modules for all workspaces with "hoistingLimits" defined
47-
path: |
48-
.turbo/cache
49-
node_modules
50-
apps/meteor/node_modules
51-
apps/meteor/ee/server/services/node_modules
52-
packages/apps-engine/node_modules
53-
packages/apps-engine/.deno-cache
54-
key: node-modules-${{ inputs.type }}-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('package.json') }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles('.yarnrc.yml') }}-deno-v${{ inputs.deno-version }}-${{ hashFiles('packages/apps-engine/deno-runtime/deno.lock') }}-v5
55-
# key: node-modules-${{ inputs.type }}-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('package.json') }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles('.yarnrc.yml') }}-deno-v${{ inputs.deno-version }}-${{ hashFiles('packages/apps-engine/deno-runtime/deno.lock') }}-v${{ github.run_id }}
56-
#
57-
# Could use this command to list all paths to save:
58-
# find . -name 'node_modules' -prune | grep -v "/\.meteor/" | grep -v "/meteor/packages/"
50+
path: packages/apps-engine/.deno-cache
51+
key: deno-${{ runner.os }}-${{ runner.arch }}-v${{ inputs.deno-version }}-${{ hashFiles('packages/apps-engine/deno-runtime/deno.lock') }}
52+
restore-keys: |
53+
deno-${{ runner.os }}-${{ runner.arch }}-v${{ inputs.deno-version }}-
5954
6055
- name: Use Node.js ${{ inputs.node-version }}
6156
id: node-version
6257
uses: actions/setup-node@v6.0.0
6358
with:
6459
node-version: ${{ inputs.node-version }}
65-
cache: 'yarn'
60+
cache: ${{ inputs.cache-modules && 'yarn' || '' }}
6661

6762
- name: Use Deno ${{ inputs.deno-version }}
6863
uses: denoland/setup-deno@v1
6964
with:
7065
deno-version: ${{ inputs.deno-version }}
7166

67+
- name: Cache mongodb-memory-server binary
68+
if: inputs.cache-modules
69+
uses: actions/cache@v5
70+
with:
71+
path: ${{ runner.temp }}/mongodb-memory-server
72+
key: mongoms-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
73+
7274
- name: Configure mongodb-memory-server cache
7375
shell: bash
7476
run: |
75-
CACHE_DIR="${GITHUB_WORKSPACE}/node_modules/.cache/mongodb-memory-server"
77+
CACHE_DIR="${{ runner.temp }}/mongodb-memory-server"
7678
mkdir -p "$CACHE_DIR"
7779
echo "MONGOMS_DOWNLOAD_DIR=$CACHE_DIR" >> $GITHUB_ENV
7880
echo "MONGOMS_PREFER_GLOBAL_PATH=false" >> $GITHUB_ENV

.github/workflows/ci-code-check.yml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,21 @@ jobs:
4545

4646
- uses: ./.github/actions/restore-packages
4747

48-
- name: Cache TypeCheck
49-
uses: actions/cache@v5
48+
- name: Restore TypeScript incremental cache
49+
id: restore-typecheck
50+
if: matrix.check == 'ts'
51+
uses: actions/cache/restore@v5
5052
with:
5153
path: ./apps/meteor/tsconfig.typecheck.tsbuildinfo
52-
key: typecheck-cache-${{ runner.OS }}-${{ hashFiles('yarn.lock') }}-${{ github.event.issue.number }}
54+
key: typecheck-cache-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
5355
restore-keys: |
54-
typecheck-cache-${{ runner.OS }}-${{ hashFiles('yarn.lock') }}
55-
typecheck-cache-${{ runner.OS }}
56-
typecheck-cache
56+
typecheck-cache-${{ runner.os }}-
57+
58+
- name: Cache observability (typecheck)
59+
if: matrix.check == 'ts'
60+
run: |
61+
echo "### TypeScript incremental cache" >> $GITHUB_STEP_SUMMARY
62+
echo "- **exact hit**: \`${{ steps.restore-typecheck.outputs.cache-hit }}\`" >> $GITHUB_STEP_SUMMARY
5763
5864
- name: Install Meteor
5965
shell: bash
@@ -79,17 +85,36 @@ jobs:
7985
if: matrix.check == 'ts'
8086
run: yarn turbo run typecheck --concurrency=5
8187

82-
- name: Cache eslint
83-
uses: actions/cache@v5
88+
- name: Save TypeScript incremental cache
89+
if: matrix.check == 'ts' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
90+
uses: actions/cache/save@v5
91+
with:
92+
path: ./apps/meteor/tsconfig.typecheck.tsbuildinfo
93+
key: typecheck-cache-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
94+
95+
- name: Restore ESLint cache
96+
id: restore-eslint
8497
if: matrix.check == 'lint'
98+
uses: actions/cache/restore@v5
8599
with:
86100
path: ./apps/meteor/.eslintcache
87-
key: eslintcache-cache-${{ runner.OS }}-${{ hashFiles('yarn.lock') }}-${{ github.event.issue.number }}
101+
key: eslintcache-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
88102
restore-keys: |
89-
eslintcache-cache-${{ runner.OS }}-${{ hashFiles('yarn.lock') }}
90-
eslintcache-cache-${{ runner.OS }}
91-
eslintcache-cache
103+
eslintcache-${{ runner.os }}-
104+
105+
- name: Cache observability (eslint)
106+
if: matrix.check == 'lint'
107+
run: |
108+
echo "### ESLint cache" >> $GITHUB_STEP_SUMMARY
109+
echo "- **exact hit**: \`${{ steps.restore-eslint.outputs.cache-hit }}\`" >> $GITHUB_STEP_SUMMARY
92110
93111
- name: Lint
94112
if: matrix.check == 'lint'
95113
run: yarn lint
114+
115+
- name: Save ESLint cache
116+
if: matrix.check == 'lint' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
117+
uses: actions/cache/save@v5
118+
with:
119+
path: ./apps/meteor/.eslintcache
120+
key: eslintcache-${{ runner.os }}-${{ hashFiles('yarn.lock') }}

.github/workflows/ci.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
node-version: ${{ steps.var.outputs.node-version }}
3434
deno-version: ${{ steps.var.outputs.deno-version }}
3535
source-hash: ${{ steps.source.outputs.hash }}
36+
packages-build-cache-key: ${{ steps.ci-cache-keys.outputs.packages-build-cache-key }}
37+
meteor-rc-cache-key: ${{ steps.ci-cache-keys.outputs.meteor-rc-cache-key }}
3638
# this is 100% intentional, secrets are not available for forks, so ee-tests will always fail
3739
# to avoid this, we are using a dummy license, expiring at 2026-07-01
3840
enterprise-license: Uo7Jcr6WW0XYA8ydHd+Sk6pZ9/0V6dIASnyTwvUrNym/zJg2Ma3eYNKkC8osXLCc72y1ahohnWY7/+7IYkvono3GYXQR+IGvYbbrVgNR6OjMahd9P/odHZL1GFTm2qHrEL5Hh/XEOG+YluFeRdWPzCizQlp4zGGOi0+PkQo096TR9NVCLrsErVl2MW1WM6ZM1W5EUJG9pKly4BQnaOTUAlor1im6i8qPTDCKrISZfLiZEWuQKaPW/GE3mRKjQNjDh0CabX1N2S880pRRGoozBYAnp2NmFfrQW0+5ihKisBTIeMbMZ7K5NE5PkYU1nhQDcc+rpDHtwG9Ceg5X0J+oea3UfrPTmDON2aSI0iO22kvL6G7QI3fyrEIvJrMbxcNKxAFeQYgnjisw/b06+chWSG4jG686Fx58XrVS87dFhWL9WoGltsk1dJCntUQvI1sX6zOfpvyg1iWRnHfYDOrwoWlX57XMm29fWineEoqnOOTOVnA/uP+DKEhercQ9Xuo7Cr6zJxpQpwd03e7ODVjiEbTDqlkZE687rmxRCD4Wmu8L86WIl2xSEIajKLX301Ww5mz/FdLqk+Mg32lkW66W3azQKvJ1440NBrYxhpJ+dl9vSFMb3s1+xnz1cYUbjUcq9mARvORcgy5mLwKulmqT6Sq0Uvbv10YCO0TW0beXYW8=
@@ -91,6 +93,14 @@ jobs:
9193
echo "DENO_VERSION: ${DENO_VERSION}"
9294
echo "deno-version=${DENO_VERSION}" >> $GITHUB_OUTPUT
9395
96+
- id: ci-cache-keys
97+
run: |
98+
set -euo pipefail
99+
PACKAGES_HASH=$(cat yarn.lock .yarnrc.yml package.json turbo.json | sha256sum | awk '{print $1}')
100+
echo "packages-build-cache-key=${PACKAGES_HASH}" >> "$GITHUB_OUTPUT"
101+
METEOR_HASH=$(git archive HEAD apps/meteor | sha256sum | awk '{print $1}')
102+
echo "meteor-rc-cache-key=${METEOR_HASH}" >> "$GITHUB_OUTPUT"
103+
94104
- id: by-tag
95105
run: |
96106
if echo "$GITHUB_REF_NAME" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' ; then
@@ -175,10 +185,13 @@ jobs:
175185
with:
176186
path: |
177187
/tmp/RocketChat-packages-build.tar.gz
178-
key: ${{ runner.arch }}-${{ runner.os }}-packages-build-${{ needs.release-versions.outputs.source-hash }}
188+
key: ${{ runner.arch }}-${{ runner.os }}-packages-build-${{ needs.release-versions.outputs.packages-build-cache-key }}
179189

180-
- name: Debug cache-hit
181-
run: echo "cache-hit=${{ steps.packages-cache-build.outputs.cache-hit }}"
190+
- name: Cache observability (packages-build)
191+
run: |
192+
echo "### 📦 packages-build cache" >> $GITHUB_STEP_SUMMARY
193+
echo "- **hit**: \`${{ steps.packages-cache-build.outputs.cache-hit }}\`" >> $GITHUB_STEP_SUMMARY
194+
echo "- **key**: \`${{ needs.release-versions.outputs.packages-build-cache-key }}\`" >> $GITHUB_STEP_SUMMARY
182195
183196
- name: Set Swap Space
184197
uses: pierotofy/set-swap-space@master
@@ -190,6 +203,7 @@ jobs:
190203
if: steps.packages-cache-build.outputs.cache-hit != 'true'
191204

192205
- name: Setup NodeJS
206+
id: setup-node-packages
193207
uses: ./.github/actions/setup-node
194208
if: steps.packages-cache-build.outputs.cache-hit != 'true'
195209
with:
@@ -200,6 +214,13 @@ jobs:
200214
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
201215
HARDENED_MODE: '1'
202216

217+
- name: Cache observability (node_modules)
218+
if: steps.packages-cache-build.outputs.cache-hit != 'true'
219+
run: |
220+
echo "### 🟢 node_modules cache" >> $GITHUB_STEP_SUMMARY
221+
echo "- **deno cache hit**: \`${{ steps.setup-node-packages.outputs.cache-deno-hit }}\`" >> $GITHUB_STEP_SUMMARY
222+
echo "- **node_modules size**: \`$(du -sh node_modules 2>/dev/null | cut -f1 || echo 'n/a')\`" >> $GITHUB_STEP_SUMMARY
223+
203224
- name: Cache vite
204225
uses: actions/cache@v5
205226
if: steps.packages-cache-build.outputs.cache-hit != 'true'
@@ -259,7 +280,7 @@ jobs:
259280
with:
260281
node-version: ${{ needs.release-versions.outputs.node-version }}
261282
deno-version: ${{ needs.release-versions.outputs.deno-version }}
262-
source-hash: ${{ needs.release-versions.outputs.source-hash }}
283+
source-hash: ${{ needs.release-versions.outputs.packages-build-cache-key }}-${{ needs.release-versions.outputs.meteor-rc-cache-key }}
263284
type: ${{ matrix.type }}
264285

265286
build-gh-docker:

0 commit comments

Comments
 (0)