Skip to content

Commit

Permalink
Merge pull request #308 from crazy-max/v2_backport_fix-home-dir
Browse files Browse the repository at this point in the history
[v2 backport] fix: create mage home dir if it does not exist
  • Loading branch information
crazy-max committed Sep 10, 2023
2 parents bed74f4 + 4f13810 commit a3d5bb5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions src/installer.ts
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 a3d5bb5

Please sign in to comment.