setup-nu icon indicating copy to clipboard operation
setup-nu copied to clipboard

how can i `use` a module with `setup-nu`?

Open amtoine opened this issue 2 years ago • 14 comments

hellord @hustcer :wave: :yum:

i have this CI where i try to use a module to update some data and push it automatically based on a schedule :smirk: but it fails with that kind of error :thinking:

is it possible to use a module easily with setup-nu? i tried changing NU_LIB_DIRS to contain pwd but that did not work :eyes:

amtoine avatar Apr 14 '23 18:04 amtoine

in the end i was able to work around the problem by

  • moving the module commands to standalone scripts in https://github.com/amtoine/nu-issue-tracker/commit/1503e4484c9f0a78183d79586402f097effae792
  • call the executable scripts directly from the CI in https://github.com/amtoine/nu-issue-tracker/commit/e7a056f20c55cd94e5bda10c6dac2f854d5b61fd

:+1:

amtoine avatar Apr 14 '23 20:04 amtoine

Thanks for the feed back, I will try to fix it, but I'm not sure is there a good way

hustcer avatar Apr 15 '23 00:04 hustcer

Thanks for the feed back, I will try to fix it, but I'm not sure is there a good way

:blush:

not urgent at all :relieved: the script fix does the job, it's just i love modules

ideas

  • that could be nice to be able to set the NU_LIB_DIRS variables in an env: block
  • and yeah, know about the current directory, especially with the checkout action, at parse-time

cheers :yum: :wave:

amtoine avatar Apr 15 '23 07:04 amtoine

I have tried many ways here: https://github.com/hustcer/setup-nu/commit/24412a454ca14e5b14b598f5bee67a06c6ab20c5, however, they all failed. It seemed that I can change the NU_LIB_DIRS in setup-nu action, but it will be overrode thus not work

hustcer avatar Apr 19 '23 10:04 hustcer

Maybe I can give it a try after nu v0.79 released due to https://github.com/nushell/nushell/issues/8870

hustcer avatar Apr 19 '23 10:04 hustcer

The only way works I found is here: https://github.com/hustcer/setup-nu/blob/develop/.github/workflows/module-test.yaml You need to copy your modules to NU_LIB_DIRS and then use it in the following step:

    - name: Cp Your Modules to NU_LIB_DIRS
      run: |
        let LIB_DIR = ($nu.config-path | path dirname | path join 'scripts')
        mkdir $LIB_DIR
        cp nu/common.nu $LIB_DIR
        print 'Available Nu Modules:'
        print (ls ($env.NU_LIB_DIRS | get 0))
    - name: Use Your Nu Modules In the Following Steps
      run: |
        use common.nu [get-env]
        print (get-env 'ABC-XYZ' 'DEFAULT-ABC-XYZ')

Running result: https://github.com/hustcer/setup-nu/actions/runs/4742880511/jobs/8421700478

hustcer avatar Apr 19 '23 11:04 hustcer

@hustcer wow thanks for all these tests, that's amazing :star_struck:

You need to copy your modules to NU_LIB_DIRS and then use it in the following step:

oooh i see what you're doing here and that it works. i think i prefer the script alternative right now though :thinking:

Maybe I can give it a try after nu v0.79 released due to https://github.com/nushell/nushell/issues/8870

well if you find something and want someone to test :smirk:

amtoine avatar Apr 19 '23 17:04 amtoine

Update: https://github.com/hustcer/setup-nu#use-modules It works for hustcer/[email protected], but not perfect, so I will leave this issue open

hustcer avatar Sep 11 '23 08:09 hustcer

noice, will see if i encounter this again :relieved:

amtoine avatar Sep 11 '23 16:09 amtoine

I came to request nupm default installation for nupm test but it would hypothetically make it easy to install modules from the registry too (recent addition)!

texastoland avatar Mar 13 '24 22:03 texastoland

@texastoland That's a good idea. PRs are welcomed.

hustcer avatar Mar 14 '24 00:03 hustcer

I looked at the code but it wasn't obvious where to start. I'm motivated to get it working for CI testing on nu_scripts though. Better in a channel or DM if I need help?

texastoland avatar Mar 14 '24 00:03 texastoland

You can contact me by discord, username hustcer

hustcer avatar Mar 14 '24 01:03 hustcer

Related to the original issue I tried all the following unsuccessfully:

  • shell: nu -I "$PWD" {0}
  • shell: nu -I "$GITHUB_WORKSPACE" {0}
  • shell: nu -I '${{ GITHUB_WORKSPACE }}' {0}
  • shell: nu -I '${{ github.workspace }}' {0}

But use ${{ github.workspace }}/mod_name works great for now 👍🏼

texastoland avatar Mar 14 '24 18:03 texastoland