Skip to content

Commit

Permalink
fix: create mage home dir if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Sep 10, 2023
1 parent 74678e6 commit d076338
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -44,12 +45,17 @@ export async function getMage(version: string): Promise<string> {
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);
}
}
Expand All @@ -67,17 +73,17 @@ export async function getMage(version: string): Promise<string> {
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}`);

const cachePath: string = await tc.cacheDir(extPath, 'mage-action', semver);
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);
Expand All @@ -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}`);
Expand Down

0 comments on commit d076338

Please sign in to comment.