Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin registering, and add register specified plugins support #106

Merged
merged 1 commit into from
Jun 27, 2024
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
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