From eba441abd8ff7eb5c14c2f4b0fb965f92acf8a82 Mon Sep 17 00:00:00 2001 From: peefy Date: Wed, 22 Nov 2023 10:21:53 +0800 Subject: [PATCH] test: add kcl language server install script tests. Signed-off-by: peefy --- .github/workflows/install-kcl-lsp.yml | 40 +++++++++++++++++++++++++++ static/script/install-kcl-lsp.sh | 22 +++++++-------- static/script/install.ps1 | 34 ++++++++++++----------- 3 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/install-kcl-lsp.yml diff --git a/.github/workflows/install-kcl-lsp.yml b/.github/workflows/install-kcl-lsp.yml new file mode 100644 index 00000000..793e6463 --- /dev/null +++ b/.github/workflows/install-kcl-lsp.yml @@ -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 diff --git a/static/script/install-kcl-lsp.sh b/static/script/install-kcl-lsp.sh index 9d4dd4ae..75d91677 100755 --- a/static/script/install-kcl-lsp.sh +++ b/static/script/install-kcl-lsp.sh @@ -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() { @@ -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 } @@ -202,7 +202,7 @@ 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 @@ -210,7 +210,7 @@ installFile() { # 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 } @@ -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 } @@ -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 @@ -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" } # ----------------------------------------------------------------------------- diff --git a/static/script/install.ps1 b/static/script/install.ps1 index 9d0c0287..ad837ef5 100644 --- a/static/script/install.ps1 +++ b/static/script/install.ps1 @@ -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", @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ."