From f8607de5b5dd2deaad60b2ae9adcb513c3a6e04b Mon Sep 17 00:00:00 2001 From: amtoine Date: Tue, 24 Oct 2023 18:41:52 +0200 Subject: [PATCH 1/2] refactor the CI in scripts --- .github/workflows/ci.yml | 43 ++----------------- .../scripts/install-nightly-nushell.sh | 22 ++++++++++ .../set-platform-specific-variables.sh | 35 +++++++++++++++ 3 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/scripts/install-nightly-nushell.sh create mode 100644 .github/workflows/scripts/set-platform-specific-variables.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e8d7412..20b0570e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ defaults: env: NU_LOG_LEVEL: DEBUG + CI_SCRIPTS: ".github/workflows/scripts" jobs: tests: @@ -27,48 +28,10 @@ jobs: - 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 - echo "NUPM=$HOME/nupm" >> $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, `$HOME` gives an incorrect path on Windows, e.g. it looks like - # `/c/Users/runneradmin` where it should really be `c:\Users\runneradmin`: this commands - # changes the `/` into `\` and replaces the first part of the path with "x:\" - echo "NUPM=$(echo $HOME | tr '/' '\\' | sed 's/^\\\(.\)\\/\1:\\/')/nupm" >> $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 "NUPM=$HOME/nupm" >> $GITHUB_ENV - fi + run: bash $CI_SCRIPTS/set-platform-specific-variables.sh "${{ runner.os }}" >> "$GITHUB_ENV" - 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("${{ env.ARCH }}.${{ env.EXT }}")) | {name, browser_download_url}'\ - ) - name=$(echo $tarball | jq '.name' | tr -d '"' | sed 's/.${{ env.EXT }}$//') - url=$(echo $tarball | jq '.browser_download_url' | tr -d '"') - - curl -fLo $name $url - - 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: Install Nupm from Source - run: git clone https://github.com/nushell/nupm "${{ env.NUPM }}" + run: bash $CI_SCRIPTS/install-nightly-nushell.sh "${{ env.ARCH }}" "${{ env.EXT }}" "${{ env.NU_BIN }}" - name: Show Nushell Version run: | diff --git a/.github/workflows/scripts/install-nightly-nushell.sh b/.github/workflows/scripts/install-nightly-nushell.sh new file mode 100644 index 00000000..9eb56880 --- /dev/null +++ b/.github/workflows/scripts/install-nightly-nushell.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +arch="$1" +ext="$2" +nu="$3" + +tarball=$(\ + curl -L https://api.github.com/repos/nushell/nightly/releases \ + | jq 'sort_by(.published_at) | reverse | .[0].assets'\ + | jq ".[] | select(.name | test(\"$arch.$ext\")) | {name, browser_download_url}"\ +) +name=$(echo $tarball | jq '.name' | tr -d '"' | sed "s/.$ext$//") +url=$(echo $tarball | jq '.browser_download_url' | tr -d '"') + +curl -fLo $name $url + +if [ "$ext" = "tar.gz" ]; then + tar xvf $name --directory /tmp +elif [ "$ext" = "zip" ]; then + unzip $name -d "/tmp/$name" +fi +cp "/tmp/$name/$nu" "$HOME/$nu" diff --git a/.github/workflows/scripts/set-platform-specific-variables.sh b/.github/workflows/scripts/set-platform-specific-variables.sh new file mode 100644 index 00000000..6d747898 --- /dev/null +++ b/.github/workflows/scripts/set-platform-specific-variables.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +os="$1" + +if [ "$os" = "Linux" ]; then + env=$(echo " + ARCH=x86_64-linux-gnu-full + EXT=tar.gz + NU_BIN=nu + NUPM=$HOME/nupm + CWD=$PWD + ") +elif [ "$os" = "Windows" ]; then + env=$(echo " + ARCH=x86_64-pc-windows-msvc + EXT=zip + NU_BIN=nu.exe + NUPM=$(echo $HOME | tr '/' '\\' | sed 's/^\\\(.\)\\/\1:\\/')/nupm + CWD=$(echo $PWD | tr '/' '\\' | sed 's/^\\\(.\)\\/\1:\\/') + ") +elif [ "$os" = "macOS" ]; then + env=$(echo " + ARCH=x86_64-apple-darwin + EXT=tar.gz + NU_BIN=nu + NUPM=$HOME/nupm + CWD=$PWD + ") +else + echo "UNKNOWN OS \`$os\`" + exit 1 +fi + +echo $env | tr " " "\n" +exit 0 From 6cb8f6c750732e0426271fe0941136ebafa452e9 Mon Sep 17 00:00:00 2001 From: amtoine Date: Tue, 24 Oct 2023 18:47:48 +0200 Subject: [PATCH 2/2] put back the installation of Nupm --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20b0570e..ff4eea5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,9 @@ jobs: - name: Install Nushell from Nightly run: bash $CI_SCRIPTS/install-nightly-nushell.sh "${{ env.ARCH }}" "${{ env.EXT }}" "${{ env.NU_BIN }}" + - name: Install Nupm from Source + run: git clone https://github.com/nushell/nupm "${{ env.NUPM }}" + - name: Show Nushell Version run: | "$HOME/${{ env.NU_BIN }}" --commands "version"