Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor the CI in scripts #36

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defaults:

env:
NU_LOG_LEVEL: DEBUG
CI_SCRIPTS: ".github/workflows/scripts"

jobs:
tests:
Expand All @@ -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 }}"
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/scripts/install-nightly-nushell.sh
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 35 additions & 0 deletions .github/workflows/scripts/set-platform-specific-variables.sh
Original file line number Diff line number Diff line change
@@ -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