-
Notifications
You must be signed in to change notification settings - Fork 2
chore(ci): prune worktrees in xtest cleanup #338
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
Changes from all commits
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,15 +3,47 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||||||||||||||||||
|
|
||||||||||||||||||
| # Function to get the bare repo path for each SDK | ||||||||||||||||||
| get_bare_repo_path() { | ||||||||||||||||||
| local sdk=$1 | ||||||||||||||||||
| case "$sdk" in | ||||||||||||||||||
| js) | ||||||||||||||||||
| echo "$SCRIPT_DIR/../js/src/web-sdk.git" | ||||||||||||||||||
| ;; | ||||||||||||||||||
| java) | ||||||||||||||||||
| echo "$SCRIPT_DIR/../java/src/java-sdk.git" | ||||||||||||||||||
| ;; | ||||||||||||||||||
| go) | ||||||||||||||||||
| echo "$SCRIPT_DIR/../go/src/otdfctl.git" | ||||||||||||||||||
| ;; | ||||||||||||||||||
| *) | ||||||||||||||||||
| echo "" | ||||||||||||||||||
| ;; | ||||||||||||||||||
| esac | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| for sdk in go java js; do | ||||||||||||||||||
| rm -rf "$SCRIPT_DIR/../$sdk/dist" | ||||||||||||||||||
|
|
||||||||||||||||||
| bare_repo_path=$(get_bare_repo_path "$sdk") | ||||||||||||||||||
|
|
||||||||||||||||||
| for branch in "$SCRIPT_DIR/../${sdk}/src/"*; do | ||||||||||||||||||
| # Check if the path ends with .git | ||||||||||||||||||
| # Check if the path ends with .git (skip bare repos) | ||||||||||||||||||
| if [[ $branch == *.git ]]; then | ||||||||||||||||||
| continue | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| if [ -d "$branch" ]; then | ||||||||||||||||||
| if ! git --git-dir="$bare_repo_path" worktree remove "$branch" --force; then | ||||||||||||||||||
| echo "Failed to remove worktree: $sdk#$branch" | ||||||||||||||||||
| fi | ||||||||||||||||||
| rm -rf "$branch" | ||||||||||||||||||
|
Comment on lines
+37
to
40
Contributor
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. The current logic for removing worktrees can be simplified and made less noisy. The A cleaner approach is to attempt
Suggested change
|
||||||||||||||||||
| fi | ||||||||||||||||||
| done | ||||||||||||||||||
|
|
||||||||||||||||||
| # Clean up any orphaned worktree registrations | ||||||||||||||||||
| if [[ -d "$bare_repo_path" ]]; then | ||||||||||||||||||
| echo "Pruning orphaned worktrees for $sdk..." | ||||||||||||||||||
| git --git-dir="$bare_repo_path" worktree prune 2>/dev/null || true | ||||||||||||||||||
| fi | ||||||||||||||||||
| done | ||||||||||||||||||
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.
This
get_bare_repo_pathfunction duplicates logic fromxtest/sdk/scripts/checkout-sdk-branch.shfor determining the bare repository path for each SDK. This duplication can lead to maintenance issues, as changes to SDK paths or names would need to be updated in both files.To improve maintainability, consider consolidating this logic into a single, shared script or configuration file that both
checkout-sdk-branch.shand this script can use. For example, you could create a helper script that sets environment variables for the paths based on the SDK language.