diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e8d7412..ff4eea5c 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,45 +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 }}" + 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 }}" 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