Skip to content

Commit

Permalink
Test register plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Jun 27, 2024
1 parent 38e4b8e commit 2795bc8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import semver from 'semver';
import * as core from '@actions/core';

import * as setup from './setup';
import { registerPlugins } from './plugins';

async function main() {
try {
const versionSpec = core.getInput('version');
console.log(`versionSpec: ${versionSpec}`);
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
const enablePlugins = (core.getInput('enable-plugins') || 'false').toUpperCase() === 'TRUE';
const enablePlugins = (core.getInput('enable-plugins') || 'false').toLowerCase();
const features = core.getInput('features') || 'default';
const githubToken = core.getInput('github-token');
const version = ['*', 'nightly'].includes(versionSpec) ? versionSpec : semver.valid(semver.coerce(versionSpec));
Expand All @@ -35,15 +36,13 @@ async function main() {
name: version === 'nightly' ? 'nightly' : 'nushell',
});
core.addPath(tool.dir);
core.info(`Successfully setup Nu ${tool.version}, with ${features} features.}`);
// version: * --> 0.95.0; nightly --> nightly-56ed69a; 0.95 --> 0.95.0
core.info(`Successfully setup Nu ${tool.version}, with ${features} features.`);

if (enablePlugins) {
// Change to workspace directory so that the register-plugins.nu script can be found.
shell.cd(process.env.GITHUB_WORKSPACE);
console.log(`Current directory: ${process.cwd()}`);
console.log('Running ./nu/register-plugins.nu to register plugins...');
shell.exec(`nu ./nu/register-plugins.nu ${tool.version}`);
}
// Change to workspace directory so that the register-plugins.nu script can be found.
shell.cd(process.env.GITHUB_WORKSPACE);
console.log(`Current directory: ${process.cwd()}`);
registerPlugins(enablePlugins, tool.version);
} catch (err) {
core.setFailed(err.message);
}
Expand Down
18 changes: 18 additions & 0 deletions src/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import shell from 'shelljs';
import semver from 'semver';
import { globby } from 'globby';

export async function registerPlugins(enablePlugins: string, version: string) {
if (enablePlugins === '' || enablePlugins === 'false') {
return;
}
const LEGACY_VERSION = '0.92.3';
const nuBin = shell.which('nu');
const plugins = await globby(`${nuBin}_plugins_*`, { absolute: true, unique: true });
console.log('Plugins:', plugins);
if (!version.includes('nightly') && semver.lte(version, LEGACY_VERSION)) {
console.log('Register plugins by `register` command');
} else {
console.log('Register plugins by `plugin add` command');
}
}
2 changes: 1 addition & 1 deletion src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface Tool {
/** Set this option to `true` if you want to check for the latest version. */
checkLatest: boolean;
/** Set this option to `true` if you want to register plugins. */
enablePlugins: boolean;
enablePlugins: string;
/** A valid semantic version specifier for the tool. */
versionSpec?: string;
/** Feature set: default or full. */
Expand Down

0 comments on commit 2795bc8

Please sign in to comment.