Skip to content

Commit

Permalink
test: add kcl language server install script tests.
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 22, 2023
1 parent 6c0e1c4 commit eba441a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 27 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/install-kcl-lsp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: script-kcl-lsp
on:
push:
branches:
- main
jobs:
check-macos:
strategy:
matrix:
os: [macos-11, macos-12, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Check Install Script KCL Language Server
run: static/script/install-kcl-lsp.sh
- name: Check run
shell: bash -leo pipefail {0}
run: sudo kcl-language-server version

check-linux:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Check Install Script KCL Language Server
run: static/script/install-kcl-lsp.sh
- name: Check run
shell: bash -ieo pipefail {0}
run: kcl-language-server version

check-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Check Install Script KCL Language Server
run: static/script/install-cli.ps1
- name: Check run
run: C:\kclvm\bin\kcl-language-server.exe version
22 changes: 11 additions & 11 deletions static/script/install-kcl-lsp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ GITHUB_REPO=kcl
# KCL filename
KCL_CLI_FILENAME=kcl-language-server
# KCL file path
KCL_CLI_FILE=${KCL_INSTALL_DIR}/kclvm/bin/${KCL_CLI_FILENAME}
KCL_CLI_FILE=${KCL_INSTALL_DIR}/bin/${KCL_CLI_FILENAME}
# KCL Home dir
KCLVM_HOME_DIR=${KCL_INSTALL_DIR}/kclvm
KCLVM_HOME_DIR=${KCL_INSTALL_DIR}/

# --- helper functions for logs ---
info() {
Expand Down Expand Up @@ -126,7 +126,7 @@ checkExistingKCL() {
if [ -f "$KCL_CLI_FILE" ]; then
# Check the KCL CLI version
echo -e "\nKCL is detected:"
$KCL_CLI_FILE -V
$KCL_CLI_FILE version
echo -e "Reinstalling KCL into ${KCL_CLI_FILE} ...\n"
fi
}
Expand Down Expand Up @@ -202,15 +202,15 @@ installFile() {
fi

# Copy temp kclvm folder into the target installation directory.
info "Copy the kclvm folder $tmp_kclvm_folder into the target installation directory $KCL_INSTALL_DIR"
info "Copy the kcl language server binary $tmp_kclvm_folder/bin/kcl-language-server into the target installation directory $KCL_INSTALL_DIR"
runAsRoot cp -f $tmp_kclvm_folder/bin/kcl-language-server $KCL_INSTALL_DIR/bin

if [ -f "$KCL_CLI_FILE" ]; then
updateProfile "$KCLVM_HOME_DIR" && info "Finished" "kcl-language-server installed into $KCL_INSTALL_DIR/bin successfully."
# Check the KCL CLI version
runAsRoot kcl-language-server version
else
error "Failed to install KCL into $KCL_CLI_FILE"
error "Failed to install KCL language server into $KCL_CLI_FILE"
exit 1
fi
}
Expand All @@ -231,11 +231,11 @@ updateProfile() {
return 1
else
if ! command grep -qc 'KCLVM_HOME' "$detected_profile"; then
info "The KCLVM PATH string is"
info "The KCL PATH string is"
info $path_str
command printf "$path_str" >> "$detected_profile"
else
warn "Your profile ($detected_profile) already mentions kcl and has not been changed."
warn "Your profile ($detected_profile) already mentions kcl language server and has not been changed."
fi
fi
}
Expand Down Expand Up @@ -317,7 +317,7 @@ END_BASH_SCRIPT
fail_trap() {
result=$?
if [ "$result" != "0" ]; then
error "Failed to install KCL"
error "Failed to install KCL language server"
info "For support, go to https://kcl-lang.io"
fi
cleanup
Expand All @@ -331,10 +331,10 @@ cleanup() {
}

installCompleted() {
echo -e "\nPlease add ${KCL_INSTALL_DIR}/kclvm/bin into your PATH"
echo -e "\nPlease add ${KCL_INSTALL_DIR}/bin into your PATH"
echo -e "Remeber run the command source ~/.bash_profile or source ~/.bashrc to ensure your PATH is effective"
echo -e "Reopen a terminal and execute `kcl -h` to ensure successful installation"
echo -e "\nTo get started with KCL, please visit https://kcl-lang.io/docs/user_docs/getting-started/kcl-quick-start"
echo -e "Reopen a terminal and execute `kcl-language-server version` to ensure successful installation"
echo -e "\nTo get started with KCL language server, please visit https://kcl-lang.io/docs/user_docs/getting-started/kcl-quick-start"
}

# -----------------------------------------------------------------------------
Expand Down
34 changes: 18 additions & 16 deletions static/script/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# Reference: https://github.com/dapr/cli/tree/master/install
# ------------------------------------------------------------

# @Warning: This script will be deprecated in KCL v0.8.0.

param (
[string]$Version,
[string]$KCLRoot = "$Env:SystemDrive\kclvm",
Expand All @@ -29,11 +27,11 @@ $ErrorActionPreference = 'stop'
$KCLRoot = $KCLRoot -replace ' ', '` '

# Constants
$KCLCliFileName = "kcl.exe"
$KCLCliFileName = "kcl-language-server.exe"
$KCLCliFileBinPath = "${KCLRoot}\bin"
$KCLCliFilePath = "${KCLCliFileBinPath}\${KCLCliFileName}"

# GitHub Org and repo hosting KCL CLI
# GitHub Org and repo hosting KCL language server CLI
$GitHubOrg = "kcl-lang"
$GitHubRepo = "kcl"

Expand All @@ -58,12 +56,12 @@ if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPa

# Check if KCL CLI is installed.
if (Test-Path $KCLCliFilePath -PathType Leaf) {
Write-Warning "KCL is detected - $KCLCliFilePath"
Invoke-Expression "$KCLCliFilePath --version"
Write-Output "Reinstalling KCL..."
Write-Warning "KCL language-server is detected - $KCLCliFilePath"
Invoke-Expression "$KCLCliFilePath version"
Write-Output "Reinstalling KCL language server..."
}
else {
Write-Output "Installing KCL..."
Write-Output "Installing KCL language server..."
}

# Create KCL Directory
Expand Down Expand Up @@ -113,7 +111,7 @@ function GetWindowsAsset {
else {
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*windows.zip" }
if (!$windowsAsset) {
throw "Cannot find the windows KCL CLI binary"
throw "Cannot find the windows KCL language-server binary"
}
[hashtable]$return = @{}
$return.url = $windowsAsset.url
Expand All @@ -124,7 +122,7 @@ function GetWindowsAsset {

$release = GetVersionInfo -Version $Version -Releases $releases
if (!$release) {
throw "Cannot find the specified KCL CLI binary version"
throw "Cannot find the specified KCL language server binary version"
}
$asset = GetWindowsAsset -Release $release
$zipFileUrl = $asset.url
Expand All @@ -139,18 +137,23 @@ $progressPreference = 'SilentlyContinue';
Invoke-WebRequest -Headers $githubHeader -Uri $zipFileUrl -OutFile $zipFilePath
$progressPreference = $oldProgressPreference;
if (!(Test-Path $zipFilePath -PathType Leaf)) {
throw "Failed to download KCL binary - $zipFilePath"
throw "Failed to download KCL language server binary - $zipFilePath"
}

# Extract KCL CLI to $KCLRoot
# Extract KCL language server to $KCLRoot
Write-Output "Extracting $zipFilePath..."
$tempFolder = New-Item -ItemType Directory -Path "$env:TEMP\tempfolder" -Force
Expand-Archive -Force -Path $zipFilePath -DestinationPath $tempFolder.FullName
Copy-Item -Path "$tempFolder\$KCLCliFileName" -Destination $KCLRoot

Microsoft.Powershell.Archive\Expand-Archive -Force -Path $zipFilePath -DestinationPath $KCLRoot
if (!(Test-Path $KCLCliFilePath -PathType Leaf)) {
throw "Failed to download KCL archieve - $zipFilePath"
throw "Failed to download KCL language server archieve - $zipFilePath"
}

# Clean up zipfile
Write-Output "Clean up $zipFilePath..."
Remove-Item -Path $tempFolder.FullName -Force -Recurse
Remove-Item $zipFilePath -Force

# Add KCLRoot directory to User Path environment variable
Expand All @@ -167,6 +170,5 @@ else {
Write-Output "Added $KCLCliFileBinPath to User Path - $UserPathEnvironmentVar"
}

Write-Output "`r`nKCL is installed successfully."
Write-Output "To get started with KCL, please visit https://kcl-lang.io/docs/user_docs/getting-started/kcl-quick-start ."
Write-Output "Ensure that Docker Desktop is set to Linux containers mode when you run KCL in self hosted mode."
Write-Output "`r`nKCL language server is installed successfully."
Write-Output "To get started with KCL language server, please visit https://kcl-lang.io/docs/user_docs/getting-started/kcl-quick-start ."

0 comments on commit eba441a

Please sign in to comment.