Skip to content

Commit

Permalink
Rename feature to features
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Nov 4, 2023
1 parent 4107c6e commit 35c37ba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/full-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup nu@${{matrix.ver}}
uses: hustcer/setup-nu@develop
with:
feature: full
features: full
enable-plugins: true
version: ${{matrix.ver}}
env:
Expand All @@ -54,7 +54,7 @@ jobs:
- name: Setup nu@nightly
uses: hustcer/setup-nu@develop
with:
feature: full
features: full
version: nightly
enable-plugins: true
env:
Expand Down
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inputs:
default: '*'
required: false
description: 'A valid semver specifier of nushell version to install.'
feature:
features:
default: 'default'
required: false
description: 'Nushell features to install, should be `full` or `default`.'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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 features = core.getInput('features') || '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 @@ -29,11 +29,11 @@ async function main() {
bin: 'nu',
owner: 'nushell',
versionSpec: ver,
feature: feature as 'default' | 'full',
features: features as 'default' | 'full',
name: version === 'nightly' ? 'nightly' : 'nushell',
});
core.addPath(tool.dir);
core.info(`Successfully setup Nu ${tool.version}, with ${feature} features.}`);
core.info(`Successfully setup Nu ${tool.version}, with ${features} features.}`);

if (enablePlugins) {
console.log('Running ./nu/register-plugins.nu to register plugins...');
Expand Down
28 changes: 14 additions & 14 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const PLATFORM_FULL_MAP: Record<Platform, string[]> = {
/**
* @returns {string[]} possible nushell target specifiers for the current platform.
*/
function getTargets(feature: 'default' | 'full'): string[] {
function getTargets(features: 'default' | 'full'): string[] {
const { arch, platform } = process;

if (arch === 'x64' && feature === 'default') {
if (arch === 'x64' && features === 'default') {
return PLATFORM_DEFAULT_MAP[platform as Platform];
}
if (arch === 'x64' && feature === 'full') {
if (arch === 'x64' && features === 'full') {
return PLATFORM_FULL_MAP[platform as Platform];
}
throw new Error(`failed to determine any valid targets; arch = ${arch}, platform = ${platform}`);
Expand All @@ -55,7 +55,7 @@ export interface Tool {
/** A valid semantic version specifier for the tool. */
versionSpec?: string;
/** Feature set: default or full. */
feature: 'default' | 'full';
features: 'default' | 'full';
/** The name of the tool binary (defaults to the repo name) */
bin?: string;
}
Expand Down Expand Up @@ -92,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, feature: 'default' | 'full'): Release[] {
const targets = getTargets(feature);
function filterMatch(response: any, versionSpec: string | undefined, features: 'default' | 'full'): Release[] {
const targets = getTargets(features);
return response.data
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
Expand All @@ -117,8 +117,8 @@ function filterMatch(response: any, versionSpec: string | undefined, feature: 'd
* @param response the response to filter a latest release from.
* @returns {Release[]} a single GitHub release.
*/
function filterLatest(response: any, feature: 'default' | 'full'): Release[] {
const targets = getTargets(feature);
function filterLatest(response: any, features: 'default' | 'full'): Release[] {
const targets = getTargets(features);
const versions = response.data.map((r: { tag_name: string }) => r.tag_name);
const latest = semver.rsort(versions)[0];
return response.data
Expand All @@ -142,8 +142,8 @@ function filterLatest(response: any, feature: 'default' | 'full'): Release[] {
* @param response the response to filter a latest release from.
* @returns {Release[]} a single GitHub release.
*/
function filterLatestNightly(response: any, feature: 'default' | 'full'): Release[] {
const targets = getTargets(feature);
function filterLatestNightly(response: any, features: 'default' | 'full'): Release[] {
const targets = getTargets(features);
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 @@ -172,16 +172,16 @@ function filterLatestNightly(response: any, feature: 'default' | 'full'): Releas
* @returns {Promise<Release>} a single GitHub release.
*/
async function getRelease(tool: Tool): Promise<Release> {
const { owner, name, versionSpec, checkLatest = false, feature = 'default' } = tool;
const { owner, name, versionSpec, checkLatest = false, features = '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, feature) : [];
const nightlyReleases = isNightly ? filterLatestNightly(response, features) : [];
const officialReleases = checkLatest
? filterLatest(response, feature)
: filterMatch(response, versionSpec, feature);
? filterLatest(response, features)
: filterMatch(response, versionSpec, features);
const releases = isNightly ? nightlyReleases : officialReleases;

if (releases) {
Expand Down

0 comments on commit 35c37ba

Please sign in to comment.