Skip to content

Commit

Permalink
feat: Add use Nu of full features support
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Oct 28, 2023
1 parent 3115c1b commit d3e23a1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 21 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/full-matrix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Nu Full Features Check

on:
push:
branches:
- main
- develop
- release/*
paths-ignore:
- '**.md'

defaults:
run:
shell: nu {0}

jobs:
test-matrix:
strategy:
matrix:
os: [windows-latest, ubuntu-22.04, macos-latest]
ver: [0.86]

runs-on: ${{ matrix.os }}
name: test (${{matrix.os}}, nu@${{matrix.ver}})
steps:
- uses: actions/[email protected]
- name: Setup nu@${{matrix.ver}}
uses: hustcer/setup-nu@develop
with:
feature: full
enable-plugins: true
version: ${{matrix.ver}}
env:
ACTIONS_STEP_DEBUG: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Show Nu Version
run: print $'Nu version info:(char nl)'; print (version)
- name: Show env Variables
run: print $'Current env:(char nl)'; print $env
- name: Show Nu Binary Path
run: print $'Nu path:(which nu)(char nl)'
- name: Show Nu Package Contents
run: print $"(char nl)Dir contents:(char nl)"; print (ls ((which nu).path.0 | path dirname))
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ inputs:
default: '*'
required: false
description: 'A valid semver specifier of nushell version to install.'
feature:
default: 'default'
required: false
description: 'Nushell features to install, should be `full` or `default`.'
check-latest:
default: false
required: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function main() {
console.log(`versionSpec: ${versionSpec}`);
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
const enablePlugins = (core.getInput('enable-plugins') || 'false').toUpperCase() === 'TRUE';
const feature = core.getInput('feature') || 'default';
const version = ['*', 'nightly'].includes(versionSpec) ? versionSpec : semver.valid(semver.coerce(versionSpec));
console.log(`coerce version: ${version}`);
const ver = version === null ? undefined : version;
Expand All @@ -28,10 +29,11 @@ async function main() {
bin: 'nu',
owner: 'nushell',
versionSpec: ver,
feature: feature as 'default' | 'full',
name: version === 'nightly' ? 'nightly' : 'nushell',
});
core.addPath(tool.dir);
core.info(`Successfully setup Nu ${tool.version}`);
core.info(`Successfully setup Nu ${tool.version}, with ${feature} features.}`);

if (enablePlugins) {
console.log('Running ./nu/register-plugins.nu to register plugins...');
Expand Down
53 changes: 34 additions & 19 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,31 @@ import * as tc from '@actions/tool-cache';
import { Octokit } from '@octokit/rest';
import { promises as fs, constants as fs_constants } from 'fs';

type Platform = 'darwin' | 'win32' | 'linux';

const PLATFORM_DEFAULT_MAP: Record<Platform, string[]> = {
darwin: ['x86_64-apple-darwin', 'macOS.zip'],
win32: ['x86_64-pc-windows-msvc.zip', 'windows.zip'],
linux: ['x86_64-unknown-linux-musl', 'x86_64-unknown-linux-gnu', 'linux.tar.gz'],
};

const PLATFORM_FULL_MAP: Record<Platform, string[]> = {
darwin: ['x86_64-darwin-full'],
win32: ['x86_64-windows-msvc-full.zip'],
linux: ['x86_64-linux-musl-full', 'x86_64-linux-gnu-full'],
};

/**
* @returns {string[]} possible nushell target specifiers for the current platform.
*/
type Platform = 'darwin' | 'win32' | 'linux';

function getTargets(): string[] {
function getTargets(feature: 'default' | 'full'): string[] {
const { arch, platform } = process;
const PLATFORM_MAP: Record<Platform, string[]> = {
darwin: ['x86_64-apple-darwin', 'macOS.zip'],
win32: ['x86_64-pc-windows-msvc.zip', 'windows.zip'],
linux: ['x86_64-unknown-linux-musl', 'x86_64-unknown-linux-gnu', 'linux.tar.gz'],
};
if (arch === 'x64') {
return PLATFORM_MAP[platform as Platform];

if (arch === 'x64' && feature === 'default') {
return PLATFORM_DEFAULT_MAP[platform as Platform];
}
if (arch === 'x64' && feature === 'full') {
return PLATFORM_FULL_MAP[platform as Platform];
}
throw new Error(`failed to determine any valid targets; arch = ${arch}, platform = ${platform}`);
}
Expand All @@ -43,6 +54,8 @@ export interface Tool {
enablePlugins: boolean;
/** A valid semantic version specifier for the tool. */
versionSpec?: string;
/** Feature set: default or full. */
feature: 'default' | 'full';
/** The name of the tool binary (defaults to the repo name) */
bin?: string;
}
Expand Down Expand Up @@ -79,8 +92,8 @@ interface Release {
* @param response the response to filter a release from with the given versionSpec.
* @returns {Release[]} a single GitHub release.
*/
function filterMatch(response: any, versionSpec: string | undefined): Release[] {
const targets = getTargets();
function filterMatch(response: any, versionSpec: string | undefined, feature: 'default' | 'full'): Release[] {
const targets = getTargets(feature);
return response.data
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
Expand All @@ -104,8 +117,8 @@ function filterMatch(response: any, versionSpec: string | undefined): Release[]
* @param response the response to filter a latest release from.
* @returns {Release[]} a single GitHub release.
*/
function filterLatest(response: any): Release[] {
const targets = getTargets();
function filterLatest(response: any, feature: 'default' | 'full'): Release[] {
const targets = getTargets(feature);
const versions = response.data.map((r: { tag_name: string }) => r.tag_name);
const latest = semver.rsort(versions)[0];
return response.data
Expand All @@ -129,8 +142,8 @@ function filterLatest(response: any): Release[] {
* @param response the response to filter a latest release from.
* @returns {Release[]} a single GitHub release.
*/
function filterLatestNightly(response: any): Release[] {
const targets = getTargets();
function filterLatestNightly(response: any, feature: 'default' | 'full'): Release[] {
const targets = getTargets(feature);
const publishedAt = response.data.map((r: { published_at: string }) => r.published_at);
const sortedDates = publishedAt.sort((a: string, b: string) => new Date(b).getTime() - new Date(a).getTime());
const latest = sortedDates[0];
Expand Down Expand Up @@ -159,14 +172,16 @@ function filterLatestNightly(response: any): Release[] {
* @returns {Promise<Release>} a single GitHub release.
*/
async function getRelease(tool: Tool): Promise<Release> {
const { owner, name, versionSpec, checkLatest = false } = tool;
const { owner, name, versionSpec, checkLatest = false, feature = 'default' } = tool;
const isNightly = versionSpec === 'nightly';
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

return octokit
.paginate(octokit.repos.listReleases, { owner, repo: name }, (response, done) => {
const nightlyReleases = isNightly ? filterLatestNightly(response) : [];
const officialReleases = checkLatest ? filterLatest(response) : filterMatch(response, versionSpec);
const nightlyReleases = isNightly ? filterLatestNightly(response, feature) : [];
const officialReleases = checkLatest
? filterLatest(response, feature)
: filterMatch(response, versionSpec, feature);
const releases = isNightly ? nightlyReleases : officialReleases;

if (releases) {
Expand Down

0 comments on commit d3e23a1

Please sign in to comment.