Skip to content

Commit

Permalink
Fix plugin registering, and add register specified plugins support
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Jun 27, 2024
1 parent ab26480 commit a1d168a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Setup ${{ matrix.crate.owner }}/${{ matrix.crate.name }}
uses: ./
with:
version: v0.90
version: v0.90.1
enable-plugins: true
env:
ACTIONS_STEP_DEBUG: true
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 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,12 +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) {
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
26 changes: 26 additions & 0 deletions src/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import path from 'path';
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');
console.log('Nu binary path:', nuBin?.toString());
const nuDir = nuBin ? path.dirname(nuBin.toString()) : '';
const plugins = await globby(`${nuDir}/nu_plugin_*`, { absolute: true, unique: true });
console.log('All available Nu plugins:', plugins);
const filteredPlugins =
enablePlugins === 'true' ? plugins : plugins.filter((it) => enablePlugins.includes(path.basename(it)));
filteredPlugins.forEach((it) => {
console.log(`Register plugin: ${it}`);
if (!version.includes('nightly') && semver.lte(version, LEGACY_VERSION)) {
shell.exec(`nu -c "'register ${it}'"`);
} else {
shell.exec(`nu -c "'plugin add ${it}'"`);
}
});
}
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 a1d168a

Please sign in to comment.