fix: create parent directories for nested clonePath#1652
Conversation
|
Hi @snecklifter. Thanks for your PR. I'm waiting for a devfile member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds ChangesParent Directory Creation Fix with Integration Test
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thank you @snecklifter LGTM, could you please add some tests in https://github.com/devfile/devworkspace-operator/tree/main/project-clone/test? |
When a devfile project specifies a nested clonePath (e.g. "back/devfile-rest"), the intermediary directories are never created, causing os.Rename to fail when moving the cloned project to its final destination. Add os.MkdirAll calls before os.Rename in both the git and zip project setup paths to ensure parent directories exist. Add an integration test fixture exercising nested clonePath with multiple projects sharing intermediary directories. Fixes: eclipse-che/che#23877 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Chris Brown <chribrow@redhat.com>
847a41d to
437833d
Compare
|
Thanks @dkwon17 — I've added an integration test fixture at |
|
Tested this PR and it seems to work as expected
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
name: nested-clone-path-test
labels:
app.kubernetes.io/name: devworkspace-project-clone-tests
app.kubernetes.io/part-of: devworkspace-operator
annotations:
controller.devfile.io/debug-start: "true"
spec:
started: true
routingClass: 'basic'
template:
attributes:
controller.devfile.io/storage-type: ephemeral
variables:
test_runner_image: quay.io/devfile/project-clone:next # Requires git, bash
main_repo: https://github.com/devfile/devworkspace-operator.git
default_branch_name: main
projects:
- name: backend-api
clonePath: back/api
git:
remotes:
origin: "{{main_repo}}"
- name: backend-worker
clonePath: back/worker
git:
remotes:
origin: "{{main_repo}}"
- name: frontend-app
clonePath: ui/app
git:
remotes:
origin: "{{main_repo}}"
- name: flat-project
git:
remotes:
origin: "{{main_repo}}"
components:
- name: test-project-clone
container:
image: "{{test_runner_image}}"
memoryLimit: 512Mi
mountSources: true
command:
- "/bin/bash"
- "-c"
- |
set -e
fail() {
echo "[ERROR] $1"
echo "[ERROR] See project-clone logs: "
echo "[ERROR] oc logs -n $DEVWORKSPACE_NAMESPACE deploy/$DEVWORKSPACE_ID -c project-clone"
exit 1
}
if [ -f "${PROJECTS_ROOT}/project-clone-errors.log" ]; then
echo "==== BEGIN PROJECT CLONE LOGS ===="
sed 's/^/ /g' "${PROJECTS_ROOT}/project-clone-errors.log"
echo "==== END PROJECT CLONE LOGS ===="
echo -e "\n\n"
fi
for project_dir in "back/api" "back/worker" "ui/app" "flat-project"; do
if [ ! -d "${PROJECTS_ROOT}/${project_dir}" ]; then
fail "Project at ${project_dir} not cloned successfully"
fi
done
echo "Testing nested clonePath project: back/api"
cd "${PROJECTS_ROOT}/back/api"
branch_name=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch_name" != "{{default_branch_name}}" ]; then
fail "Project back/api does not have default branch checked out"
fi
remote_url=$(git config remote.origin.url)
if [ "$remote_url" != "{{main_repo}}" ]; then
fail "Remote 'origin' not configured for back/api"
fi
echo "back/api: on $branch_name, remotes configured"
echo "Testing nested clonePath project: back/worker"
cd "${PROJECTS_ROOT}/back/worker"
branch_name=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch_name" != "{{default_branch_name}}" ]; then
fail "Project back/worker does not have default branch checked out"
fi
remote_url=$(git config remote.origin.url)
if [ "$remote_url" != "{{main_repo}}" ]; then
fail "Remote 'origin' not configured for back/worker"
fi
echo "back/worker: on $branch_name, remotes configured"
echo "Testing nested clonePath project: ui/app"
cd "${PROJECTS_ROOT}/ui/app"
branch_name=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch_name" != "{{default_branch_name}}" ]; then
fail "Project ui/app does not have default branch checked out"
fi
remote_url=$(git config remote.origin.url)
if [ "$remote_url" != "{{main_repo}}" ]; then
fail "Remote 'origin' not configured for ui/app"
fi
echo "ui/app: on $branch_name, remotes configured"
echo "Testing flat clonePath project (no nesting)"
cd "${PROJECTS_ROOT}/flat-project"
branch_name=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch_name" != "{{default_branch_name}}" ]; then
fail "Project flat-project does not have default branch checked out"
fi
remote_url=$(git config remote.origin.url)
if [ "$remote_url" != "{{main_repo}}" ]; then
fail "Remote 'origin' not configured for flat-project"
fi
echo "flat-project: on $branch_name, remotes configured"
echo "[SUCCESS] Test succeeded. Sleeping indefinitely"
tail -f /dev/null
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rohanKanojia, snecklifter The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@snecklifter thank you! Merging. |
Summary
clonePath(e.g.back/devfile-rest),os.Renamefails because the intermediary parent directories don't existos.MkdirAll(path.Dir(...))calls beforeos.Renamein both the git and zip project setup paths to ensure parent directories are createdclonePathvalues,path.Dirresolves to the already-existing root soMkdirAllis a no-opFixes: eclipse-che/che#23877
Test plan
clonePathvalues (e.g.back/devfile-rest,ui/devfile-ui)/projectsclonePathvalues still work as before🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests