From e572b86a7fffd60300bcb31e7f04e2571dead846 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 10:11:03 +0200 Subject: [PATCH 1/9] get the latest build with jq and extract the tarball --- .github/workflows/ci.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 330f7b7..cb1de6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,13 +18,15 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup Rust toolchain - uses: actions-rust-lang/setup-rust-toolchain@v1.5.0 - with: - rustflags: "" + - name: Install Nushell from Nightly + run: | + tarball=$(curl -L https://api.github.com/repos/nushell/nightly/releases | jq 'sort_by(.published_at) | reverse | .[0].assets' | jq '.[] | select(.name | test("x86_64-linux-gnu-full.tar.gz")) | {name, browser_download_url}') + name=$(echo $tarball | jq '.name' | tr -d '"' | sed 's/.tar.gz$//') + url=$(echo $tarball | jq '.browser_download_url' | tr -d '"') - - name: Install Nushell - run: cargo install --locked --git https://github.com/nushell/nushell.git nu + curl -fLo $name $url + tar xvf $name --directory /tmp + cp /tmp/$name/nu $HOME/nu - name: Run the tests - run: nu --commands "use $PWD/nupm/; nupm test" + run: $HOME/nu --commands "use $PWD/nupm/; nupm test" From 177357c7cdaf046d35a8cd48e17d896f658bc831 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 10:31:43 +0200 Subject: [PATCH 2/9] use `$nu.current-exe` to run Nushell in `nupm test` and `nupm install` --- nupm/install.nu | 2 +- nupm/test.nu | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index 799a9ee..684bceb 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -128,7 +128,7 @@ def install-path [ do { cd $tmp_dir - nu $build_file ($pkg_dir | path join 'package.nuon') + ^$nu.current-exe $build_file ($pkg_dir | path join 'package.nuon') } rm -rf $tmp_dir diff --git a/nupm/test.nu b/nupm/test.nu index b797033..ca29a94 100644 --- a/nupm/test.nu +++ b/nupm/test.nu @@ -18,7 +18,7 @@ export def main [ print $'Testing package ($pkg_root)' cd $pkg_root - let tests = nu [ + let tests = ^$nu.current-exe [ --no-config-file --commands 'use tests/ @@ -34,7 +34,7 @@ export def main [ | where ($filter in $it) | par-each {|test| let res = do { - nu [ + ^$nu.current-exe [ --no-config-file --commands $'use tests/; ($test)' From 194d24d6b5c6d67a0c01a8f6569210d8d7db76c9 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 10:38:18 +0200 Subject: [PATCH 3/9] break the long curl call --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb1de6e..3c27905 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,11 @@ jobs: - name: Install Nushell from Nightly run: | - tarball=$(curl -L https://api.github.com/repos/nushell/nightly/releases | jq 'sort_by(.published_at) | reverse | .[0].assets' | jq '.[] | select(.name | test("x86_64-linux-gnu-full.tar.gz")) | {name, browser_download_url}') + tarball=$(\ + curl -L https://api.github.com/repos/nushell/nightly/releases \ + | jq 'sort_by(.published_at) | reverse | .[0].assets'\ + | jq '.[] | select(.name | test("x86_64-linux-gnu-full.tar.gz")) | {name, browser_download_url}'\ + ) name=$(echo $tarball | jq '.name' | tr -d '"' | sed 's/.tar.gz$//') url=$(echo $tarball | jq '.browser_download_url' | tr -d '"') From b965ca0eaa1699acb874ecb3d6cab14325d36b2a Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 10:45:09 +0200 Subject: [PATCH 4/9] generalize to the other platforms --- .github/workflows/ci.yml | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c27905..b9a8a5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,10 @@ on: name: continuous-integration +defaults: + run: + shell: bash + jobs: tests: strategy: @@ -18,19 +22,40 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set platform-specific variables + run: | + if [ "${{ runner.os }}" = "Linux" ]; then + echo "ARCH=x86_64-linux-gnu-full" >> $GITHUB_ENV + echo "EXT=tar.gz" >> $GITHUB_ENV + echo "NU_BIN=nu" >> $GITHUB_ENV + elif [ "${{ runner.os }}" = "Windows" ]; then + echo "ARCH=x86_64-pc-windows-msvc" >> $GITHUB_ENV + echo "EXT=zip" >> $GITHUB_ENV + echo "NU_BIN=nu.exe" >> $GITHUB_ENV + elif [ "${{ runner.os }}" = "macOS" ]; then + echo "ARCH=x86_64-apple-darwin" >> $GITHUB_ENV + echo "EXT=tar.gz" >> $GITHUB_ENV + echo "NU_BIN=nu" >> $GITHUB_ENV + fi + - name: Install Nushell from Nightly run: | tarball=$(\ curl -L https://api.github.com/repos/nushell/nightly/releases \ | jq 'sort_by(.published_at) | reverse | .[0].assets'\ - | jq '.[] | select(.name | test("x86_64-linux-gnu-full.tar.gz")) | {name, browser_download_url}'\ + | jq '.[] | select(.name | test("${{ env.ARCH }}.${{ env.EXT }}")) | {name, browser_download_url}'\ ) - name=$(echo $tarball | jq '.name' | tr -d '"' | sed 's/.tar.gz$//') + name=$(echo $tarball | jq '.name' | tr -d '"' | sed 's/.${{ env.EXT }}$//') url=$(echo $tarball | jq '.browser_download_url' | tr -d '"') curl -fLo $name $url - tar xvf $name --directory /tmp - cp /tmp/$name/nu $HOME/nu + + if [ "${{ env.EXT }}" = "tar.gz" ]; then + tar xvf $name --directory /tmp + elif [ "${{ env.EXT }}" = "zip" ]; then + unzip $name -d "/tmp/$name" + fi + cp "/tmp/$name/${{ env.NU_BIN }}" "$HOME/${{ env.NU_BIN }}" - name: Run the tests - run: $HOME/nu --commands "use $PWD/nupm/; nupm test" + run: "$HOME/${{ env.NU_BIN }}" --commands "use $PWD/nupm/; nupm test" From 93555f5380ac05c648fe618b4d7171688c5eefb0 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 11:01:52 +0200 Subject: [PATCH 5/9] show the version of Nushell --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9a8a5b..4797de4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,5 +57,8 @@ jobs: fi cp "/tmp/$name/${{ env.NU_BIN }}" "$HOME/${{ env.NU_BIN }}" + - name: Show Nushell Version + run: "$HOME/${{ env.NU_BIN }}" --commands "version" + - name: Run the tests run: "$HOME/${{ env.NU_BIN }}" --commands "use $PWD/nupm/; nupm test" From 27dc6649da958dd2a1ed0c19703cc55244394958 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 11:25:52 +0200 Subject: [PATCH 6/9] trigger the CI on workflow dispatch (manually) --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4797de4..713ebd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ on: push: branches: - main + workflow_dispatch: name: continuous-integration From 696f6108eb7d5b0da839f57a5e04c234e9da6a05 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 11:30:36 +0200 Subject: [PATCH 7/9] fix workflow file --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 713ebd9..01c6757 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,9 @@ jobs: cp "/tmp/$name/${{ env.NU_BIN }}" "$HOME/${{ env.NU_BIN }}" - name: Show Nushell Version - run: "$HOME/${{ env.NU_BIN }}" --commands "version" + run: | + "$HOME/${{ env.NU_BIN }}" --commands "version" - name: Run the tests - run: "$HOME/${{ env.NU_BIN }}" --commands "use $PWD/nupm/; nupm test" + run: | + "$HOME/${{ env.NU_BIN }}" --commands "use $PWD/nupm/; nupm test" From 2f186ecbaa7cc3fc86b18018898f0da7d2856e2e Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 15:15:59 +0200 Subject: [PATCH 8/9] fix the module path when on windows --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01c6757..2228ea6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,4 +64,11 @@ jobs: - name: Run the tests run: | + # NOTE: for some reason, `$PWD` gives an incorrect path on Windows + # it looks like `/d/a/nupm/nupm` where it should really be `d:\a\nupm\nupm` + if [ "${{ runner.os }}" = "Windows" ]; then + # NOTE: this commands changes the `/` into `\` and replaces the first one with a ":" + "$HOME/${{ env.NU_BIN }}" --commands "use $(echo $PWD | tr '/' '\\' | sed 's/^\\\(.\)\\/\1:\\/')/nupm/; nupm test" + else "$HOME/${{ env.NU_BIN }}" --commands "use $PWD/nupm/; nupm test" + fi From b28d6a5ec53a6afb2d4f7e4cdc7ffa3e25f2f847 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 12 Oct 2023 16:48:59 +0200 Subject: [PATCH 9/9] refactor the Windows magic inside `$GITHUB_ENV` block --- .github/workflows/ci.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2228ea6..33cdadf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,14 +29,20 @@ jobs: echo "ARCH=x86_64-linux-gnu-full" >> $GITHUB_ENV echo "EXT=tar.gz" >> $GITHUB_ENV echo "NU_BIN=nu" >> $GITHUB_ENV + echo "CWD=$PWD" >> $GITHUB_ENV elif [ "${{ runner.os }}" = "Windows" ]; then echo "ARCH=x86_64-pc-windows-msvc" >> $GITHUB_ENV echo "EXT=zip" >> $GITHUB_ENV echo "NU_BIN=nu.exe" >> $GITHUB_ENV + # NOTE: for some reason, `$PWD` gives an incorrect path on Windows, e.g. it looks like + # `/d/a/nupm/nupm` where it should really be `d:\a\nupm\nupm`: this commands changes the + # `/` into `\` and replaces the first part of the path with "x:\" + echo "CWD=$(echo $PWD | tr '/' '\\' | sed 's/^\\\(.\)\\/\1:\\/')" >> $GITHUB_ENV elif [ "${{ runner.os }}" = "macOS" ]; then echo "ARCH=x86_64-apple-darwin" >> $GITHUB_ENV echo "EXT=tar.gz" >> $GITHUB_ENV echo "NU_BIN=nu" >> $GITHUB_ENV + echo "CWD=$PWD" >> $GITHUB_ENV fi - name: Install Nushell from Nightly @@ -60,15 +66,8 @@ jobs: - name: Show Nushell Version run: | - "$HOME/${{ env.NU_BIN }}" --commands "version" + "$HOME/${{ env.NU_BIN }}" --commands "version" - name: Run the tests run: | - # NOTE: for some reason, `$PWD` gives an incorrect path on Windows - # it looks like `/d/a/nupm/nupm` where it should really be `d:\a\nupm\nupm` - if [ "${{ runner.os }}" = "Windows" ]; then - # NOTE: this commands changes the `/` into `\` and replaces the first one with a ":" - "$HOME/${{ env.NU_BIN }}" --commands "use $(echo $PWD | tr '/' '\\' | sed 's/^\\\(.\)\\/\1:\\/')/nupm/; nupm test" - else - "$HOME/${{ env.NU_BIN }}" --commands "use $PWD/nupm/; nupm test" - fi + "$HOME/${{ env.NU_BIN }}" --commands "use ${{ env.CWD }}/nupm/; nupm test"