Skip to content

Jetbrains integration smoke test #8180

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

Merged
merged 1 commit into from
Mar 2, 2022
Merged
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
64 changes: 64 additions & 0 deletions .github/workflows/jetbrains-integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: JetBrains Test
on:
workflow_dispatch:
inputs:
secret_gateway_link:
type: string
description: Gateway Link
required: true
secret_access_token:
type: string
description: OAuth2 Access Token
required: true
secret_endpoint:
type: string
description: IDE Endpoint
required: true
jobs:
jetbrains-smoke-test-mac:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.17.3'
- uses: actions/setup-java@v2
with:
distribution: zulu
java-version: "11"
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Gateway Plugin
working-directory: components/ide/jetbrains/gateway-plugin
run: |
./gradlew -PpluginVersion=test buildPlugin
- name: Smoke Test
env:
LEEWAY_REMOTE_CACHE_BUCKET: gitpod-core-leeway-cache-branch
working-directory: dev/jetbrains-test
run: |
mkdir ./build && cp -r ../../components/ide/jetbrains/gateway-plugin/build/distributions/gitpod-gateway-test.zip build/gateway-test.zip

export GATEWAY_LINK=$(jq -r '.inputs.secret_gateway_link' $GITHUB_EVENT_PATH)
export GITPOD_TEST_ACCESSTOKEN=$(jq -r '.inputs.secret_access_token' $GITHUB_EVENT_PATH)
export WS_ENDPOINT=$(jq -r '.inputs.secret_endpoint' $GITHUB_EVENT_PATH)
export GATEWAY_PLUGIN_PATH=$(pwd)/build/gateway-test.zip

mkdir -p ~/Library/Application\ Support/JetBrains/consentOptions
echo -n "rsch.send.usage.stat:1.1:0:1644945193441" > ~/Library/Application\ Support/JetBrains/consentOptions/accepted
mkdir -p ~/Library/Application\ Support/JetBrains/JetBrainsClient/options
touch ~/Library/Application\ Support/JetBrains/JetBrainsClient/options/ide.general.xml
gradle :test
- name: Move video
if: always()
run: |
cp -r dev/jetbrains-test/video dev/jetbrains-test/build/reports
- name: Save report
if: always()
uses: actions/upload-artifact@v2
with:
name: video
path: |
dev/jetbrains-test/build/reports
7 changes: 7 additions & 0 deletions .werft/run-integration-tests-ide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,20 @@ pod:
secretKeyRef:
name: integration-test-user
key: token
- name: ROBOQUAT_TOKEN
valueFrom:
secretKeyRef:
name: github-roboquat-automatic-changelog
key: token
command:
- /bin/bash
- -c
- |
sleep 1
set -Eeuo pipefail

printf '{{ toJson .Annotations }}' > context.json

echo "[prep] receiving config..."
export GOOGLE_APPLICATION_CREDENTIALS="/config/gcloud/legacy_credentials/[email protected]/adc.json"
echo "[prep] received config."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal class GitpodAuthService : OAuthServiceBase<Credentials>() {
getAccessToken(gitpodHost) != null

fun getAccessToken(gitpodHost: String) =
PasswordSafe.instance.getPassword(getAccessTokenCredentialAttributes(gitpodHost))
System.getenv("GITPOD_TEST_ACCESSTOKEN") ?: PasswordSafe.instance.getPassword(getAccessTokenCredentialAttributes(gitpodHost))

fun setAccessToken(gitpodHost: String, accessToken: String?) {
PasswordSafe.instance.setPassword(getAccessTokenCredentialAttributes(gitpodHost), accessToken)
Expand Down
4 changes: 4 additions & 0 deletions dev/jetbrains-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gradle
.idea
build
bin
36 changes: 36 additions & 0 deletions dev/jetbrains-test/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
}

group 'io.gitpod'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
maven { url = "https://packages.jetbrains.team/maven/p/ij/intellij-dependencies" }
}

test {
systemProperty('video.save.mode', 'ALL')
systemProperty('gateway_link', System.getenv('GATEWAY_LINK'))
systemProperty('gateway_plugin_path', System.getenv('GATEWAY_PLUGIN_PATH'))
useJUnitPlatform()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")

implementation("com.google.code.gson:gson:2.8.9")
implementation("com.squareup.okhttp3:okhttp:4.9.3")
implementation("com.intellij.remoterobot:remote-robot:0.11.12")
implementation("com.intellij.remoterobot:remote-fixtures:0.11.12")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")

// Logging Network Calls
testImplementation('com.squareup.okhttp3:logging-interceptor:4.9.3')

// Video Recording
implementation('com.automation-remarks:video-recorder-junit5:2.0')
}
1 change: 1 addition & 0 deletions dev/jetbrains-test/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.code.style=official
Binary file not shown.
5 changes: 5 additions & 0 deletions dev/jetbrains-test/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
89 changes: 89 additions & 0 deletions dev/jetbrains-test/gradlew.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
2 changes: 2 additions & 0 deletions dev/jetbrains-test/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'jetbrains-test'

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.gitpod.jetbrains.launcher

enum class Ide(val code: String, val feedsCode: String) {
IDEA_COMMUNITY("IC", "IIC"),
IDEA_ULTIMATE("IU", "IIU"),
CLION("CL", "CL"),
WEBSTORM("WS", "WS"),
RUBY_MINE("RM", "RM"),
PYCHARM("PY", "PCP"),
GATEWAY("GW", "GW");

fun getIdePropertiesEnvVarName() = when (this) {
IDEA_COMMUNITY, IDEA_ULTIMATE -> "IDEA_PROPERTIES"
CLION -> "CLION_PROPERTIES"
WEBSTORM -> if (Os.hostOS() == Os.MAC) "WEBSTORM_PROPERTIES" else "WEBIDE_PROPERTIES"
RUBY_MINE -> "RUBYMINE_PROPERTIES"
PYCHARM -> "PYCHARM_PROPERTIES"
GATEWAY -> "GATEWAY_PROPERTIES"
}

fun getVmOptionsEnvVarName() = when (this) {
IDEA_COMMUNITY, IDEA_ULTIMATE -> "IDEA_VM_OPTIONS"
CLION -> "CLION_VM_OPTIONS"
WEBSTORM -> if (Os.hostOS() == Os.MAC) "WEBSTORM_VM_OPTIONS" else "WEBIDE_VM_OPTIONS"
RUBY_MINE -> "RUBYMINE_VM_OPTIONS"
PYCHARM -> "PYCHARM_VM_OPTIONS"
GATEWAY -> "GATEWAY_VM_OPTIONS"
}.let {
if (Os.hostOS() == Os.WINDOWS) {
val productPrefix = it.substringBefore("_")
"${productPrefix}64${it.removePrefix(productPrefix)}"
} else {
it
}
}

companion object {
fun withCode(code: String) = values().single { it.code == code }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package io.gitpod.jetbrains.launcher

import com.google.gson.JsonParser
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardOpenOption

class IdeDownloader @JvmOverloads constructor(private val httpClient: OkHttpClient = OkHttpClient()) {

private companion object {
const val ROBOT_PLUGIN_VERSION_DEFAULT = "0.11.9"

fun getRobotServerPluginDownloadUrl(version: String): String =
"https://packages.jetbrains.team/maven/p/ij/intellij-dependencies/com/intellij/remoterobot/robot-server-plugin/$version/robot-server-plugin-$version.zip"

fun getFeedsOsPropertyName() = when (Os.hostOS()) {
Os.WINDOWS -> "windowsZip"
Os.LINUX -> "linux"
Os.MAC -> "mac"
}
}

fun downloadAndExtractLatestEap(ide: Ide, toDir: Path): Path {
val idePackage = downloadIde(ide, toDir)
return extractIde(idePackage, toDir)
}

@JvmOverloads
fun downloadRobotPlugin(toDir: Path, version: String = ROBOT_PLUGIN_VERSION_DEFAULT): Path {
return downloadFile(getRobotServerPluginDownloadUrl(version), toDir.resolve("robot-server-plugin-$version"))
}

private fun extractIde(idePackage: Path, toDir: Path): Path = when (Os.hostOS()) {
Os.LINUX -> extractTar(idePackage, toDir).single()
Os.MAC -> extractDmgApp(idePackage, toDir)
Os.WINDOWS -> {
val appDir = Files.createDirectory(toDir.resolve(idePackage.fileName.toString().substringBefore(".win.zip")))
extractZip(idePackage, appDir)
appDir
}
}

private fun downloadIde(ide: Ide, toDir: Path): Path {
val ideDownloadLink = getIdeDownloadUrl(ide, httpClient)
val idePackageName = ideDownloadLink.substringAfterLast("/").removeSuffix("/")
val targetFile = toDir.resolve(idePackageName)
return downloadFile(ideDownloadLink, targetFile)
}

private fun downloadFile(url: String, toFile: Path): Path {
return httpClient.newCall(Request.Builder().url(url).build()).execute().use { response ->
check(response.isSuccessful) { "failed to download file from $url" }
Files.newOutputStream(toFile, StandardOpenOption.CREATE_NEW).use {
response.body!!.byteStream().buffered().copyTo(it)
}
toFile
}
}

private fun getIdeDownloadUrl(ide: Ide, httpClient: OkHttpClient): String {
return httpClient.newCall(
Request.Builder().url(
"https://data.services.jetbrains.com/products/releases".toHttpUrl()
.newBuilder()
.addQueryParameter("code", ide.feedsCode)
.addQueryParameter("platform", getFeedsOsPropertyName())
.build()
).build()
).execute().use { response ->
check(response.isSuccessful) { "failed to get $ide feeds" }
JsonParser.parseReader(response.body!!.charStream())
.asJsonObject[ide.feedsCode]
.asJsonArray
.firstOrNull {
it.asJsonObject["downloads"]?.asJsonObject?.keySet()?.isNotEmpty() ?: false
}
?.asJsonObject?.get("downloads")
?.asJsonObject?.get(getFeedsOsPropertyName())
?.asJsonObject?.get("link")
?.asString ?: error("no suitable ide found")
}
}
}
Loading