Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.6.0

- Added a `auto-setup` input that will automatically setup moon toolchains by running `moon setup`.
- Updated proto version detection to extract the `proto.version` field from `.moon/toolchain.yml`.

# 0.5.0

- Support proto v0.51 changes and `.protolock` files.
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ jobs:

## Inputs

- `auto-install` - Auto-install tools from the root `.prototools` on setup. Defaults to `false`.
- `auto-install` - Auto-install proto tools by running `proto install`. Defaults to `false`.
- `auto-setup` - Auto-setup moon toolchains by running `moon setup`. Defaults to `false`.
- `cache` - Toggle caching of the toolchain directory. Defaults to `true`.
- `cache-base` - Base branch/ref to save a warmup cache on. Other branches/refs will restore from
this base.
- `cache-version` - Version of the cache. Can be used to invalidate keys.
- `moon-version` - Version of moon to explicitly install.
- `proto-version` - Version of proto to explicitly install.
- `moon-version` - Version of moon to explicitly install. Version will be extracted from
`.prototools`.
- `proto-version` - Version of proto to explicitly install. Version will be extracted from
`.moon/toolchain.yml`.
- `workspace-root` - Relative path to moon's workspace root if initialized in a sub-directory.
Defaults to "".
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ description: 'Installs proto and moon globally when required, and caches the too
inputs:
auto-install:
default: 'false'
description: 'Auto-install tools on setup.'
description: 'Auto-install proto tools using `proto install`.'
auto-setup:
default: 'false'
description: 'Auto-setup moon toolchains using `moon setup`.'
cache:
description: 'Toggle caching of the toolchain directory.'
default: 'true'
Expand Down
35 changes: 34 additions & 1 deletion helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import execa from 'execa';
import yaml from 'yaml';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as glob from '@actions/glob';
Expand Down Expand Up @@ -147,10 +148,42 @@ export async function getToolchainCacheKey() {
return `${getCacheKeyPrefix()}-${process.platform}-${process.arch}-${hasher.digest('hex')}`;
}

function getProtoVersion(): string {
const version = core.getInput('proto-version');

if (version) {
return version;
}

if (isUsingMoon()) {
const toolchainPath = path.join(getWorkspaceRoot(), '.moon/toolchain.yml');

if (fs.existsSync(toolchainPath)) {
const toolchain = yaml.parse(fs.readFileSync(toolchainPath, 'utf8')) as {
proto?: { version?: string };
};
const protoVersion = toolchain.proto?.version;

// Only fully-qualified is allowed
if (protoVersion && typeof protoVersion === 'string' && protoVersion.split('.').length >= 3) {
return protoVersion;
}
}
}

return 'latest';
}

function getMoonVersion(): string {
return core.getInput('moon-version') || 'latest';
}

export async function installBin(bin: string) {
core.info(`Installing \`${bin}\` globally`);

const version = core.getInput(`${bin}-version`) || 'latest';
const version =
// eslint-disable-next-line no-nested-ternary
bin === 'proto' ? getProtoVersion() : bin === 'moon' ? getMoonVersion() : 'latest';

const scriptName = WINDOWS ? `${bin}.ps1` : `${bin}.sh`;
const scriptPath = path.join(getProtoHome(), 'temp', scriptName);
Expand Down
10 changes: 8 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ async function run() {
await restoreCache();

if (core.getBooleanInput('auto-install')) {
core.info('Auto-installing tools');
core.info('Installing proto tools');

await execa('proto', ['use'], { cwd: getWorkspaceRoot(), stdio: 'inherit' });
await execa('proto', ['install'], { cwd: getWorkspaceRoot(), stdio: 'inherit' });
}

if (isUsingMoon() && core.getBooleanInput('auto-setup')) {
core.info('Setting up moon toolchains');

await execa('moon', ['setup'], { cwd: getWorkspaceRoot(), stdio: 'inherit' });
}
} catch (error: unknown) {
core.setFailed(error as Error);
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonrepo/setup-toolchain",
"version": "0.5.0",
"version": "0.6.0",
"description": "A GitHub action to setup and cache the proto and moon toolchains.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -19,22 +19,23 @@
"author": "Miles Johnson",
"license": "MIT",
"dependencies": {
"@actions/cache": "^4.0.3",
"@actions/cache": "^4.0.5",
"@actions/core": "^1.11.1",
"@actions/glob": "^0.5.0",
"@actions/tool-cache": "^2.0.2",
"execa": "^5.1.1"
"execa": "^5.1.1",
"yaml": "^2.8.1"
},
"devDependencies": {
"@types/node": "^20.10.4",
"@vercel/ncc": "^0.38.1",
"@types/node": "^24.3.0",
"@vercel/ncc": "^0.38.3",
"eslint": "^8.56.0",
"eslint-config-moon": "^2.0.13",
"prettier": "^3.1.1",
"prettier-config-moon": "^1.1.2",
"prettier": "^3.6.2",
"prettier-config-moon": "^1.2.1",
"ts-node": "^10.9.2",
"tsconfig-moon": "^1.3.0",
"typescript": "^5.8.2"
"tsconfig-moon": "^1.4.1",
"typescript": "^5.9.2"
},
"engines": {
"node": ">=16.0.0"
Expand Down
Loading
Loading