diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d8a36d..0b51f3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: - run: databricks version shell: bash - - run: ./setup-cli/test.sh $(cat ./setup-cli/VERSION) + - run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION) shell: bash action_with_version: @@ -57,7 +57,7 @@ jobs: - run: databricks version shell: bash - - run: ./setup-cli/test.sh 0.200.0 + - run: ./setup-cli/assert/version.sh 0.200.0 shell: bash install: @@ -79,13 +79,62 @@ jobs: - run: env shell: bash + - name: Assert databricks CLI is not already installed + run: ./setup-cli/assert/not-installed.sh + shell: bash + - run: ./setup-cli/install.sh shell: bash - run: databricks version shell: bash - - run: ./setup-cli/test.sh $(cat ./setup-cli/VERSION) + - name: Assert the version of the CLI installed + run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION) + shell: bash + + - name: Assert installation path is /usr/local/bin for non-windows platforms + run: ./setup-cli/assert/path.sh /usr/local/bin/databricks + if: matrix.os != 'windows-latest' + shell: bash + + - name: Assert installation path is /c/Windows for windows platforms + if: matrix.os == 'windows-latest' + run: ./setup-cli/assert/path.sh /c/Windows/databricks + + + install-dbr: + # All DBR images are built on top of Ubuntu + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + path: ./setup-cli + + # Append ~/bin to the PATH. This helps with the assertions in the next steps. + - run: echo "PATH=$PATH:$HOME/bin" >> $GITHUB_ENV + + - name: Assert databricks CLI is not already installed + run: ./setup-cli/assert/not-installed.sh + shell: bash + + - name: Install the CLI + run: ./setup-cli/install.sh + shell: bash + env: + DATABRICKS_RUNTIME_VERSION: value-does-not-matter + + - name: Run the CLI + run: databricks version + shell: bash + + - name: Assert the version of the CLI installed + run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION) + shell: bash + + - name: Assert installation path is ~/bin + run: ./setup-cli/assert/path.sh ~/bin/databricks shell: bash curl: @@ -104,11 +153,57 @@ jobs: with: path: ./setup-cli + - name: Assert databricks CLI is not already installed + run: ./setup-cli/assert/not-installed.sh + shell: bash + - run: curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/${{ github.sha }}/install.sh | sh shell: bash - run: databricks version shell: bash - - run: ./setup-cli/test.sh $(cat ./setup-cli/VERSION) + - name: Assert the version of the CLI installed + run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION) + shell: bash + + - name: Assert installation path is /usr/local/bin for non-windows platforms + run: ./setup-cli/assert/path.sh /usr/local/bin/databricks + if: matrix.os != 'windows-latest' + shell: bash + + - name: Assert installation path is /c/Windows for windows platforms + if: matrix.os == 'windows-latest' + run: ./setup-cli/assert/path.sh /c/Windows/databricks + + curl-dbr: + # All DBR images are built on top of Ubuntu + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + path: ./setup-cli + + # Append ~/bin to the PATH. This helps with the assertions in the next steps. + - run: echo "PATH=$PATH:$HOME/bin" >> $GITHUB_ENV + + - name: Assert databricks CLI is not already installed + run: ./setup-cli/assert/not-installed.sh + shell: bash + + - run: curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/${{ github.sha }}/install.sh | sh + shell: bash + env: + DATABRICKS_RUNTIME_VERSION: value-does-not-matter + + - run: databricks version + shell: bash + + - name: Assert the version of the CLI installed + run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION) + shell: bash + + - name: Assert installation path is ~/bin + run: ./setup-cli/assert/path.sh ~/bin/databricks shell: bash diff --git a/assert/not-installed.sh b/assert/not-installed.sh new file mode 100755 index 0000000..18957a5 --- /dev/null +++ b/assert/not-installed.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Assert databricks CLI is not already installed +if which databricks >/dev/null 2>&1; then + exit 1 +else + exit 0 +fi \ No newline at end of file diff --git a/assert/path.sh b/assert/path.sh new file mode 100755 index 0000000..5c4bccf --- /dev/null +++ b/assert/path.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -euo pipefail + +EXPECTED="${1:-invalid}" +ACTUAL=$(which databricks) + +if [[ "$EXPECTED" != "$ACTUAL" ]]; then + echo "Path \"$ACTUAL\" does not match expectation \"$EXPECTED\"." + exit 1 +else + echo "Path \"$ACTUAL\" matches expectation." + exit 0 +fi diff --git a/test.sh b/assert/version.sh similarity index 100% rename from test.sh rename to assert/version.sh diff --git a/install.sh b/install.sh index 1097d9f..dfb73bc 100755 --- a/install.sh +++ b/install.sh @@ -27,6 +27,15 @@ MINGW64_NT) ;; esac +# Set target to ~/bin if DATABRICKS_RUNTIME_VERSION environment variable is set. +if [ -n "$DATABRICKS_RUNTIME_VERSION" ]; then + # Set the installation target to ~/bin when run on DBR + TARGET="$HOME/bin" + + # Create the target directory if it does not exist + mkdir -p "$TARGET" +fi + # Include architecture in file name. ARCH="$(uname -m)" case "$ARCH" in