Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
terminal

GitHub Action

Setup Nu

v3.6

Setup Nu

terminal

Setup Nu

Setup a Nushell Environment to Run Nu Scripts or Commands

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Setup Nu

uses: hustcer/setup-nu@v3.6

Learn more about this action in hustcer/setup-nu

Choose a version

setup-nu

中文说明

Latest Main Check

This GitHub Action will setup a Nushell environment for you.

Usage

Which Version Should I Choose?

  1. setup-nu@v3 supports Nu v0.60.0 ~ latest;
  2. setup-nu@v2 supports Nu v0.60.0 ~ 0.70.0;
  3. setup-nu@v1 supports Nu v0.60.0 ~ 0.63.0;

Examples

Basic

In most cases you just need to specify the version of Nushell to be used in your workflow. For example the following installs the v0.80 version of Nushell. Then you can set the command you want to run in the following steps, and don't forget to set shell: nu {0} to make the commands be executed by nu:

- uses: hustcer/setup-nu@v3
  with:
    version: '0.80'   # Don't use 0.80 here, as it was a float number and will be convert to 0.8, you can use v0.80/0.80.0 or '0.80'
- run: print $'Nu version info:(char nl)'; version
  shell: nu {0}
- name: Default shell will be `nu`
  shell: nu {0}
  run: |
    print $'Nu path:(which nu)(char nl)'
    def greeting [name: string] {
        print $'Hello ($name)'
    }
    greeting hustcer

Used as Default Shell

Of cause, You can also set the default shell to nu by setting the defaults.run.shell config:

name: basic

on: push
defaults:
  run:
    shell: nu {0}

jobs:
  basic-usage:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4.0.0
    - uses: hustcer/setup-nu@main
      with:
        version: '*'
    - run: version; $"(char nl)Dir contents:(char nl)"; ls ((which nu).path.0 | path dirname)
    - run: |
        print $'Current env:(char nl)'
        print $env
    - name: You can run bash commands, too
      run: pwd && ls -la
      shell: bash

Use Modules

To use modules in Nu, you can follow this example:

    - name: Setup nu
      uses: hustcer/setup-nu@v3.5
      with:
        version: 0.83
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - name: Use Your Nu Modules
      shell: nu {0}
      run: |
        nu -c "use nu/module.nu *; print (get-env 'ABC-XYZ' 'DEFAULT-ABC-XYZ')"

You have to wrap the nu code in nu -c "", and the nu version should be equal or above 0.69, it's not perfect yet, However, this is the only way I found works. Please tell me if you found a better way and PRs are always welcomed.

Others

Or, check the following examples:

  1. run-test.yaml
  2. run-matrix.yaml
  3. Advanced example: How Nushell Make a Release? Workflow, Script

If you want to use the latest version of nushell you can specify this by set check-latest to true(it's the same as version: '*', but more readable). For example the following installs the latest version:

- uses: hustcer/setup-nu@v3
  with:
    check-latest: true
- run: print $'Nu version info:(char nl)'; version

Note: Before Nushell reaches 1.0, each version may change a lot, it is recommend that you use a specified version instead.

In rare circumstances you might get rate limiting errors, this is caused by the workflow has to make requests to GitHub API in order to list available releases. If this happens you can set the GITHUB_TOKEN environment variable.

- uses: hustcer/setup-nu@v3
  with:
    version: '0.80'
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Inputs

Name Required Description Type Default
version no A valid NPM-style semver specification. string *
check-latest no Set to true if you want to use the latest version bool false
enable-plugins no Set to true if you want to register the bundled plugins, Nu v0.69 and above is required bool false

The semver specification is passed directly to NPM's semver package. This GitHub Action will install the latest matching release.

License

Licensed under: