@ambi-robotics/cache v1.3.2
@ambi-robotics/cache
This package provides a drop-in replacement for the Github Actions cache toolkit functions, but allows for the use of S3-like storage backends (e.g. Minio) via environment variable configurations.
The work here is based in part on this github action.
Usage
Save Cache
Saves a cache containing the files in paths using the key provided. The
files would be compressed using zstandard compression algorithm if zstd is
installed, otherwise gzip is used. Function returns the cache id if the cache
was saved succesfully and throws an error if cache upload fails.
const cache = require('@ambi-robotics/cache')
const paths = ['node_modules', 'packages/*/node_modules/']
const key = 'npm-foobar-d5ea0750'
const cacheId = await cache.saveCache(paths, key, undefined, false, {
bucket: 'actions-cache', // required
port: 9000, // optional, default is 9000
endPoint: 'play.min.io', // optional, default s3.amazon.aws
accessKey: 'ASDFJKL', // required
secretKey: 'zud+sdfjkewf', // required
sessionToken: 'AQoDY', // optional
region: 'us-east-1', // optional
useSSL: true // optional, use http instead of https
})Restore Cache
Restores a cache based on key and restoreKeys to the paths provided.
Function returns the cache key for cache hit and returns undefined if cache not
found.
const cache = require('@actions/cache')
const paths = ['node_modules', 'packages/*/node_modules/']
const key = 'npm-foobar-d5ea0750'
const restoreKeys = ['npm-foobar-', 'npm-']
const cacheKey = await cache.restoreCache(
paths,
key,
restoreKeys,
undefined,
false,
{
bucket: 'actions-cache', // required
port: 9000, // optional, default is 9000
endPoint: 'play.min.io', // optional, default s3.amazon.aws
accessKey: 'ASDFJKL', // required
secretKey: 'zud+sdfjkewf', // required
sessionToken: 'AQoDY', // optional
region: 'us-east-1', // optional
useSSL: true // optional, use http instead of https
}
)Environment Variables
Rather than providing the S3 or minio configuration in each function call, you can set environment variables for the main parameters.
bucket:ALT_GHA_CACHE_BUCKETport:ALT_GHA_CACHE_PORTaccessKey:ALT_GHA_CACHE_ACCESS_KEYorAWS_ACCESS_KEY_IDsecretKey:ALT_GHA_CACHE_SECRET_KEYorAWS_SECRET_ACCESS_KEYsessionToken:ALT_GHA_CACHE_SESSION_TOKENorAWS_SESSION_TOKENregion:ALT_GHA_CACHE_REGIONorAWS_REGIONuseSSL:ALT_GHA_CACHE_USE_SSL