Skip to content

Commit

Permalink
[TEST] dist
Browse files Browse the repository at this point in the history
  • Loading branch information
irgaly committed Jul 11, 2024
1 parent 2caf63a commit fab3fa0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
44 changes: 26 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82977,6 +82977,12 @@ async function execute(command, args = [], cwd) {
function pathContains(parent, child) {
return !path.relative(parent, child).startsWith("../");
}
/**
* expand `~` to os.homedir()
*/
function expandHome(path) {
return path.replace(/^~\//, `${os.homedir()}/`);
}
// Caching may throw errors for legitimate reasons that should not fail the action.
// Example: Race condition between multiple github runners where both try to save cache with the same key at the same time.
// You only need 1 of the runners to save the cache. The other runners can gracefully ignore the error and continue running.
Expand All @@ -82990,12 +82996,14 @@ async function saveCache(paths, key) {
}
async function main() {
try {
const mintDirectory = core.getInput('mint-directory');
const mintDirectory = expandHome(core.getInput('mint-directory'));
const mintExecutableDirectory = expandHome(core.getInput('mint-executable-directory'));
const bootstrap = (core.getInput('bootstrap') == 'true');
const useCache = (core.getInput('use-cache') == 'true');
const cachePrefix = core.getInput('cache-prefix');
const clean = (core.getInput('clean') == 'true');
core.info(`mintDirectory: ${mintDirectory}`);
core.info(`mintExecutableDirectory: ${mintExecutableDirectory}`);
core.info(`bootstrap: ${bootstrap}`);
core.info(`useCache: ${useCache}`);
core.info(`cachePrefix: ${cachePrefix}`);
Expand All @@ -83011,15 +83019,13 @@ async function main() {
core.info(`mintVersion from Mintfile: ${mintVersion}`);
}
}
const binaryDirectoryPrefix = `${process.env['HOME']}`;
const binaryDirectory = `${binaryDirectoryPrefix}/bin`;
const mintPath = `${binaryDirectory}/mint`;
const mint = `${mintExecutableDirectory}/mint`;
const mintCacheKey = `${cachePrefix}-${process.env['RUNNER_OS']}-${process.env['RUNNER_ARCH']}-irgaly/setup-mint-${mintVersion}`;
const mintPaths = [mintPath];
const mintPaths = [mint];
core.info(`mint cache key: ${mintCacheKey}`);
const mintRestored = ((await cache.restoreCache(mintPaths, mintCacheKey)) != undefined);
if (mintRestored) {
core.info(`${mintPath} restored from cache`);
core.info(`${mint} restored from cache`);
}
else {
const temp = path.join(process.env['RUNNER_TEMP'] || '.', (0, uuid_1.v4)());
Expand All @@ -83031,21 +83037,23 @@ async function main() {
'-b', mintVersion,
'https://github.com/yonaskolb/Mint.git']);
if (os.platform() == 'darwin') {
await execute('make', ['-C', `${temp}/Mint`, `PREFIX=${binaryDirectoryPrefix}`]);
await execute('make', ['build', '-C', `${temp}/Mint`]);
fs.mkdirSync(mintExecutableDirectory, { recursive: true });
fs.copyFileSync(`${temp}/Mint/.build/apple/Products/Release/mint`, mint);
}
else {
await execute('swift', ['build', '-c', 'release'], `${temp}/Mint`);
fs.mkdirSync(binaryDirectory, { recursive: true });
fs.copyFileSync(`${temp}/Mint/.build/release/mint`, mintPath);
fs.mkdirSync(mintExecutableDirectory, { recursive: true });
fs.copyFileSync(`${temp}/Mint/.build/release/mint`, mint);
}
await saveCache(mintPaths, mintCacheKey);
}
if (hasMintfile && bootstrap) {
const mintDirectory = (process.env['MINT_PATH'] || '~/.mint').replace(/^~\//, `${os.homedir()}/`);
const mintBinaryDirectory = (process.env['MINT_LINK_PATH'] || '~/.mint/bin').replace(/^~\//, `${os.homedir()}/`);
const mintBinaryNeedsCache = !pathContains(mintDirectory, mintBinaryDirectory);
const mintPackagesDirectory = `${mintDirectory}/packages`;
const mintDependencyPaths = [mintDirectory];
const mintPathDirectory = expandHome(process.env['MINT_PATH'] || '~/.mint');
const mintBinaryDirectory = expandHome(process.env['MINT_LINK_PATH'] || '~/.mint/bin');
const mintBinaryNeedsCache = !pathContains(mintPathDirectory, mintBinaryDirectory);
const mintPackagesDirectory = `${mintPathDirectory}/packages`;
const mintDependencyPaths = [mintPathDirectory];
const mintDependencyCacheKey = `${cachePrefix}-${process.env['RUNNER_OS']}-${process.env['RUNNER_ARCH']}-irgaly/setup-mint-deps-${await (0, glob_1.hashFiles)(mintFile)}`;
const mintDependencyRestoreKeys = [`${cachePrefix}-${process.env['RUNNER_OS']}-${process.env['RUNNER_ARCH']}-irgaly/setup-mint-deps-`];
const mintBinaryPaths = [mintBinaryDirectory];
Expand All @@ -83062,10 +83070,10 @@ async function main() {
mintDependencyRestored = (mintDependencyRestoredKey == mintDependencyCacheKey);
}
if (mintDependencyRestored) {
core.info(`${mintDirectory} / ${mintBinaryDirectory} restored from cache`);
core.info(`${mintPathDirectory} / ${mintBinaryDirectory} restored from cache`);
}
else {
await execute(mintPath, ['bootstrap', '-v', '-m', `${mintFile}`]);
await execute(mint, ['bootstrap', '-v', '-m', `${mintFile}`]);
if (useCache) {
if (clean) {
const mintFileString = fs.readFileSync(mintFile).toString();
Expand Down Expand Up @@ -83094,8 +83102,8 @@ async function main() {
for (const installed of installedPackages) {
core.info(`installed: ${installed.name}`);
if (!defined.includes(installed.name) && !defined.includes(installed.short)) {
core.info(`=> unisntall: ${installed.name}`);
await execute(mintPath, ['uninstall', `${installed.name}`]);
core.info(`=> uninstall: ${installed.name}`);
await execute(mint, ['uninstall', `${installed.name}`]);
const builds = path.dirname(installed.build);
if (fs.readdirSync(builds).length == 0) {
fs.rmdirSync(path.dirname(builds), { recursive: true });
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit fab3fa0

Please sign in to comment.