|
| 1 | +apiVersion: workspace.devfile.io/v1alpha2 |
| 2 | +kind: DevWorkspace |
| 3 | +metadata: |
| 4 | + name: project-clone-test |
| 5 | + labels: |
| 6 | + app.kubernetes.io/name: devworkspace-project-clone-tests |
| 7 | + app.kubernetes.io/part-of: devworkspace-operator |
| 8 | + annotations: |
| 9 | + controller.devfile.io/debug-start: "true" |
| 10 | +spec: |
| 11 | + started: true |
| 12 | + routingClass: 'basic' |
| 13 | + template: |
| 14 | + attributes: |
| 15 | + controller.devfile.io/storage-type: ephemeral |
| 16 | + variables: |
| 17 | + test_runner_image: quay.io/devfile/project-clone:next # Requires git, bash |
| 18 | + main_repo: https://github.com/devfile/devworkspace-operator.git |
| 19 | + fork_repo: https://github.com/amisevsk/devworkspace-operator.git |
| 20 | + checkout_branch: 0.21.x |
| 21 | + checkout_tag: v0.21.0 |
| 22 | + checkout_hash: e17b2754 |
| 23 | + default_branch_name: main |
| 24 | + projects: |
| 25 | + - name: default-project-setup |
| 26 | + git: |
| 27 | + remotes: |
| 28 | + main-origin: "{{main_repo}}" |
| 29 | + - name: test-checkout-branch |
| 30 | + git: |
| 31 | + checkoutFrom: |
| 32 | + remote: origin |
| 33 | + revision: "{{checkout_branch}}" |
| 34 | + remotes: |
| 35 | + origin: "{{main_repo}}" |
| 36 | + fork: "{{fork_repo}}" |
| 37 | + - name: test-checkout-tag |
| 38 | + git: |
| 39 | + checkoutFrom: |
| 40 | + remote: fork |
| 41 | + revision: "{{checkout_tag}}" |
| 42 | + remotes: |
| 43 | + origin: "{{main_repo}}" |
| 44 | + fork: "{{fork_repo}}" |
| 45 | + - name: test-checkout-hash |
| 46 | + git: |
| 47 | + checkoutFrom: |
| 48 | + remote: fork |
| 49 | + revision: "{{checkout_hash}}" |
| 50 | + remotes: |
| 51 | + origin: "{{main_repo}}" |
| 52 | + fork: "{{fork_repo}}" |
| 53 | + components: |
| 54 | + - name: test-project-clone |
| 55 | + container: |
| 56 | + image: "{{test_runner_image}}" |
| 57 | + memoryLimit: 512Mi |
| 58 | + mountSources: true |
| 59 | + command: |
| 60 | + - "/bin/bash" |
| 61 | + - "-c" |
| 62 | + - | |
| 63 | + set -e |
| 64 | +
|
| 65 | + fail() { |
| 66 | + echo "[ERROR] $1" |
| 67 | + echo "[ERROR] See project-clone logs: " |
| 68 | + echo "[ERROR] oc logs -n $DEVWORKSPACE_NAMESPACE deploy/$DEVWORKSPACE_ID -c project-clone" |
| 69 | + exit 1 |
| 70 | + } |
| 71 | +
|
| 72 | + if [ -f "${PROJECTS_ROOT}/project-clone-errors.log" ]; then |
| 73 | + echo "==== BEGIN PROJECT CLONE LOGS ====" |
| 74 | + sed 's/^/ /g' "${PROJECTS_ROOT}/project-clone-errors.log" |
| 75 | + echo "==== END PROJECT CLONE LOGS ====" |
| 76 | + echo -e "\n\n" |
| 77 | + fi |
| 78 | +
|
| 79 | + for project_dir in "default-project-setup" "test-checkout-branch" "test-checkout-tag" "test-checkout-hash"; do |
| 80 | + if [ ! -d "${PROJECTS_ROOT}/${project_dir}" ]; then |
| 81 | + fail "Project $project_dir not cloned successfully" |
| 82 | + fi |
| 83 | + done |
| 84 | +
|
| 85 | + echo "Testing default project set up" |
| 86 | + cd "${PROJECTS_ROOT}/default-project-setup" |
| 87 | + branch_name=$(git rev-parse --abbrev-ref HEAD) |
| 88 | + if [ "$branch_name" != "{{default_branch_name}}" ]; then |
| 89 | + fail "Project does not have default branch checked out" |
| 90 | + fi |
| 91 | + tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) |
| 92 | + if [ "$tracking_branch" != "main-origin/{{default_branch_name}}" ]; then |
| 93 | + fail "Default project's branch does not track remote branch" |
| 94 | + fi |
| 95 | + remote_url=$(git config remote.main-origin.url) |
| 96 | + if [ "$remote_url" != "{{main_repo}}" ]; then |
| 97 | + fail "Remote 'main-origin' not configured" |
| 98 | + fi |
| 99 | + echo "Project is on $branch_name, tracking $tracking_branch, with remotes configured" |
| 100 | +
|
| 101 | + echo "Testing branch checkout project set up" |
| 102 | + cd "${PROJECTS_ROOT}/test-checkout-branch" |
| 103 | + branch_name=$(git rev-parse --abbrev-ref HEAD) |
| 104 | + if [ "$branch_name" != "{{checkout_branch}}" ]; then |
| 105 | + fail "Project does not have {{checkout_branch}} branch checked out" |
| 106 | + fi |
| 107 | + tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) |
| 108 | + if [ "$tracking_branch" != "origin/{{checkout_branch}}" ]; then |
| 109 | + fail "Checked out branch does not track remote branch origin/{{checkout_branch}}" |
| 110 | + fi |
| 111 | + remote_url=$(git config remote.origin.url) |
| 112 | + if [ "$remote_url" != "{{main_repo}}" ]; then |
| 113 | + fail "Remote 'origin' not configured" |
| 114 | + fi |
| 115 | + remote_url=$(git config remote.fork.url) |
| 116 | + if [ "$remote_url" != "{{fork_repo}}" ]; then |
| 117 | + fail "Remote 'fork' not configured" |
| 118 | + fi |
| 119 | + echo "Project is on $branch_name, tracking $tracking_branch, with remotes configured" |
| 120 | +
|
| 121 | + echo "Testing tag checkout project set up" |
| 122 | + cd "${PROJECTS_ROOT}/test-checkout-tag" |
| 123 | + tag_name=$(git describe --tags) |
| 124 | + if [ "$tag_name" != "{{checkout_tag}}" ]; then |
| 125 | + fail "Project does not have tag {{checkout_tag}} checked out" |
| 126 | + fi |
| 127 | + remote_url=$(git config remote.origin.url) |
| 128 | + if [ "$remote_url" != "{{main_repo}}" ]; then |
| 129 | + fail "Remote 'origin' not configured" |
| 130 | + fi |
| 131 | + remote_url=$(git config remote.fork.url) |
| 132 | + if [ "$remote_url" != "{{fork_repo}}" ]; then |
| 133 | + fail "Remote 'fork' not configured" |
| 134 | + fi |
| 135 | + echo "Project is on tag $tag_name, with remotes configured" |
| 136 | +
|
| 137 | + echo "Testing hash checkout project set up" |
| 138 | + cd "${PROJECTS_ROOT}/test-checkout-hash" |
| 139 | + commit_hash=$(git rev-parse HEAD) |
| 140 | + if [[ "$commit_hash" == "{{checkout_hash}}"* ]]; then |
| 141 | + fail "Current HEAD is not at {{checkout_hash}}" |
| 142 | + fi |
| 143 | + remote_url=$(git config remote.origin.url) |
| 144 | + if [ "$remote_url" != "{{main_repo}}" ]; then |
| 145 | + fail "Remote 'origin' not configured" |
| 146 | + fi |
| 147 | + remote_url=$(git config remote.fork.url) |
| 148 | + if [ "$remote_url" != "{{fork_repo}}" ]; then |
| 149 | + fail "Remote 'fork' not configured" |
| 150 | + fi |
| 151 | + echo "Project is on commit $commit_hash, with remotes configured" |
| 152 | +
|
| 153 | + echo "[SUCCESS] Test succeeded. Sleeping indefinitely" |
| 154 | + tail -f /dev/null |
0 commit comments