From d07633890f282ec4bf9648ec8912ee2836417620 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 10 Sep 2023 11:43:23 +0200 Subject: [PATCH] fix: create mage home dir if it does not exist --- src/installer.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 44e0425..1c75fae 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -5,6 +5,7 @@ import * as core from '@actions/core'; import * as httpm from '@actions/http-client'; import * as tc from '@actions/tool-cache'; import * as cache from '@actions/cache'; +import fs from 'fs'; const osPlat: string = os.platform(); const osArch: string = os.arch(); @@ -44,12 +45,17 @@ export async function getMage(version: string): Promise { return getExePath(magePath); } + const mageHome = path.join(`${process.env.HOME}`, '.mage'); + if (!fs.existsSync(mageHome)) { + fs.mkdirSync(mageHome, {recursive: true}); + } + if (cache.isFeatureAvailable()) { core.debug(`GitHub actions cache feature available`); - const cacheKey = await cache.restoreCache([getExePath(mageLocalPath())], getCacheKey(semver)); + const cacheKey = await cache.restoreCache([getExePath(mageHome)], getCacheKey(semver)); if (cacheKey) { core.info(`Restored ${cacheKey} from GitHub actions cache`); - const cachePath: string = await tc.cacheDir(mageLocalPath(), 'mage-action', semver); + const cachePath: string = await tc.cacheDir(mageHome, 'mage-action', semver); return getExePath(cachePath); } } @@ -67,9 +73,9 @@ export async function getMage(version: string): Promise { core.info('Extracting Mage...'); let extPath: string; if (osPlat == 'win32') { - extPath = await tc.extractZip(downloadPath, mageLocalPath()); + extPath = await tc.extractZip(downloadPath, mageHome); } else { - extPath = await tc.extractTar(downloadPath, mageLocalPath()); + extPath = await tc.extractTar(downloadPath, mageHome); } core.debug(`Extracted to ${extPath}`); @@ -77,7 +83,7 @@ export async function getMage(version: string): Promise { core.debug(`Cached to ${cachePath}`); if (cache.isFeatureAvailable()) { core.debug(`Caching to GitHub actions cache`); - await cache.saveCache([getExePath(mageLocalPath())], getCacheKey(semver)); + await cache.saveCache([getExePath(mageHome)], getCacheKey(semver)); } return getExePath(cachePath); @@ -87,10 +93,6 @@ const getCacheKey = (semver: string): string => { return util.format('mage-action-cache-%s', semver); }; -const mageLocalPath = (): string => { - return path.join(`${process.env.HOME}`, '.mage'); -}; - const getExePath = (basePath: string): string => { const exePath: string = path.join(basePath, osPlat == 'win32' ? 'mage.exe' : 'mage'); core.debug(`Exe path is ${exePath}`);