# setup-nu [![`main`åæ¯æµè¯](https://github.com/hustcer/setup-nu/actions/workflows/latest-matrix.yaml/badge.svg)](https://github.com/hustcer/setup-nu/actions/workflows/latest-matrix.yaml) æ¤ GitHub Action å°ä¸ºæ¨é ç½® [Nushell](https://github.com/nushell/nushell) è¿è¡ç¯å¢ã ## 使ç¨è¯´æ ### ä¾å #### åºç¡ä½¿ç¨ å¨å¤§å¤æ°æ åµä¸ï¼ä½ åªéè¦å¨å·¥ä½æµç¨ä¸éè¿ `version` å段æå®è¦ä½¿ç¨ç Nushell ççæ¬å³å¯ãæ¯å¦ä¸é¢çä¾åå°ä¼å®è£ [Nushell](https://github.com/nushell/nushell) ç`v0.90`çæ¬ãç¶åä½ å¯ä»¥å¨åç»æ¥éª¤ä¸é ç½®ä½ æ³è¿è¡çå½ä»¤ï¼æåå«å¿äºè®¾ç½®`shell: nu {0}`以使å½ä»¤è¢«`nu`æ§è¡ï¼ ```yaml - uses: hustcer/setup-nu@v3 with: version: "0.90" # ä¸è¦ä½¿ç¨ 0.90, å®ä¼è¢«è®¤ä¸ºæ¯ä¸ä¸ªæµ®ç¹æ°å¹¶è½¬æ¢ä¸º 0.9, ä½ å¯ä»¥ä½¿ç¨ v0.90/0.90.0 æè '0.90'(å äºå¼å·åæå符串) - 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 ``` #### 设为é»è®¤ Shell å½ç¶ï¼æ´ç®æ´çåæ³æ¯éè¿è®¾ç½® `defaults.run.shell` æ¥è®©æ¨çèæ¬æè å½ä»¤é»è®¤ç± `nu` æ¥æ§è¡ï¼å¦ä¸ï¼ ```yaml name: basic on: push defaults: run: shell: nu {0} jobs: basic-usage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - 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 ``` #### 使ç¨æ¨¡å è¥æ³å¨ `Nu` ä¸ä½¿ç¨æ¨¡å, å¯ä»¥åèå¦ä¸ç¤ºä¾ï¼ 1. éè¿ `nu -c` 使ç¨æ¨¡å ```yaml - name: Setup nu uses: hustcer/setup-nu@v3 with: version: 0.101.0 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')" ``` ä½ éè¦å° `nu` 代ç å è£¹å¨ `nu -c ""` ä¸å¹¶æ§è¡, èä¸è¦æ±ä½ 使ç¨ç Nu çæ¬å¨ `0.69` å以ä¸ã 2. éè¿ç»å¯¹è·¯å¾ä½¿ç¨æ¨¡å ```yaml - name: Setup nu uses: hustcer/setup-nu@v3 with: version: 0.101.0 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') ``` åæ ·ï¼è¦æ±ä½ 使ç¨ç Nu çæ¬å¨ `0.69` å以ä¸ã 3. å°ä½ ç Nu Modules æ·è´å° `$env.NU_LIB_DIRS` çä»»æä¸ä¸ªç®å½éé¢ ```yaml - name: Setup nu@latest uses: hustcer/setup-nu@v3 with: version: 0.101.0 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') ``` è¦æ³éè¿è¿ç§æ¹å¼ä½¿ç¨ Nu Modules 请确ä¿ä½ ç Nu çæ¬ä¸ä½äº `0.85`ã è¿äºæ¹å¼å¹¶ä¸å®ç¾, ä¸è¿ç¡®å®å¯ç¨ï¼å¦æä½ ææ´å¥½çåæ³ï¼æç¸ä¿¡ä¸å®æçï¼è¯·åè¯æï¼æè å¦æè½æ个 PR å°±æ´å¥½å¦ï¼ #### ä½¿ç¨ Nu ææ°ç `nightly` çæ¬ `Nushell` ç®åæ£å¤äºæ´»è·å¼åæï¼å¦æä½ æ³ä½¿ç¨ææ°çç¹æ§ä¹å¯ä»¥éè¿å°çæ¬è®¾ç½®ä¸º `nightly` è·å¾ï¼æ¯å¦ä¸é¢çä¾åï¼ ```yaml - uses: hustcer/setup-nu@v3 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** > 请谨æ ä½¿ç¨ `Nushell` `nightly` çæ¬: nu çäºè¿å¶æ件æ¯å¤©é½å¯è½åçååï¼å¯è½ä¼å¯¼è´ä½ çå·¥ä½æµæ æ³æ£å¸¸å·¥ä½ã > èä¸åªæææ°ç `nightly` çæ¬ä¼è¢«ä¸è½½å¹¶é 置好, åæ¶å®ççæ¬åªè½è¢«æå®ä¸º `nightly` èä¸è½æ¯å ¶å®å¼ã #### å ¶å® æè ä½ ä¹å¯ä»¥æ¥çä¸é¢å 个ä¾åï¼ 1. [run-test.yaml](https://github.com/hustcer/setup-nu/blob/main/.github/workflows/run-test.yaml) 2. [run-matrix.yaml](https://github.com/hustcer/setup-nu/blob/main/.github/workflows/latest-matrix.yaml) 3. è¿é¶ä½¿ç¨: çç Nushell æ¯å¦ä½åççå§ [å·¥ä½æµ](https://github.com/nushell/nushell/blob/main/.github/workflows/release.yml), [èæ¬](https://github.com/nushell/nushell/blob/main/.github/workflows/release-pkg.nu) å¦æä½ æ³ä½¿ç¨ææ°çæ¬ç Nushellï¼ä½ å¯ä»¥éè¿è®¾ç½® `check-latest` 为 `true` æ¥åå°ï¼å®ä¸`version: '*'`é ç½®çææç¸åï¼ä½æ´æ读ï¼ãä¾å¦ï¼ä»¥ä¸å°ä¼å®è£ ææ°çæ¬ç Nushellï¼ ```yaml - uses: hustcer/setup-nu@v3 with: check-latest: true - run: print $'Nu version info:(char nl)'; version ``` **å¤æ³¨**: **_å¨ Nushell 1.0 åå¸ä¹åï¼æ¯ä¸ªçæ¬å¯è½ä¼æè¾å¤§çååï¼æ以建议æ¨ä½¿ç¨æå®ç Nushell çæ¬_**ã ### è¾å ¥ | å称 | å¿ å¡« | æè¿° | ç±»å | é»è®¤å¼ | | ---------------- | ---- | ------------------------------------------------------------------------------------------------------------------- | ------ | --------- | | `version` | å¦ | åæ³ç NPM é£æ ¼ç semver çæ¬ï¼such as `0.86.0` ä¹å¯ä»¥ä¸º`nightly`. | string | \* | | `check-latest` | å¦ | å¯ä»¥è®¾ç½®ä¸º `true` å¦æä½ æ³ä½¿ç¨ææ°ç Nushell çæ¬ | bool | false | | `enable-plugins` | å¦ | å¯ä»¥è®¾ç½®ä¸º `true` å¦æä½ éè¦æ³¨åäºè¿å¶å å çæ件æè éå·åéçæ件å称å符串ï¼`nu_plugin_polars,nu_plugin_query`, éè¦ Nu çæ¬ >= v0.86 | bool\|string | false | | `features` | å¦ | å¯é项: `default`ï¼`full`, 设置为 `full` å°å å« `extra` å `dataframe` ä¸çå½ä»¤, `full` ä» æ¯æ `Nu` `v0.86` ~ `v0.93`, ä¹åçæ¬ä¸é»è®¤çæ¬å°å å«ææç¹æ§ | string | `default` | | `github-token` | å¦ | ä½ ç GitHub Token æè PAT token | string | `${{ github.token }}` | æ¨å¨ `version` å段æå®ç **semver çæ¬** ä¼ç´æ¥ä¼ éç» NPM ç [semver å ](https://www.npmjs.com/package/semver)ãæ¤ GitHub Action å°å®è£ ææ°çå¹é çæ¬ã ## è®¸å¯ Licensed under: - MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)