Skip to content

Commit

Permalink
feat: general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Nov 23, 2024
1 parent e34a796 commit 36d1350
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions .github/workflows/sync-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ jobs:
echo "Branch $pr_branch already exists. Fetching and updating."
git fetch origin "$pr_branch"
git checkout "$pr_branch"
git rebase "origin/$pr_branch"
git rebase "origin/$branch_name"
else
echo "Creating new branch $pr_branch."
git checkout -b "$pr_branch"
fi
git clone https://github.com/ubiquity/ts-template template-repo
# Convert WHITELIST_FILES to array
whitelist_files=()
IFS=' ' read -r -a whitelist_files <<< "$WHITELIST_FILES"
# Convert ADDITIONAL_FILES inputs to array
additional_files=()
if [[ -n "$ADDITIONAL_FILES" ]]; then
Expand All @@ -75,23 +79,33 @@ jobs:
# Prepare file list for the PR body and process each whitelist file
file_list=""
for file in $WHITELIST_FILES "${additional_files[@]}"; do
for file in "${whitelist_files[@]}" "${additional_files[@]}"; do
# BLACKLIST_FILES check
skip_file=false
for blacklisted in "${blacklist_files[@]}"; do
if [[ "$file" == "$blacklisted" ]]; then
skip_file=true
break
fi
done
if [[ "$skip_file" == true ]]; then
echo "Skipping blacklisted file: $file"
continue
fi
# Process files
if [[ -d "template-repo/$file" ]]; then
# Copy directory contents to avoid nesting
echo "Processing directory: $file"
mkdir -p "$file" # Ensure target directory exists
mkdir -p "$file"
rsync -a --delete "template-repo/$file/" "$file/"
file_list+=$'\n'"- \`${file}\` (directory)"
elif [[ -e "template-repo/$file" ]]; then
# Skip file if they match the blacklist
if [[ ! " ${blacklist_files[@]} " =~ " ${file} " ]]; then
cp -f "template-repo/$file" "$file"
file_list+=$'\n'"- \`${file}\`"
else
echo "Skipping blacklisted file: $file"
fi
echo "Processing file: $file"
cp -f "template-repo/$file" "$file"
file_list+=$'\n'"- \`${file}\`"
else
# Remove whitelisted file from destination if it doesn't exist in template
echo "Removing file/directory: $file"
rm -rf "$file"
file_list+=$'\n'"- \`${file}\` (removed)"
fi
Expand All @@ -105,16 +119,14 @@ jobs:
git commit -m "chore: sync template" || echo "No changes to commit."
# Push
git push "$original_remote" "$pr_branch"
git push --force "$original_remote" "$pr_branch" || echo "Branch already exists remotely."
# Check for existing pull requests
existing_pr=$(gh pr list --base "$branch_name" --head "$pr_branch" --state open --json id --jq '.[0].id')
if [[ -z "$existing_pr" ]]; then
# Create a new pull request
gh pr create --title "Sync branch to template" --body "This pull request merges changes from the template repository, overwriting or removing the following files:${file_list}" --head "$pr_branch" --base "$branch_name"
else
# Update the body of the existing pull request
gh pr edit "$existing_pr" --body "This pull request merges changes from the template repository, overwriting or removing the following files:${file_list}"
echo "Updated the existing pull request #$existing_pr."
fi

0 comments on commit 36d1350

Please sign in to comment.