diff --git a/dist/index.js b/dist/index.js index 85e528b..90e0562 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/src/cache-restore/index.ts b/src/cache-restore/index.ts index e5ebef4..b3db275 100644 --- a/src/cache-restore/index.ts +++ b/src/cache-restore/index.ts @@ -1,19 +1,19 @@ -import * as cache from '@actions/cache'; -import * as core from '@actions/core'; -import { runRestoreCache } from './run'; -import { Inputs } from '../inputs'; +import { isFeatureAvailable } from '@actions/cache' +import { endGroup, startGroup, warning } from '@actions/core' +import { Inputs } from '../inputs' +import { runRestoreCache } from './run' export async function restoreCache(inputs: Inputs) { if (!inputs.cache) return - if (!cache.isFeatureAvailable()) { - core.warning('Cache is not available, skipping cache restoration') + if (!isFeatureAvailable()) { + warning('Cache is not available, skipping cache restoration') return } - core.startGroup('Restoring cache...') - await runRestoreCache(inputs); - core.endGroup(); + startGroup('Restoring cache...') + await runRestoreCache(inputs) + endGroup() } export default restoreCache diff --git a/src/cache-restore/run.ts b/src/cache-restore/run.ts index f10ab78..017c2a9 100644 --- a/src/cache-restore/run.ts +++ b/src/cache-restore/run.ts @@ -1,39 +1,39 @@ -import * as cache from '@actions/cache'; -import * as core from '@actions/core'; -import * as exec from '@actions/exec'; -import * as glob from '@actions/glob'; -import os from 'os'; -import { Inputs } from '../inputs'; +import { restoreCache } from '@actions/cache' +import { debug, info, saveState, setOutput } from '@actions/core' +import * as exec from '@actions/exec' +import * as glob from '@actions/glob' +import os from 'os' +import { Inputs } from '../inputs' export async function runRestoreCache(inputs: Inputs) { - const cachePath = await getCacheDirectory(); - core.saveState('cache_path', cachePath); + const cachePath = await getCacheDirectory() + saveState('cache_path', cachePath) - const fileHash = await glob.hashFiles(inputs.cacheDependencyPath); + const fileHash = await glob.hashFiles(inputs.cacheDependencyPath) if (!fileHash) { - throw new Error('Some specified paths were not resolved, unable to cache dependencies.'); + throw new Error('Some specified paths were not resolved, unable to cache dependencies.') } - const primaryKey = `pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-${fileHash}`; - core.debug(`Primary key is ${primaryKey}`); - core.saveState('cache_primary_key', primaryKey); + const primaryKey = `pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-${fileHash}` + debug(`Primary key is ${primaryKey}`) + saveState('cache_primary_key', primaryKey) - let cacheKey = await cache.restoreCache([cachePath], primaryKey); + let cacheKey = await restoreCache([cachePath], primaryKey) - core.setOutput('cache-hit', Boolean(cacheKey)); + setOutput('cache-hit', Boolean(cacheKey)) if (!cacheKey) { - core.info(`Cache is not found`); - return; + info(`Cache is not found`) + return } - core.saveState('cache_restored_key', cacheKey) - core.info(`Cache restored from key: ${cacheKey}`) + saveState('cache_restored_key', cacheKey) + info(`Cache restored from key: ${cacheKey}`) } async function getCacheDirectory() { const { stdout } = await exec.getExecOutput('pnpm store path --silent') const cacheFolderPath = stdout.trim() - core.debug(`Cache folder is set to "${cacheFolderPath}"`) - return cacheFolderPath; -}; + debug(`Cache folder is set to "${cacheFolderPath}"`) + return cacheFolderPath +} diff --git a/src/cache-save/index.ts b/src/cache-save/index.ts index ea9bee2..2beec06 100644 --- a/src/cache-save/index.ts +++ b/src/cache-save/index.ts @@ -1,14 +1,14 @@ -import * as core from '@actions/core'; -import { Inputs } from '../inputs'; -import { runSaveCache } from './run'; +import { setFailed } from '@actions/core' +import { Inputs } from '../inputs' +import { runSaveCache } from './run' export async function saveCache(inputs: Inputs) { if (!inputs.cache) return try { - await runSaveCache(); + await runSaveCache() } catch (error) { - core.setFailed((error as Error).message); + setFailed((error as Error).message) } } diff --git a/src/cache-save/run.ts b/src/cache-save/run.ts index d343800..7481d58 100644 --- a/src/cache-save/run.ts +++ b/src/cache-save/run.ts @@ -1,18 +1,18 @@ -import * as core from '@actions/core'; -import * as cache from '@actions/cache'; +import { saveCache } from '@actions/cache' +import { getState, info } from '@actions/core' export async function runSaveCache() { - const state = core.getState('cache_restored_key'); - const primaryKey = core.getState('cache_primary_key'); - const cachePath = core.getState('cache_path'); + const state = getState('cache_restored_key') + const primaryKey = getState('cache_primary_key') + const cachePath = getState('cache_path') if (primaryKey === state) { - core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); - return; + info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`) + return } - const cacheId = await cache.saveCache([cachePath], primaryKey); - if (cacheId == -1) return; + const cacheId = await saveCache([cachePath], primaryKey) + if (cacheId == -1) return - core.info(`Cache saved with the key: ${primaryKey}`); + info(`Cache saved with the key: ${primaryKey}`) } diff --git a/src/index.ts b/src/index.ts index ac98d1a..b3c72cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ import { setFailed, saveState, getState } from '@actions/core' +import restoreCache from './cache-restore' +import saveCache from './cache-save' import getInputs, { Inputs } from './inputs' import installPnpm from './install-pnpm' import setOutputs from './outputs' import pnpmInstall from './pnpm-install' import pruneStore from './pnpm-store-prune' -import restoreCache from './cache-restore' -import saveCache from './cache-save' async function main() { const inputs = getInputs() @@ -24,7 +24,7 @@ async function runMain(inputs: Inputs) { console.log('Installation Completed!') setOutputs(inputs) - await restoreCache(inputs); + await restoreCache(inputs) pnpmInstall(inputs) }