Skip to content

Commit

Permalink
Merge pull request #307 from crazy-max/fix-home-dir
Browse files Browse the repository at this point in the history
fix: create mage home dir if it does not exist
  • Loading branch information
crazy-max authored Sep 10, 2023
2 parents 74678e6 + d0d1cd3 commit 6a5dcb5
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
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 6a5dcb5

Please sign in to comment.