Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
new: Append to PATH.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 27, 2023
1 parent 3e9e886 commit b8756b3
Show file tree
Hide file tree
Showing 6 changed files with 626 additions and 497 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.3.0

- Will now append `~/.proto/bin` to `PATH`, to make the moon toolchain available.
- Will now cache the `~/.proto/plugins` directory.

# 1.2.0

- Will only cache the `~/.proto/tools` toolchain. `~/.moon/tools` is no longer supported.
Expand Down
16 changes: 14 additions & 2 deletions helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@ import path from 'node:path';
import * as glob from '@actions/glob';

export function getMoonDir() {
if (process.env.MOON_HOME) {
return process.env.MOON_HOME;
}

return path.join(os.homedir(), '.moon');
}

export function getHomeDir() {
export function getProtoDir() {
if (process.env.PROTO_HOME) {
return process.env.PROTO_HOME;
}

return path.join(os.homedir(), '.proto');
}

export function getPluginsDir() {
return path.join(getProtoDir(), 'plugins');
}

export function getToolsDir() {
return path.join(getHomeDir(), 'tools');
return path.join(getProtoDir(), 'tools');
}

export async function getToolchainCacheKey() {
Expand Down
21 changes: 16 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import execa from 'execa';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import { getHomeDir, getMoonDir, getToolchainCacheKey, getToolsDir } from './helpers';
import {
getMoonDir,
getPluginsDir,
getProtoDir,
getToolchainCacheKey,
getToolsDir,
} from './helpers';

const WINDOWS = process.platform === 'win32';

Expand All @@ -15,12 +21,16 @@ async function installMoon() {
const version = core.getInput('version') || 'latest';
const isV1 = version === 'latest' || !version.startsWith('0');

const protoDir = getProtoDir();
const protoBinDir = path.join(protoDir, 'bin');

const binName = WINDOWS ? 'moon.exe' : 'moon';
const binDir = isV1 ? path.join(getMoonDir(), 'bin') : path.join(getToolsDir(), 'moon', version);
const binDir = isV1 ? path.join(getMoonDir(), 'bin') : path.join(protoDir, 'tools/moon', version);
const binPath = path.join(binDir, binName);

if (version !== 'latest' && fs.existsSync(binPath)) {
core.addPath(binDir);
core.addPath(protoBinDir);
core.info('Binary already exists, skipping installation');

return;
Expand All @@ -31,7 +41,7 @@ async function installMoon() {
isV1
? `https://moonrepo.dev/install/${WINDOWS ? 'moon.ps1' : 'moon.sh'}`
: `https://moonrepo.dev/${scriptName}`,
path.join(getHomeDir(), 'temp', scriptName),
path.join(protoDir, 'temp', scriptName),
);
const args = version === 'latest' ? [] : [version];

Expand All @@ -50,8 +60,9 @@ async function installMoon() {
core.info(`Installed binary to ${binPath}`);

core.addPath(binDir);
core.addPath(protoBinDir);

core.info(`Added installation direction to PATH`);
core.info(`Added installation directory to PATH`);
}

async function restoreCache() {
Expand All @@ -63,7 +74,7 @@ async function restoreCache() {

const primaryKey = await getToolchainCacheKey();
const cacheKey = await cache.restoreCache(
[getToolsDir()],
[getPluginsDir(), getToolsDir()],
primaryKey,
[`moon-toolchain-${process.platform}`, 'moon-toolchain'],
{},
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonrepo/setup-moon-action",
"version": "1.2.0",
"version": "1.3.0",
"description": "A GitHub action for installing moon globally and caching the toolchain.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -19,22 +19,22 @@
"author": "Miles Johnson",
"license": "MIT",
"dependencies": {
"@actions/cache": "^3.2.1",
"@actions/core": "^1.10.0",
"@actions/cache": "^3.2.2",
"@actions/core": "^1.10.1",
"@actions/glob": "^0.4.0",
"@actions/tool-cache": "^2.0.1",
"execa": "^5.1.1"
},
"devDependencies": {
"@types/node": "^18.15.10",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.46.0",
"eslint-config-moon": "^2.0.6",
"prettier": "^3.0.0",
"@types/node": "^20.7.1",
"@vercel/ncc": "^0.38.0",
"eslint": "^8.50.0",
"eslint-config-moon": "^2.0.10",
"prettier": "^3.0.3",
"prettier-config-moon": "^1.1.2",
"ts-node": "^10.9.1",
"tsconfig-moon": "^1.3.0",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"engines": {
"node": ">=16.0.0"
Expand Down
Loading

0 comments on commit b8756b3

Please sign in to comment.