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

Commit

Permalink
new: Install proto also.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 28, 2023
1 parent 34a3caf commit 1ca5981
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 1.4.0

- Re-enabled the v1.3 release.
- Will now also install `proto` globally.
- Includes `.prototools` when hashing the cache key.

# 1.3.1

- Reverted previous release as it broke CI.

# 1.3.0

- Will now append `~/.proto/bin` to `PATH`, to make the moon toolchain available.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
default: 'latest'
description: 'Version of moon to install.'
required: false
proto-version:
default: 'latest'
description: 'Version of proto to install.'
required: false
outputs:
cache-key:
description: 'The cache key used for the toolchain folder (~/.moon).'
Expand Down
10 changes: 1 addition & 9 deletions helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import os from 'node:os';
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 getProtoDir() {
if (process.env.PROTO_HOME) {
return process.env.PROTO_HOME;
Expand All @@ -27,7 +19,7 @@ export function getToolsDir() {
}

export async function getToolchainCacheKey() {
const toolchainHash = await glob.hashFiles('.moon/toolchain.yml');
const toolchainHash = await glob.hashFiles('.moon/toolchain.yml\n.prototools');

return `moon-toolchain-${process.platform}-${toolchainHash}`;
}
50 changes: 20 additions & 30 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,35 @@ import execa from 'execa';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import {
getMoonDir,
getPluginsDir,
getProtoDir,
getToolchainCacheKey,
getToolsDir,
} from './helpers';
import { getPluginsDir, getProtoDir, getToolchainCacheKey, getToolsDir } from './helpers';

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

// eslint-disable-next-line complexity
async function installMoon() {
core.info('Installing `moon` globally');
async function installBin(bin: string, versionInput: string) {
core.info(`Installing \`${bin}\` globally`);

const version = core.getInput('version') || 'latest';
const isV1 = version === 'latest' || !version.startsWith('0');
const version = core.getInput(versionInput) || 'latest';

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

const binName = WINDOWS ? 'moon.exe' : 'moon';
const binDir = isV1 ? path.join(getMoonDir(), 'bin') : path.join(protoDir, 'tools/moon', version);
const binPath = path.join(binDir, binName);
const binFile = WINDOWS ? `${bin}.exe` : bin;
const binDir = path.join(getProtoDir(), 'bin');
const binPath = path.join(binDir, binFile);

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

return;
}

const scriptName = WINDOWS ? 'install.ps1' : 'install.sh';
const script = await tc.downloadTool(
isV1
? `https://moonrepo.dev/install/${WINDOWS ? 'moon.ps1' : 'moon.sh'}`
: `https://moonrepo.dev/${scriptName}`,
path.join(protoDir, 'temp', scriptName),
);
const scriptName = WINDOWS ? `${bin}.ps1` : `${bin}.sh`;
const scriptPath = path.join(getProtoDir(), 'temp', scriptName);

// If the installer already exists, delete it and ensure were using the latest
if (fs.existsSync(scriptPath)) {
fs.unlinkSync(scriptPath);
}

const script = await tc.downloadTool(`https://moonrepo.dev/install/${scriptName}`, scriptPath);
const args = version === 'latest' ? [] : [version];

core.info(`Downloaded installation script to ${script}`);
Expand All @@ -54,15 +44,14 @@ async function installMoon() {

// Make it available without exe extension
if (WINDOWS) {
await fs.promises.copyFile(binPath, path.join(binDir, 'moon'));
await fs.promises.copyFile(binPath, path.join(binDir, bin));
}

core.info(`Installed binary to ${binPath}`);

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

core.info(`Added installation directory to PATH`);
core.info(`Added directory ${binDir} to PATH`);
}

async function restoreCache() {
Expand Down Expand Up @@ -95,7 +84,8 @@ async function restoreCache() {
async function run() {
try {
await restoreCache();
await installMoon();
await installBin('proto', 'proto-version');
await installBin('moon', 'version');
} catch (error: unknown) {
core.setFailed((error as Error).message);
}
Expand Down

0 comments on commit 1ca5981

Please sign in to comment.