mirror of
https://github.com/julia-actions/setup-julia.git
synced 2026-02-20 15:06:54 +08:00
Cache artifacts directory by default
This commit is contained in:
25
src/caching.ts
Normal file
25
src/caching.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as cache from '@actions/cache'
|
||||
import * as glob from '@actions/glob'
|
||||
|
||||
import * as path from 'path'
|
||||
|
||||
// TODO: Change to hashFiles once https://github.com/actions/toolkit/issues/472 has been resolved
|
||||
import * as md5File from 'md5-file'
|
||||
|
||||
const JULIA_HOME = path.join(`${process.env.HOME}`, '.julia')
|
||||
|
||||
/**
|
||||
* Cache the ~/.julia/artifacts directory.
|
||||
*/
|
||||
export async function cacheArtifacts(): Promise<number> {
|
||||
const projectFiles = await (await glob.create('**/Project.toml')).glob()
|
||||
let projectsHash = ''
|
||||
projectFiles.forEach((f) => {
|
||||
projectsHash.concat('-', md5File.sync(f))
|
||||
})
|
||||
|
||||
const paths = [path.join(JULIA_HOME, 'artifacts')]
|
||||
const key = `artifacts-${process.env.RUNNER_OS}-${projectsHash}`
|
||||
|
||||
return cache.saveCache(paths, key)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import * as tc from '@actions/tool-cache'
|
||||
import * as path from 'path'
|
||||
|
||||
import * as installer from './installer'
|
||||
import * as jlcache from './caching'
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
@@ -39,6 +40,13 @@ async function run() {
|
||||
if (core.getInput('show-versioninfo') == 'true') {
|
||||
exec.exec('julia', ['-e', 'using InteractiveUtils; versioninfo()'])
|
||||
}
|
||||
|
||||
// Create caches
|
||||
if (core.getInput('cache-artifacts') == 'true') {
|
||||
core.debug('caching artifacts directory...')
|
||||
const cacheId = await jlcache.cacheArtifacts()
|
||||
core.setOutput('artifacts-cache-id', cacheId.toString())
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user