Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ inputs:
description: Cache repositories based on MODULE.bazel/WORKSPACE
required: false
default: "false"
cache-restore-timeout:
description: Timeout in milliseconds for each cache restore operation (download + extraction). Set to 0 to disable.
required: false
default: "0"
token:
description: GitHub token to query Bazelisk releases
required: false
Expand Down
3 changes: 3 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,15 @@ if (externalCacheConfig) {
}
}

const cacheRestoreTimeoutMs = parseInt(core.getInput('cache-restore-timeout')) || 0

const token = core.getInput('token')
core.exportVariable('BAZELISK_GITHUB_TOKEN', token)

export default {
baseCacheKey,
cacheSave,
cacheRestoreTimeoutMs,
bazeliskCache: {
enabled: core.getBooleanInput('bazelisk-cache'),
files: [`${moduleRoot}/.bazelversion`],
Expand Down
25 changes: 22 additions & 3 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128381,12 +128381,15 @@ if (externalCacheConfig) {
}
}

const cacheRestoreTimeoutMs = parseInt(getInput('cache-restore-timeout')) || 0

const token = getInput('token')
exportVariable('BAZELISK_GITHUB_TOKEN', token)

/* harmony default export */ const config = ({
baseCacheKey,
cacheSave,
cacheRestoreTimeoutMs,
bazeliskCache: {
enabled: getBooleanInput('bazelisk-cache'),
files: [`${moduleRoot}/.bazelversion`],
Expand Down Expand Up @@ -128581,20 +128584,36 @@ async function index_restoreCache(cacheConfig) {
await (0,promises_namespaceObject.setTimeout)(delay)

startGroup(`Restore cache for ${cacheConfig.name}`)
const name = cacheConfig.name
try {
const hash = await glob_hashFiles(cacheConfig.files.join('\n'))
const name = cacheConfig.name
const paths = cacheConfig.paths
const restoreKey = `${config.baseCacheKey}-${name}-`
const key = `${restoreKey}${hash}`

core_debug(`Attempting to restore ${name} cache from ${key}`)

const restoredKey = await restoreCache(
const restorePromise = restoreCache(
paths, key, [restoreKey],
{ segmentTimeoutInMs: 300000 } // 5 minutes
{ segmentTimeoutInMs: 300000 } // 5 minutes per download segment
)

let restoredKey
if (config.cacheRestoreTimeoutMs > 0) {
const ac = new AbortController()
const timeoutPromise = (0,promises_namespaceObject.setTimeout)(config.cacheRestoreTimeoutMs, null, { signal: ac.signal })
.then(() => { throw new Error(`Timed out restoring ${name} cache after ${config.cacheRestoreTimeoutMs}ms`) })
timeoutPromise.catch(() => {})

try {
restoredKey = await Promise.race([restorePromise, timeoutPromise])
} finally {
ac.abort()
}
} else {
restoredKey = await restorePromise
}

if (restoredKey) {
info(`Successfully restored cache from ${restoredKey}`)

Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127583,12 +127583,15 @@ if (externalCacheConfig) {
}
}

const cacheRestoreTimeoutMs = parseInt(getInput('cache-restore-timeout')) || 0

const token = getInput('token')
exportVariable('BAZELISK_GITHUB_TOKEN', token)

/* harmony default export */ const config = ({
baseCacheKey,
cacheSave,
cacheRestoreTimeoutMs,
bazeliskCache: {
enabled: getBooleanInput('bazelisk-cache'),
files: [`${moduleRoot}/.bazelversion`],
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,27 @@ async function restoreCache(cacheConfig) {

core.debug(`Attempting to restore ${name} cache from ${key}`)

const restoredKey = await cache.restoreCache(
const restorePromise = cache.restoreCache(
paths, key, [restoreKey],
{ segmentTimeoutInMs: 300000 } // 5 minutes
{ segmentTimeoutInMs: 300000 } // 5 minutes per download segment
)

let restoredKey
if (config.cacheRestoreTimeoutMs > 0) {
const ac = new AbortController()
const timeoutPromise = setTimeout(config.cacheRestoreTimeoutMs, null, { signal: ac.signal })
.then(() => { throw new Error(`Timed out restoring ${name} cache after ${config.cacheRestoreTimeoutMs}ms`) })
timeoutPromise.catch(() => {})

try {
restoredKey = await Promise.race([restorePromise, timeoutPromise])
} finally {
ac.abort()
}
} else {
restoredKey = await restorePromise
}

if (restoredKey) {
core.info(`Successfully restored cache from ${restoredKey}`)

Expand Down
Loading