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

Run VSCode extension's tests on top of che-theia #864

Closed
wants to merge 160 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
fbd357d
test action
svor Feb 3, 2021
a6c4fc1
Update vscode-extension-tests-check.yaml
svor Feb 3, 2021
b8e18cd
Update vscode-extension-tests-check.yaml
svor Feb 3, 2021
e126449
Update vscode-extension-tests-check.yaml
svor Feb 3, 2021
5b49311
Update vscode-extension-tests-check.yaml
svor Feb 3, 2021
3623203
Update vscode-extension-tests-check.yaml
svor Feb 3, 2021
e697af4
update action
svor Feb 4, 2021
7c8b807
update action
svor Feb 4, 2021
b0d927e
update action
svor Feb 4, 2021
a4fd643
update action
svor Feb 4, 2021
113885f
update action
svor Feb 4, 2021
d1ab956
update action
svor Feb 4, 2021
b58cc04
update action
svor Feb 5, 2021
6afb76d
update action
svor Feb 5, 2021
3afacbd
update action
svor Feb 5, 2021
e244e90
update action
svor Feb 5, 2021
2551902
update action
svor Feb 5, 2021
df43c61
update action
svor Feb 5, 2021
114e35f
update action
svor Feb 5, 2021
e500f70
update action
svor Feb 5, 2021
9f1ddb7
update action
svor Feb 5, 2021
93fc1dc
update action
svor Feb 5, 2021
0645553
update action
svor Feb 5, 2021
1ad5e55
update action
svor Feb 5, 2021
d0fefa0
update action
svor Feb 5, 2021
3de05a4
update action
svor Feb 5, 2021
59d62cf
update action
svor Feb 5, 2021
0da9df1
update action
svor Feb 5, 2021
57a21e7
update action
svor Feb 5, 2021
0838653
update action
svor Feb 6, 2021
9302c6e
update action
svor Feb 6, 2021
5c2c5b5
update action
svor Feb 6, 2021
53d0e85
update action
svor Feb 6, 2021
b4cf804
update action
svor Feb 6, 2021
f8d9d58
update action
svor Feb 6, 2021
af4b0a5
update action
svor Feb 6, 2021
8ace9fd
update action
svor Feb 7, 2021
5a5e50c
update action
svor Feb 7, 2021
34f5182
update action
svor Feb 7, 2021
2c0ee1e
update action
svor Feb 7, 2021
db466bb
update action
svor Feb 7, 2021
224381c
update action
svor Feb 7, 2021
0a171a0
update action
svor Feb 7, 2021
d1f8842
update action
svor Feb 7, 2021
759e359
update action
svor Feb 7, 2021
6d135b8
update action
svor Feb 7, 2021
396d571
update action
svor Feb 7, 2021
955496b
update action
svor Feb 7, 2021
5021e9b
update action
svor Feb 8, 2021
4f52df2
update action
svor Feb 8, 2021
e334942
update action
svor Feb 8, 2021
cb7277d
update action
svor Feb 8, 2021
6499a34
update action
svor Feb 8, 2021
dc302a7
update action
svor Feb 8, 2021
254a757
update action
svor Feb 8, 2021
161030b
update action
svor Feb 8, 2021
e17ea4b
update action
svor Feb 8, 2021
49cbf19
update action
svor Feb 9, 2021
dbfaa9b
update action
svor Feb 9, 2021
ef91091
update action
svor Feb 9, 2021
d82ee21
update action
svor Feb 9, 2021
bf2fdf3
update action
svor Feb 9, 2021
df2aa2e
update action
svor Feb 9, 2021
f78839e
update action
svor Feb 9, 2021
403e20c
update action
svor Feb 9, 2021
6627e6c
update action
svor Feb 9, 2021
12f4b0f
update action
svor Feb 10, 2021
f7736a6
update action
svor Feb 10, 2021
fa83559
update action
svor Feb 10, 2021
6579417
update action
svor Feb 10, 2021
8e35c31
update action
svor Feb 10, 2021
174383e
update
svor Feb 10, 2021
dc8efc2
update
svor Feb 10, 2021
c31d67a
update
svor Feb 10, 2021
6e6366b
generate devfile
svor Feb 17, 2021
5a71775
update
svor Feb 17, 2021
9790b3b
update
svor Feb 17, 2021
8de81b0
update
svor Feb 17, 2021
83c17ce
update
svor Feb 17, 2021
1ddc57f
update
svor Feb 17, 2021
7bc8716
update
svor Feb 17, 2021
bd72f44
update
svor Feb 18, 2021
4ae001a
update
svor Feb 18, 2021
9e31727
update
svor Feb 18, 2021
c0993d6
update
svor Feb 18, 2021
7196e36
update
svor Feb 18, 2021
4771145
update
svor Feb 18, 2021
d51bb86
update
svor Feb 18, 2021
18904da
update
svor Feb 18, 2021
9ce60eb
update
svor Feb 18, 2021
c2a6e89
update
svor Feb 18, 2021
fa1564d
update
svor Feb 18, 2021
a6dce2c
update
svor Feb 18, 2021
54d5783
update
svor Feb 18, 2021
1705184
update
svor Feb 18, 2021
a6aeba4
update
svor Feb 18, 2021
4cee98e
update
svor Feb 18, 2021
0c8b837
update
svor Feb 18, 2021
d5739ec
update
svor Feb 18, 2021
6a64d0c
update
svor Feb 18, 2021
3c0e43b
update
svor Feb 18, 2021
f87a58d
update
svor Feb 19, 2021
02a2ad6
update
svor Feb 19, 2021
9b5fbd4
update
svor Feb 19, 2021
9f506ee
update
svor Feb 19, 2021
f0f629c
update
svor Feb 19, 2021
1381dd9
update
svor Feb 19, 2021
9fb54e0
find repo
svor Feb 19, 2021
bc0e356
find repo
svor Feb 19, 2021
ed78113
find repo
svor Feb 19, 2021
ad01083
Merge branch 'master' of https://github.com/eclipse/che-plugin-regist…
svor Feb 19, 2021
0fcbd67
test
svor Feb 19, 2021
40a5e95
test
svor Feb 19, 2021
171da6c
test
svor Feb 19, 2021
1eeab6f
test
svor Feb 19, 2021
b54efe8
test
svor Feb 19, 2021
a5f81fe
update
svor Feb 22, 2021
de67e0b
update
svor Feb 22, 2021
4793b0c
update
svor Feb 22, 2021
6cc4d19
update
svor Feb 22, 2021
277caf7
update
svor Feb 22, 2021
a613605
update
svor Feb 22, 2021
c1af3d1
update
svor Feb 22, 2021
e635213
update
svor Feb 22, 2021
55d82b7
update
svor Feb 22, 2021
db49d95
update
svor Feb 22, 2021
514820e
update
svor Feb 23, 2021
d8adeb3
getChanges
svor Feb 23, 2021
0742852
update
svor Feb 23, 2021
a01c814
update
svor Feb 23, 2021
d26650a
update
svor Feb 23, 2021
055ecc5
update
svor Feb 23, 2021
0fd4e60
update
svor Feb 23, 2021
0a3dc8f
update
svor Feb 23, 2021
5293c2d
update
svor Feb 23, 2021
534f9f5
update
svor Feb 23, 2021
486218e
set env
svor Feb 23, 2021
fd6bce2
set env
svor Feb 23, 2021
df814e1
set env
svor Feb 23, 2021
39de34d
set env2
svor Feb 23, 2021
ab6dfbd
set env2
svor Feb 23, 2021
e635c1a
cleanup
svor Feb 23, 2021
dce6836
use env
svor Feb 24, 2021
ae8897e
use env
svor Feb 24, 2021
d241259
cleanup
svor Feb 24, 2021
66bcb86
cleanup
svor Feb 24, 2021
490f2b7
cleanup
svor Feb 24, 2021
afa5237
update
svor Feb 24, 2021
e11c946
test shellcheck
svor Feb 24, 2021
fff00d0
tests shellcheck
svor Feb 24, 2021
011d0d5
tests shellcheck
svor Feb 24, 2021
56bb3ea
tests shellcheck
svor Feb 24, 2021
cb4a224
tests shellcheck
svor Feb 24, 2021
234138f
tests shellcheck
svor Feb 24, 2021
0cedfbd
upadate
svor Feb 25, 2021
fdb0165
cleanup
svor Mar 1, 2021
ff6c5e8
cleanup
svor Mar 1, 2021
81e7339
run if che-theia-plugins was changed
svor Mar 1, 2021
d4deda3
cleanup
svor Mar 1, 2021
80c52ff
Merge branch 'master' into sv/VSC-tests
svor Mar 1, 2021
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
2 changes: 1 addition & 1 deletion .ci/cico-plugin-registry-pr-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ echo "Theia IDE Container Name is: "
echo "$theia_ide_container_name"

# Start the python3 selenium script that will connect to the workspace to run tests
python3 .ci/language-tests-runner.py "${workspace_url}"
python3 .ci/tests-runner.py "${workspace_url}"
sleep 20
cat geckodriver.log

Expand Down
39 changes: 39 additions & 0 deletions .ci/get-changed-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# shellcheck disable=SC2016
#
# Copyright (c) 2012-2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation

set -e

sudo pip install yq

CHANGED_LINES=$(git diff -U0 HEAD "$(git merge-base HEAD origin/master)" che-theia-plugins.yaml | grep @@ | cut -d ' ' -f 3 | sed 's/+//')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to extract out the arguments for git diff into arguments for the script. That way it's not hardcoded in the script, but takes input from the GitHub action job.

For example:
https://github.com/eclipse/che-plugin-registry/blob/master/.ci/sidecar-build-publish.sh#L16
https://github.com/eclipse/che-plugin-registry/blob/master/.github/workflows/sidecar-build-push.yaml#L48

echo "$CHANGED_LINES"
for number in $CHANGED_LINES
do
LINE=$(sed "$number!d" che-theia-plugins.yaml | xargs)
if [[ $LINE == *"revision:"* ]]; then
break
fi
exit 0
done
EXTENSION_REVISION=$(echo "$LINE" | cut -d ' ' -f 2)
EXTENSION_REPO=$(yq -r --arg EXTENSION_REVISION "$EXTENSION_REVISION" '[.plugins[] | select(.repository.revision == $EXTENSION_REVISION )] | .[0] | .repository.url' che-theia-plugins.yaml)

if [[ $EXTENSION_REPO == null ]]; then
EXTENSION_REPO=''
fi

echo "Extension revision: $EXTENSION_REVISION"
echo "Extension repository: $EXTENSION_REPO"

echo "::set-env name=EXTENSION_REVISION::$EXTENSION_REVISION"
echo "::set-env name=EXTENSION_REPO::$EXTENSION_REPO"
126 changes: 126 additions & 0 deletions .ci/run-extension-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/bash
# shellcheck disable=SC2016
#
# Copyright (c) 2012-2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation

set -e

function installDeps() {
sudo pip install selenium
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to create a user level virtual environment.

wget https://github.com/mozilla/geckodriver/releases/download/v0.29.0/geckodriver-v0.29.0-linux64.tar.gz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create an variable for the geckodriver version, and use that variable in the URL. This makes it easier to read and update.

tar -xvzf geckodriver*
chmod +x geckodriver
sudo mv geckodriver /usr/local/bin/
}

function cloneExtension() {
EXTENSION_PROJECT_NAME=$(basename "$EXTENSION_REPO")
export EXTENSION_PROJECT_NAME

mkdir -p /tmp/projects/"$EXTENSION_PROJECT_NAME"
git clone "${EXTENSION_REPO}" /tmp/projects/"$EXTENSION_PROJECT_NAME"
cd /tmp/projects/"$EXTENSION_PROJECT_NAME"
git checkout tags/"${EXTENSION_REVISION}"
git status
}

function prepareDevfile() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move all the logic of this file to a github action

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benoitf do you mean to create more steps in the action and each step will execute some part of this script?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not clear enough

today you're using that script by doing:

name: Run VSCode extension's tests
        if: env.EXTENSION_REPO != ''
        run: |
          ./.ci/run-extension-tests.sh

but if you turn it to a github action, then we could just invoke it by calling

       if: env.EXTENSION_REPO != ''
        uses: che-incubator/vscode-extension-tests@next

(so plug-in registry is only a client of the action hosted elsewhere)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and with github actions it's easy to get unit tests / code coverage / etc.

# Get Extension's ID
EXTENSION_ID=$(yq -r --arg EXTENSION_REPO "$EXTENSION_REPO" '[.plugins[] | select(.repository.url == $EXTENSION_REPO)] | .[1] | .id' "$GITHUB_WORKSPACE"/che-theia-plugins.yaml)
if [ "$EXTENSION_ID" == null ];
then
# If ID wasn't set in che-theia-plugins.yaml let's parse package.json and build ID as publisher/name
PACKAGE_JSON=/tmp/projects/$EXTENSION_PROJECT_NAME/package.json
EXTENSION_NAME=$(jq -r '.name' "$PACKAGE_JSON")
EXTENSION_PUBLISHER=$(jq -r '.publisher' "$PACKAGE_JSON")
EXTENSION_ID=$EXTENSION_PUBLISHER/$EXTENSION_NAME
fi
EXTENSION_ID=$EXTENSION_ID/latest

# Add Extension's ID into devfile template
sed -i -e "s|@|$EXTENSION_ID|g" "$GITHUB_WORKSPACE"/.ci/templates/extension-tests-devfile.yaml
echo ----- Devfile -----
cat "$GITHUB_WORKSPACE"/.ci/templates/extension-tests-devfile.yaml
}

function compileExtension() {
yarn install
yarn compile
}

function prepareWorkspace() {
chectl workspace:create --start --devfile=https://raw.githubusercontent.com/svor/che-vscode-extension-tests/main/devfile.yaml > workspace_url.txt
WORKSPACE_URL=$(tail -n 1 workspace_url.txt)
export WORKSPACE_URL
echo Workspace URL is "$WORKSPACE_URL"

pods=$(kubectl get pod -n admin-che -l che.workspace_id --field-selector=status.phase==Running 2>&1)
while [ "$pods" == 'No resources found in admin-che namespace.' ];
do
chectl workspace:list
echo "Workspace is not ready"
kubectl get pod -n admin-che
sleep 10
pods=$(kubectl get pod -n admin-che -l che.workspace_id --field-selector=status.phase==Running 2>&1)
done

kubectl get pods -n admin-che -l che.workspace_id

### Find workspace name and theia-ide container
WORKSPACE_NAME=$(kubectl get pod -n admin-che -l che.workspace_id -o json | jq '.items[0].metadata.name' | tr -d \")
THEIA_IDE_CONTAINER_NAME=$(kubectl get pod -n admin-che -l che.workspace_id -o json | jq '.items[0].metadata.annotations[]' | grep -P "theia-ide" | tr -d \")

echo "Workspace name is: "
echo "$WORKSPACE_NAME"
echo "Theia IDE Container Name is: "
echo "$THEIA_IDE_CONTAINER_NAME"

### Copy extension's sources into theia container
copySources

sleep 10

# Start the python3 selenium script that will connect to the workspace to run tests
python3 "$GITHUB_WORKSPACE"/.ci/tests-runner.py "${WORKSPACE_URL}"
}

function copySources() {
echo "----- Copy Sources --------"
kubectl cp /tmp/projects/"$EXTENSION_PROJECT_NAME" admin-che/"${WORKSPACE_NAME}":/projects -c "$THEIA_IDE_CONTAINER_NAME"
echo "----- Sources were copied --------"
### Check if copy
kubectl exec "${WORKSPACE_NAME}" -n admin-che -c "$THEIA_IDE_CONTAINER_NAME" -- ls -la /projects
}

function checkTestsLogs() {
kubectl cp admin-che/"${WORKSPACE_NAME}":/projects/test.log /tmp/test.log -c "${THEIA_IDE_CONTAINER_NAME}"
while ! grep -q "TESTS PASSED" /tmp/test.log && ! grep -q "TESTS FAILED" /tmp/test.log;
do
echo "Waiting for log file to be created and have TESTS FAILED or TESTS PASSED"
sleep 10
kubectl cp admin-che/"${WORKSPACE_NAME}":/projects/test.log /tmp/test.log -c "${THEIA_IDE_CONTAINER_NAME}"
done

cat /tmp/test.log

# Test to see if the tests failed
if grep -q "TESTS FAILED" /tmp/test.log;
then
exit 1
fi
}

installDeps
cloneExtension
compileExtension
prepareDevfile
prepareWorkspace
checkTestsLogs
16 changes: 16 additions & 0 deletions .ci/templates/extension-tests-devfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: 1.0.0
metadata:
name: extension-test-sample
components:
- mountSources: true
memoryLimit: 3Gi
type: dockerimage
image: 'quay.io/eclipse/che-theia-dev:next'
alias: che-dev
- type: chePlugin
reference: 'https://raw.githubusercontent.com/svor/che-vscode-extension-tests/main/meta.yaml'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a central place we can put this, i.e. not your fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericwill I think we can move this extension into che-incubator, but when eclipse-che/che#19172 will be resolved. I'm still working on this extension.

- type: chePlugin
id: @
- id: eclipse/che-theia/next
memoryLimit: 1024Mi
type: cheEditor
15 changes: 12 additions & 3 deletions .ci/language-tests-runner.py → .ci/tests-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
options = Options()
options.log.level = "trace"
options.headless = True
options.add_argument('--disable-web-security')
options.add_argument('--allow-running-insecure-content')
options.add_argument('--ignore-certificate-errors')

NEW_USER="admin"

browser = webdriver.Firefox(options=options, executable_path="/usr/local/bin/geckodriver")
wait = WebDriverWait(browser, 30)
print (sys.argv[1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a print statement left over from development 😄

browser.get(sys.argv[1])

wait.until(EC.title_contains('Log in'))
Expand All @@ -41,6 +45,11 @@
browser.implicitly_wait(20)
browser.get(sys.argv[1])

#Waiting for theia itself to be loaded so that tests will be run
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'ide-application-iframe')))
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="theia-app-shell"]')))
try:
#Waiting for theia itself to be loaded so that tests will be run
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'ide-iframe')))
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="theia-app-shell"]')))
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="/projects:/projects/test.log"]')))
print("----- Workspace is ready -----")
except Exception as e:
print("Loading took too much time!", e)
64 changes: 64 additions & 0 deletions .github/workflows/vscode-extension-tests-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Copyright (c) 2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

name: VSCode Extension's Tests

on:
push:
paths:
- 'che-theia-plugins.yaml'
jobs:
test-extension:
runs-on: ubuntu-20.04
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Get changes
run: |
./.ci/get-changed-plugin.sh
- uses: actions/setup-node@v1
if: env.EXTENSION_REPO != ''
with:
node-version: '12'
- name: Build image
if: env.EXTENSION_REPO != ''
run: |
export SKIP_FORMAT=true
export SKIP_LINT=true
export SKIP_TEST=true
docker pull quay.io/eclipse/che-plugin-registry:nightly
BUILDER=docker ./build.sh --tag vscode-extension
# save locally built image
docker save -o docker-image.tar quay.io/eclipse/che-plugin-registry:vscode-extension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try a better name than vscode-extension, maybe vscode-extension-test or something similar?

- name: Start minikube
if: env.EXTENSION_REPO != ''
uses: che-incubator/setup-minikube-action@next
- name: Load image
if: env.EXTENSION_REPO != ''
run: |
# load image in the docker registry
eval $(minikube docker-env)
docker load --input=docker-image.tar
# display images
docker images
- name: Deploy Eclipse Che
if: env.EXTENSION_REPO != ''
uses: che-incubator/che-deploy-action@next
with:
# use custom image built by this PR
plugin-registry-image: quay.io/eclipse/che-plugin-registry:vscode-extension
- name: Run VSCode extension's tests
if: env.EXTENSION_REPO != ''
run: |
./.ci/run-extension-tests.sh