-
Notifications
You must be signed in to change notification settings - Fork 150
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
Changes from all commits
fbd357d
a6c4fc1
b8e18cd
e126449
5b49311
3623203
e697af4
7c8b807
b0d927e
a4fd643
113885f
d1ab956
b58cc04
6afb76d
3afacbd
e244e90
2551902
df43c61
114e35f
e500f70
9f1ddb7
93fc1dc
0645553
1ad5e55
d0fefa0
3de05a4
59d62cf
0da9df1
57a21e7
0838653
9302c6e
5c2c5b5
53d0e85
b4cf804
f8d9d58
af4b0a5
8ace9fd
5a5e50c
34f5182
2c0ee1e
db466bb
224381c
0a171a0
d1f8842
759e359
6d135b8
396d571
955496b
5021e9b
4f52df2
e334942
cb7277d
6499a34
dc302a7
254a757
161030b
e17ea4b
49cbf19
dbfaa9b
ef91091
d82ee21
bf2fdf3
df2aa2e
f78839e
403e20c
6627e6c
12f4b0f
f7736a6
fa83559
6579417
8e35c31
174383e
dc8efc2
c31d67a
6e6366b
5a71775
9790b3b
8de81b0
83c17ce
1ddc57f
7bc8716
bd72f44
4ae001a
9e31727
c0993d6
7196e36
4771145
d51bb86
18904da
9ce60eb
c2a6e89
fa1564d
a6dce2c
54d5783
1705184
a6aeba4
4cee98e
0c8b837
d5739ec
6a64d0c
3c0e43b
f87a58d
02a2ad6
9b5fbd4
9f506ee
f0f629c
1381dd9
9fb54e0
bc0e356
ed78113
ad01083
0fcbd67
40a5e95
171da6c
1eeab6f
b54efe8
a5f81fe
de67e0b
4793b0c
6cc4d19
277caf7
a613605
c1af3d1
e635213
55d82b7
db49d95
514820e
d8adeb3
0742852
a01c814
d26650a
055ecc5
0fd4e60
0a3dc8f
5293c2d
534f9f5
486218e
fd6bce2
df814e1
39de34d
ab6dfbd
e635c1a
dce6836
ae8897e
d241259
66bcb86
490f2b7
afa5237
e11c946
fff00d0
011d0d5
56bb3ea
cb4a224
234138f
0cedfbd
fdb0165
ff6c5e8
81e7339
d4deda3
80c52ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/+//') | ||
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" |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
but if you turn it to a github action, then we could just invoke it by calling
(so plug-in registry is only a client of the action hosted elsewhere) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')) | ||
|
@@ -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) |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try a better name than |
||
- 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 |
There was a problem hiding this comment.
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