-
Notifications
You must be signed in to change notification settings - Fork 280
ci: cache Bun package downloads #632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,13 @@ jobs: | |
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - uses: oven-sh/setup-bun@v2 | ||
| id: setup-bun | ||
|
|
||
| - name: Restore installed dependencies | ||
| uses: actions/cache@v6 | ||
| with: | ||
| path: node_modules | ||
| key: bun-node-modules-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-bun.outputs.bun-version }}-${{ hashFiles('bun.lock', 'package.json', 'bunfig.toml', 'scripts/check-expo-version.js') }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: printf '%s\n' '--- .github/workflows/lint.yml ---'
sed -n '1,55p' .github/workflows/lint.yml
printf '%s\n' '--- .github/workflows/test.yml ---'
sed -n '1,60p' .github/workflows/test.yml
printf '%s\n' '--- cache configuration references ---'
rg -n -C 3 'actions/cache|restore-keys|bun-node-modules|hashFiles' .github/workflows/lint.yml .github/workflows/test.ymlRepository: reactnativecn/react-native-update Length of output: 4253 🌐 Web query:
💡 Result: In GitHub Actions, the Citations:
Restore a compatible prefix cache in both workflows. When the hashed inputs change, 🧰 Tools🪛 zizmor (1.29.0)[warning] 18-38: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block (excessive-permissions) 📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
| - name: Install Dependency | ||
| run: bun install --frozen-lockfile | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: reactnativecn/react-native-update
Length of output: 23733
🏁 Script executed:
Repository: reactnativecn/react-native-update
Length of output: 43107
🌐 Web query:
Bun documentation bun install node_modules cache CI cache global cache lifecycle scripts platform-specific packages💡 Result:
Bun's installation process is highly optimized for performance and security. Below is a summary of its key behaviors and best practices. Global Cache Bun uses a global cache to store downloaded packages, typically located at ~/.bun/install/cache [1]. Each package version is stored in its own subdirectory [1]. When you run bun install, Bun checks this cache before downloading files from the registry [1]. To speed up deployments in CI/CD, it is recommended to cache this specific directory (e.g., using GitHub Actions' actions/cache) rather than node_modules, as Bun is generally fast enough to reconstruct node_modules from the cache [2]. Lifecycle Scripts Bun is secure by default and does not execute arbitrary lifecycle scripts (like postinstall) [3][4]. Instead, it uses an allowlist for trusted packages [3][4]. To enable lifecycle scripts for a specific package, add its name to the trustedDependencies array in your package.json [3][4]. You can also use bun pm trust to add a package to this list automatically [4]. To globally disable all scripts, use the --ignore-scripts flag or configure install.ignoreScripts in bunfig.toml [3]. Platform-Specific Packages Bun supports filtering dependencies based on architecture and OS through flags like --os, --cpu, and --libc [5][6][7]. This is particularly useful in environments like Docker or cross-compilation, as it prevents the installation of unnecessary platform-specific binary variants (e.g., glibc vs musl on Linux) [6][7]. These constraints are recorded in the lockfile, ensuring subsequent installs (such as --frozen-lockfile) remain consistent [6][7]. CI/CD Best Practices For reproducible and deterministic builds in CI/CD, use bun ci [8]. This command is equivalent to bun install --frozen-lockfile and will fail if the lockfile is out of sync with package.json [8]. By caching the global cache directory and ensuring a lockfile is present, you can achieve efficient, network-minimized installs [8][2]. Global Virtual Store Bun also supports a global virtual store, which allows projects to share a single copy of common packages on disk, reducing storage usage [9]. This is off by default and can be enabled by setting globalStore = true or using the BUN_INSTALL_GLOBAL_STORE environment variable [9].
Citations:
Cache Bun’s global install cache in both workflows.
The cache keys omit the runner image and libc, while
bun.lockincludes platform-specific packages such as Biome, TypeScript, andunrs-resolverbindings. A cache hit can restorenode_modulesbuilt for an older runner environment beforebun install --frozen-lockfileruns. Cache~/.bun/install/cacheinstead in.github/workflows/lint.ymland.github/workflows/test.yml.🧰 Tools
🪛 zizmor (1.29.0)
[warning] 18-38: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block
(excessive-permissions)
📍 Affects 2 files
.github/workflows/lint.yml#L30-L30(this comment).github/workflows/test.yml#L31-L31🤖 Prompt for AI Agents