Skip to content

Commit

Permalink
feat: Add Nushell nightly version support, close #58 (#59)
Browse files Browse the repository at this point in the history
* feat: Add Nushell nightly version support

* fix: Fix Nu config setup for nightly version

* docs: Update README.md for nightly usage

* docs: Update README.md for nightly usage
  • Loading branch information
hustcer authored Oct 27, 2023
1 parent efdfd48 commit 92f49b4
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 148 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/use-nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build Workflow and Use NU Nightly Test

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

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: '20'
- name: Build Setup Script
run: |
npm i -g pnpm
pnpm i --registry=https://registry.npmmirror.com
pnpm run lint
pnpm run build
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
crate:
- { owner: nushell, name: nushell }

runs-on: ${{ matrix.os }}
name: test (${{matrix.os}}, ${{ matrix.crate.owner }}/${{ matrix.crate.name }})
steps:
- uses: actions/[email protected]
- name: Setup ${{ matrix.crate.owner }}/${{ matrix.crate.name }}
uses: ./
with:
version: nightly
enable-plugins: true
env:
ACTIONS_STEP_DEBUG: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Show Nu Path and Related Assets
run: which $(printf nu | tr '[:upper:]' '[:lower:]') && echo "Dir contents --->:" && ls -la "$(dirname `which nu`)"
shell: bash
- name: Spawn a Nu Session and Display Version Info
run: nu -c 'print (version); print $"(char nl)Dir contents:(char nl)"; ls ((which nu).path.0 | path dirname)'
shell: bash
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#custom-shell
- name: Use Nu as Default Shell
shell: nu {0}
run: |
print $'Current env:(char nl)'
print $env
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ build:
run: build
@$'(ansi g)Start `run` task...(ansi reset)'; \
cd {{SETUP_NU_PATH}}; \
let-env RUNNER_TEMP = './runner/temp'; \
let-env RUNNER_TOOL_CACHE = './runner/cache'; \
$env.RUNNER_TEMP = './runner/temp'; \
$env.RUNNER_TOOL_CACHE = './runner/cache'; \
node dist/index.js

# 检查过期依赖, 需全局安装 `npm-check-updates`
Expand Down
153 changes: 89 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ This GitHub Action will setup a [Nushell](https://github.com/nushell/nushell) en

### Which Version Should I Choose?

1. `[email protected]` supports `Nu` **v0.60.0 ~ latest**;
2. `[email protected]` supports `Nu` **v0.60.0 ~ 0.70.0**;
3. `setup-nu@v1` supports `Nu` **v0.60.0 ~ 0.63.0**;
- `[email protected]` supports `Nu` **v0.60.0 ~ latest** and latest `nightly` version;
- `[email protected]` supports `Nu` **v0.60.0 ~ latest**;
- `[email protected]` supports `Nu` **v0.60.0 ~ 0.70.0**;
- `setup-nu@v1` supports `Nu` **v0.60.0 ~ 0.63.0**;

### Examples

Expand All @@ -24,9 +25,9 @@ Then you can set the command you want to run in the following steps, and don't f
to make the commands be executed by `nu`:

```yaml
- uses: hustcer/setup-nu@v3.6
- uses: hustcer/setup-nu@v3.7
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'
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`
Expand Down Expand Up @@ -55,17 +56,17 @@ jobs:
basic-usage:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: hustcer/setup-nu@main
with:
version: '*'
- run: version; print $"(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
- uses: actions/[email protected]
- uses: hustcer/setup-nu@main
with:
version: "*"
- run: version; print $"(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 Nu Modules
Expand All @@ -75,65 +76,89 @@ To use modules in `Nu`, please refer to the following examples:
1. Use Nu modules in `nu -c`

```yaml
- name: Setup nu
uses: hustcer/setup-nu@v3.6
with:
version: 0.86
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')"
- name: Setup nu
uses: hustcer/setup-nu@v3.7
with:
version: 0.86
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 to or above `0.69`.

2. Use modules from absolute path

```yaml
- name: Setup nu
uses: hustcer/setup-nu@v3.6
with:
version: 0.86
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Use Your Nu Modules by Absolute Path
shell: nu {0}
run: |
use ${{ github.workspace }}/nu/module.nu *
print 'Use module from: ${{ github.workspace }}/nu/module.nu'
print (get-env 'ABC-XYZ' 'DEFAULT-ABC-XYZ-ABSOLUTE-PATH')
- name: Setup nu
uses: hustcer/setup-nu@v3.7
with:
version: 0.86
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Use Your Nu Modules by Absolute Path
shell: nu {0}
run: |
use ${{ github.workspace }}/nu/module.nu *
print 'Use module from: ${{ github.workspace }}/nu/module.nu'
print (get-env 'ABC-XYZ' 'DEFAULT-ABC-XYZ-ABSOLUTE-PATH')
```

Again, the nu version should be equal to or above `0.69`.

3. Copy your modules to one of the default `$env.NU_LIB_DIRS`

```yaml
- name: Setup nu@latest
uses: hustcer/setup-nu@v3.6
with:
version: 0.86
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Nu Modules
shell: nu {0}
run: |
let LIB_DIR = [$nu.default-config-dir 'scripts'] | path join
if not ($LIB_DIR | path exists) { mkdir $LIB_DIR }
cp -r nu/* $LIB_DIR
- name: Use Your Nu Modules
shell: nu {0}
run: |
use module.nu *
print (get-env 'ABC-XYZ' 'DEFAULT-ABC-XYZ')
- name: Setup nu@latest
uses: hustcer/setup-nu@v3.7
with:
version: 0.86
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Nu Modules
shell: nu {0}
run: |
let LIB_DIR = [$nu.default-config-dir 'scripts'] | path join
if not ($LIB_DIR | path exists) { mkdir $LIB_DIR }
cp -r nu/* $LIB_DIR
- name: Use Your Nu Modules
shell: nu {0}
run: |
use module.nu *
print (get-env 'ABC-XYZ' 'DEFAULT-ABC-XYZ')
```

To make it work please make sure that the nu version should be equal to or above `0.85`.

They are not perfect yet, but they do work. BTW: Please tell me if you found a better way and PRs are always welcomed.

#### Use Nu Nightly Version

`Nushell` is currently in active development, if you want to use the latest features it's also available by set the version to `nightly`, just as below:

```yaml
- uses: hustcer/[email protected]
with:
version: nightly # Will download and setup the latest nightly version of Nushell
- 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
```
> **Warning**
> Use `Nushell` nightly version with caution: The nu binary may change every other day and this may break your workflow.
> Only the latest nightly version will be downloaded and setup, and the version must be `nightly`.

#### Others

Or, check the following examples:
Expand All @@ -147,33 +172,33 @@ If you want to use the latest version of nushell you can specify this by set `ch
the latest version:
```yaml
- uses: hustcer/setup-nu@v3.6
- uses: hustcer/setup-nu@v3.7
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**.
**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.

```yaml
- uses: hustcer/setup-nu@v3.6
- uses: hustcer/setup-nu@v3.7
with:
version: '0.80'
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 |
| Name | Required | Description | Type | Default |
| ---------------- | -------- | ----------------------------------------------------------------------------------------- | ------ | ------- |
| `version` | no | A valid NPM-style semver specification, such as `0.86.0`, etc. and `nightly`. | 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](https://www.npmjs.com/package/semver).
This GitHub Action will install the latest matching release.
Expand Down
Loading

0 comments on commit 92f49b4

Please sign in to comment.