Skip to content

Commit eb2878a

Browse files
committed
fix(build): improve asset download resilience against rate limits
- Increase GitHub release cache TTL from 1h to 4h to reduce API calls - Use exponential backoff (factor 2) instead of linear retries - Add SKIP_ASSET_DOWNLOAD env var to skip downloads when assets are already cached locally (avoids rate limit exhaustion during repeated local builds and pre-commit hook reruns) - Simplify cli package.json placeholder version to 0.0.0
1 parent 0bb60bb commit eb2878a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

packages/build-infra/lib/github-releases.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { pRetry } from '@socketsecurity/lib/promises'
1212

1313
const logger = getDefaultLogger()
1414

15-
// Cache GitHub API responses for 1 hour to avoid rate limiting.
15+
// Cache GitHub API responses for 4 hours to reduce API calls and avoid rate limiting.
1616
const cache = createTtlCache({
1717
memoize: true,
1818
prefix: 'github-releases',
19-
ttl: 60 * 60 * 1000, // 1 hour.
19+
ttl: 4 * 60 * 60 * 1000, // 4 hours.
2020
})
2121

2222
/**
@@ -155,8 +155,8 @@ export async function getLatestRelease(
155155
return null
156156
},
157157
{
158-
backoffFactor: 1,
159-
baseDelayMs: 5_000,
158+
backoffFactor: 2,
159+
baseDelayMs: 3_000,
160160
onRetry: (attempt, error) => {
161161
if (!quiet) {
162162
logger.info(
@@ -231,8 +231,8 @@ export async function getReleaseAssetUrl(
231231
return asset.browser_download_url
232232
},
233233
{
234-
backoffFactor: 1,
235-
baseDelayMs: 5_000,
234+
backoffFactor: 2,
235+
baseDelayMs: 3_000,
236236
onRetry: (attempt, error) => {
237237
if (!quiet) {
238238
logger.info(` Retry attempt ${attempt + 1}/3 for asset URL...`)

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@socketsecurity/cli",
3-
"version": "0.0.0-copied-from-packages-socket",
3+
"version": "0.0.0",
44
"description": "CLI for Socket.dev",
55
"private": true,
66
"license": "MIT",

packages/cli/scripts/download-assets.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ async function downloadAssets(assetNames, parallel = true) {
231231
* Main entry point.
232232
*/
233233
async function main() {
234+
// Skip downloads entirely when SKIP_ASSET_DOWNLOAD is set.
235+
// Useful for repeated local builds where assets are already cached,
236+
// or when GitHub API rate limits are exhausted.
237+
if (process.env.SKIP_ASSET_DOWNLOAD) {
238+
logger.info('Skipping asset downloads (SKIP_ASSET_DOWNLOAD is set)')
239+
return
240+
}
241+
234242
const args = process.argv.slice(2)
235243
const parallel = !args.includes('--no-parallel')
236244
const assetArgs = args.filter(arg => !arg.startsWith('--'))

0 commit comments

Comments
 (0)