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

Create tests to check 'Git zero-config' flow as PR checks #494

Merged
merged 58 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e200e39
Create 'Dockerfile' file to configure ci-operator
artaleks9 Apr 10, 2023
b0ba760
Update 'build-pr-check.yml' github action
artaleks9 Apr 10, 2023
3cc493a
Update 'build-pr-check.yml' file
artaleks9 Apr 10, 2023
d2ab0e5
Fix up the path to file
artaleks9 Apr 10, 2023
ff72384
Fix up the commiter email field
artaleks9 Apr 10, 2023
dd37d36
Add 'git config' to workflow
artaleks9 Apr 10, 2023
6af7347
Add git push command
artaleks9 Apr 10, 2023
c712598
Merge 6af7347b43ae6238c577bf1fecd8d02d7ae8afd7 into c9e8f5eae94b38e1e…
artaleks9 Apr 10, 2023
7989aa7
Update PR_IMAGE_TAG
artaleks9 Apr 10, 2023
813217a
Add changes to 'build-pr-check.yml' file
artaleks9 Apr 10, 2023
8e1ddb4
Merge 813217a135640066b721c573ceb31cde2a8ead91 into c9e8f5eae94b38e1e…
artaleks9 Apr 10, 2023
cae34a8
Update PR_IMAGE_TAG
artaleks9 Apr 10, 2023
669be6e
Do changes in 'build-pr-check.yml' file
artaleks9 Apr 10, 2023
b048dba
Update 'build-pr-check.yml' file with load env
artaleks9 Apr 11, 2023
0570b73
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 Apr 11, 2023
913f7e2
Update 'pr-image-tag' file
artaleks9 Apr 11, 2023
fc34740
Merge 913f7e23809438dfd6b9bca382ebbd6cd895cad7 into 16dff88b2e1037dc7…
artaleks9 Apr 11, 2023
550f164
Add PR_IMAGE_TAG
artaleks9 Apr 11, 2023
38adab7
Update '.ci/openshift-ci/Dockerfile' file
artaleks9 Apr 11, 2023
48bdf13
Merge branch 'che#21753' of github.com:eclipse-che/che-server into ch…
artaleks9 Apr 11, 2023
238b2d1
Fix 'build-pr-check.yml' file
artaleks9 Apr 11, 2023
00bfcb2
Remove from 'build-pr-check.yml' the 'write PR_IMAGE_TAG'
artaleks9 Apr 12, 2023
e751529
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 Apr 13, 2023
9e403e0
Change 'build-pr-check.yml' file
artaleks9 Apr 13, 2023
5cef5dc
Add 'killProcessByPort' to 'build-pr-check.yml' file
artaleks9 Apr 13, 2023
cb31d7c
Rework 'build-pr-check.yml' file
artaleks9 Apr 15, 2023
0fd1c8e
Fix up 'name' workflow
artaleks9 Apr 15, 2023
479588f
Change 'if' condition
artaleks9 Apr 15, 2023
02f1fa2
Update .ci/openshift-ci/common.sh
artaleks9 Apr 17, 2023
b875837
Update .ci/openshift-ci/test-bitbucket-flow.sh
artaleks9 Apr 17, 2023
f399acc
Update .ci/openshift-ci/test-github-flow.sh
artaleks9 Apr 17, 2023
101fe27
Update .ci/openshift-ci/test-gitlab-flow.sh
artaleks9 Apr 17, 2023
4961dc1
Update '.ci/openshift-ci/Dockerfile'
artaleks9 Apr 17, 2023
d70a3c2
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 Apr 17, 2023
f034bc0
Modify files
artaleks9 Apr 18, 2023
48618f2
Remove 'origin'
artaleks9 Apr 18, 2023
8f96d33
Add 'git remote add' to script
artaleks9 Apr 18, 2023
ae1a430
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 Apr 19, 2023
1d63bb9
Change commands
artaleks9 Apr 19, 2023
be98e29
Return back git commanhs
artaleks9 Apr 19, 2023
5b12750
Add variables
artaleks9 Apr 19, 2023
d12cb18
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 Apr 19, 2023
37ffbb3
Check variable
artaleks9 Apr 19, 2023
1937e94
Add variable
artaleks9 Apr 19, 2023
4405259
Add to check folders
artaleks9 Apr 19, 2023
55054f8
Do changes to check files
artaleks9 Apr 19, 2023
3210336
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 Apr 20, 2023
204c081
Restore code of tests
artaleks9 Apr 20, 2023
436d244
Check content another files
artaleks9 Apr 20, 2023
1cbef4b
Check to get content of variables
artaleks9 Apr 20, 2023
9b77edd
Upadte getting PR image tag
artaleks9 Apr 20, 2023
8dfd8db
Update 'build-pr-check.yml' file
artaleks9 Apr 20, 2023
e0a725c
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 May 7, 2023
8bba2d1
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 May 15, 2023
ac50d75
Rename tests to 'no-pat-oauth-flow' names
artaleks9 May 19, 2023
98ead31
Merge branch 'main' of github.com:eclipse-che/che-server into che#21753
artaleks9 May 19, 2023
70823d6
Update 'common.sh' to implement PAT setup flow
artaleks9 May 19, 2023
5e08ac2
Add tests to check git flow with PAT setup
artaleks9 May 19, 2023
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/openshift-ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2019-2021 Red Hat, Inc.
# Copyright (c) 2023 Red Hat, Inc.
Copy link
Contributor

@vinokurig vinokurig Apr 20, 2023

Choose a reason for hiding this comment

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

This file wasn't changed, do not change the license header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems, happened a bit confusing thing..
I recently did PR (Create 'Dockerfile' to configure ci-operator), where added this Dockerfile, but didn't take into account Valeriy's comment about header.
So I decided to fix it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct header: Copyright (c) 2019-2023 Red Hat, Inc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmytro-ndp If the file is new, just is created, then we'll point the only current year

# 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/
Expand Down
238 changes: 238 additions & 0 deletions .ci/openshift-ci/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
#!/bin/bash
#
# Copyright (c) 2023 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
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

PR_IMAGE_TAG="pr-${PULL_NUMBER}"

export CHE_NAMESPACE=${CHE_NAMESPACE:-"eclipse-che"}
export CHE_SERVER_IMAGE=${CHE_SERVER_IMAGE:-"quay.io/eclipse/che-server:${PR_IMAGE_TAG}"}
export ARTIFACTS_DIR=${ARTIFACT_DIR:-"/tmp/artifacts"}
export CHE_FORWARDED_PORT="8081"
export OCP_ADMIN_USER_NAME=${OCP_ADMIN_USER_NAME:-"admin"}
export OCP_NON_ADMIN_USER_NAME=${OCP_NON_ADMIN_USER_NAME:-"user"}
export OCP_LOGIN_PASSWORD=${OCP_LOGIN_PASSWORD:-"passw"}
export ADMIN_PROJECT_NAME=${OCP_ADMIN_USER_NAME}"-che"
export USER_PROJECT_NAME=${OCP_NON_ADMIN_USER_NAME}"-che"
export PUBLIC_REPO_WORKSPACE_NAME=${PUBLIC_REPO_WORKSPACE_NAME:-"public-repo-wksp-testname"}
export PRIVATE_REPO_WORKSPACE_NAME=${PRIVATE_REPO_WORKSPACE_NAME:-"private-repo-wksp-testname"}
export PUBLIC_PROJECT_GITLAB_NAME=${PUBLIC_PROJECT_NAME:-"public-repo"}
export PRIVATE_PROJECT_GITLAB_NAME=${PRIVATE_PROJECT_NAME:-"private-repo"}
export YAML_FILE_NAME=${YAML_FILE_NAME:-"devfile.yaml"}

provisionOpenShiftOAuthUser() {
echo -e "[INFO] Provisioning Openshift OAuth user"
htpasswd -c -B -b users.htpasswd ${OCP_ADMIN_USER_NAME} ${OCP_LOGIN_PASSWORD}
htpasswd -b users.htpasswd ${OCP_NON_ADMIN_USER_NAME} ${OCP_LOGIN_PASSWORD}
oc create secret generic htpass-secret --from-file=htpasswd="users.htpasswd" -n openshift-config
oc apply -f ".ci/openshift-ci/htpasswdProvider.yaml"
oc adm policy add-cluster-role-to-user cluster-admin ${OCP_ADMIN_USER_NAME}

echo -e "[INFO] Waiting for htpasswd auth to be working up to 5 minutes"
CURRENT_TIME=$(date +%s)
ENDTIME=$((CURRENT_TIME + 300))
while [ "$(date +%s)" -lt $ENDTIME ]; do
if oc login -u ${OCP_ADMIN_USER_NAME} -p ${OCP_LOGIN_PASSWORD} --insecure-skip-tls-verify=false; then
break
fi
sleep 10
done
}

createCustomResourcesFile() {
cat > custom-resources.yaml <<-END
apiVersion: org.eclipse.che/v2
spec:
devEnvironments:
maxNumberOfRunningWorkspacesPerUser: 10000
END

echo "Generated custom resources file"
cat custom-resources.yaml
}

deployChe() {
chectl server:deploy --cheimage=$CHE_SERVER_IMAGE \
--che-operator-cr-patch-yaml=custom-resources.yaml \
--platform=openshift \
--telemetry=off \
--batch
}

# this command starts port forwarding between the local machine and the che-host service in the OpenShift cluster.
forwardPortToService() {
oc port-forward service/che-host ${CHE_FORWARDED_PORT}:8080 -n ${CHE_NAMESPACE} &
sleep 3s
}

killProcessByPort() {
fuser -k ${CHE_FORWARDED_PORT}/tcp
}

requestFactoryResolverGitRepoUrl() {
GIT_REPO_URL=$1
CLUSTER_ACCESS_TOKEN=$(oc whoami -t)

curl -i -X 'POST' \
http://localhost:${CHE_FORWARDED_PORT}/api/factory/resolver \
-H 'accept: */*' \
-H "Authorization: Bearer ${CLUSTER_ACCESS_TOKEN}" \
-H 'Content-Type: application/json' \
-d '{
"url": "'${GIT_REPO_URL}'"
}'
}

# check that factory resolver returns correct value
testFactoryResolverNoPatOAuth() {
PUBLIC_REPO_URL=$1
PRIVATE_REPO_URL=$2

echo "[INFO] Check factory resolver with NO PAT/OAuth setup"
# for public repo
if [ "$(requestFactoryResolverGitRepoUrl ${PUBLIC_REPO_URL} | grep "HTTP/1.1 200")" ]; then
echo "[INFO] Factory resolver returned 'HTTP/1.1 200' status code."
else
echo "[ERROR] Factory resolver returned wrong status code. Expected: HTTP/1.1 200."
exit 1
fi

# for private repo
if [ "$(requestFactoryResolverGitRepoUrl ${PRIVATE_REPO_URL} | grep "HTTP/1.1 400")" ]; then
echo "[INFO] Factory resolver returned 'HTTP/1.1 400' status code. Expected client side error."
else
echo "[ERROR] Factory resolver returned wrong status code. Expected 'HTTP/1.1 400'."
exit 1
fi
}

testFactoryResolverWithPatOAuth() {
PUBLIC_REPO_URL=$1
PRIVATE_REPO_URL=$2

echo "[INFO] Check factory resolver with PAT/OAuth setup"
# for public repo
if [ "$(requestFactoryResolverGitRepoUrl ${PUBLIC_REPO_URL} | grep "HTTP/1.1 200")" ]; then
echo "[INFO] Factory resolver returned 'HTTP/1.1 200' status code."
else
echo "[ERROR] Factory resolver returned wrong status code. Expected: HTTP/1.1 200"
exit 1
fi

# for private repo
if [ "$(requestFactoryResolverGitRepoUrl ${PRIVATE_REPO_URL} | grep "HTTP/1.1 200")" ]; then
echo "[INFO] Factory resolver returned 'HTTP/1.1 200' status code."
else
echo "[ERROR] Factory resolver returned wrong status code. Expected: HTTP/1.1 200"
exit 1
fi
}

runTestWorkspaceWithGitRepoUrl() {
WS_NAME=$1
PROJECT_NAME=$2
GIT_REPO_URL=$3

oc new-project ${USER_PROJECT_NAME} || true
oc project ${USER_PROJECT_NAME}
cat .ci/openshift-ci/devworkspace-test.yaml > devworkspace-test.yaml

# patch the devworkspace-test.yaml file
sed -i "s#ws-name#${WS_NAME}#g" devworkspace-test.yaml
sed -i "s#project-name#${PROJECT_NAME}#g" devworkspace-test.yaml
sed -i "s#git-repo-url#${GIT_REPO_URL}#g" devworkspace-test.yaml

cat devworkspace-test.yaml

oc apply -f devworkspace-test.yaml -n ${USER_PROJECT_NAME}
oc wait -n ${USER_PROJECT_NAME} --for=condition=Ready dw ${WS_NAME} --timeout=360s
}

testProjectIsCloned() {
PROJECT_NAME=$1
WORKSPACE_POD_NAME=$(oc get pods -n ${USER_PROJECT_NAME} | grep workspace | awk '{print $1}')
if oc exec -it -n ${USER_PROJECT_NAME} ${WORKSPACE_POD_NAME} -- test -f /projects/${PROJECT_NAME}/${YAML_FILE_NAME}; then
echo "[INFO] Project file /projects/${PROJECT_NAME}/${YAML_FILE_NAME} exists."
else
echo "[ERROR] Project file /projects/${PROJECT_NAME}/${YAML_FILE_NAME} does not exist."
exit 1
fi
}

# check a project is not cloned for private repo with no OAuth/PAT setup
testProjectIsNotCloned() {
dmytro-ndp marked this conversation as resolved.
Show resolved Hide resolved
PROJECT_NAME=$1
WORKSPACE_POD_NAME=$(oc get pods -n ${USER_PROJECT_NAME} | grep workspace | awk '{print $1}')
if oc exec -it -n ${USER_PROJECT_NAME} ${WORKSPACE_POD_NAME} -- test -e /projects/${PROJECT_NAME}; then
echo "[ERROR] Project /projects/${PROJECT_NAME} exists."
exit 1
else
echo "[INFO] Project /projects/${PROJECT_NAME} does not exist."
fi
}

deleteTestWorkspace() {
WS_NAME=$1
oc delete dw ${WS_NAME} -n ${USER_PROJECT_NAME}
}

# Catch the finish of the job and write logs in artifacts.
catchFinish() {
local RESULT=$?
killProcessByPort
if [ "$RESULT" != "0" ]; then
set +e
collectEclipseCheLogs
set -e
fi

[[ "${RESULT}" != "0" ]] && echo "[ERROR] Job failed." || echo "[INFO] Job completed successfully."
exit $RESULT
}

collectEclipseCheLogs() {
mkdir -p ${ARTIFACTS_DIR}/che-logs

# Collect all Eclipse Che logs and cluster CR
chectl server:logs -n $CHE_NAMESPACE --directory ${ARTIFACTS_DIR}/che-logs --telemetry off
oc get checluster -o yaml -n $CHE_NAMESPACE > "${ARTIFACTS_DIR}/che-cluster.yaml"
}

testClonePublicRepoNoPatOAuth() {
WS_NAME=$1
PROJECT_NAME=$2
GIT_REPO_URL=$3

runTestWorkspaceWithGitRepoUrl ${WS_NAME} ${PROJECT_NAME} ${GIT_REPO_URL}
testProjectIsCloned ${PROJECT_NAME}
deleteTestWorkspace ${WS_NAME}
}

testClonePrivateRepoNoPatOAuth() {
WS_NAME=$1
PROJECT_NAME=$2
GIT_REPO_URL=$3

runTestWorkspaceWithGitRepoUrl ${WS_NAME} ${PROJECT_NAME} ${GIT_REPO_URL}
testProjectIsNotCloned ${PROJECT_NAME}
deleteTestWorkspace ${WS_NAME}
}

setupTestEnvironment() {
provisionOpenShiftOAuthUser
createCustomResourcesFile
deployChe
forwardPortToService
}
21 changes: 21 additions & 0 deletions .ci/openshift-ci/devworkspace-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
name: ws-name
spec:
started: true
template:
projects:
- name: project-name
git:
remotes:
origin: git-repo-url
contributions:
- name: che-code
uri: https://eclipse-che.github.io/che-plugin-registry/main/v3/plugins/che-incubator/che-code/latest/devfile.yaml
components:
- name: che-code-runtime-description
container:
env:
- name: CODE_HOST
value: 0.0.0.0
12 changes: 12 additions & 0 deletions .ci/openshift-ci/htpasswdProvider.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: htpasswd
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpass-secret
31 changes: 31 additions & 0 deletions .ci/openshift-ci/test-bitbucket-flow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright (c) 2023 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
#

# exit immediately when a command fails
set -ex
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

export PUBLIC_REPO_URL=${PUBLIC_REPO_URL:-"https://chepullreq1@bitbucket.org/chepullreq/public-repo.git"}
export PRIVATE_REPO_URL=${PRIVATE_REPO_URL:-"https://chepullreq1@bitbucket.org/chepullreq/private-repo.git"}

# import common test functions
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "${SCRIPT_DIR}"/common.sh

trap "catchFinish" EXIT SIGINT

setupTestEnvironment
testFactoryResolverNoPatOAuth ${PUBLIC_REPO_URL} ${PRIVATE_REPO_URL}
testClonePublicRepoNoPatOAuth ${PUBLIC_REPO_WORKSPACE_NAME} ${PUBLIC_PROJECT_GITLAB_NAME} ${PUBLIC_REPO_URL}
testClonePrivateRepoNoPatOAuth ${PRIVATE_REPO_WORKSPACE_NAME} ${PRIVATE_PROJECT_GITLAB_NAME} ${PRIVATE_REPO_URL}
31 changes: 31 additions & 0 deletions .ci/openshift-ci/test-github-flow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright (c) 2023 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
#

# exit immediately when a command fails
set -ex
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

export PUBLIC_REPO_URL=${PUBLIC_REPO_URL:-"https://github.com/chepullreq1/public-repo.git"}
export PRIVATE_REPO_URL=${PRIVATE_REPO_URL:-"https://github.com/chepullreq1/private-repo.git"}

# import common test functions
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "${SCRIPT_DIR}"/common.sh

trap "catchFinish" EXIT SIGINT

setupTestEnvironment
testFactoryResolverNoPatOAuth ${PUBLIC_REPO_URL} ${PRIVATE_REPO_URL}
testClonePublicRepoNoPatOAuth ${PUBLIC_REPO_WORKSPACE_NAME} ${PUBLIC_PROJECT_GITLAB_NAME} ${PUBLIC_REPO_URL}
testClonePrivateRepoNoPatOAuth ${PRIVATE_REPO_WORKSPACE_NAME} ${PRIVATE_PROJECT_GITLAB_NAME} ${PRIVATE_REPO_URL}
31 changes: 31 additions & 0 deletions .ci/openshift-ci/test-gitlab-flow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright (c) 2023 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
#

# exit immediately when a command fails
set -ex
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

export PUBLIC_REPO_URL=${PUBLIC_REPO_URL:-"https://gitlab.com/chepullreq1/public-repo.git"}
export PRIVATE_REPO_URL=${PRIVATE_REPO_URL:-"https://gitlab.com/chepullreq1/private-repo.git"}

# import common test functions
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "${SCRIPT_DIR}"/common.sh

trap "catchFinish" EXIT SIGINT

setupTestEnvironment
testFactoryResolverNoPatOAuth ${PUBLIC_REPO_URL} ${PRIVATE_REPO_URL}
testClonePublicRepoNoPatOAuth ${PUBLIC_REPO_WORKSPACE_NAME} ${PUBLIC_PROJECT_GITLAB_NAME} ${PUBLIC_REPO_URL}
testClonePrivateRepoNoPatOAuth ${PRIVATE_REPO_WORKSPACE_NAME} ${PRIVATE_PROJECT_GITLAB_NAME} ${PRIVATE_REPO_URL}
Loading