all in one run fix2 #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync Weblate Commits | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
check-and-sync: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
run: | | |
git clone https://github.com/racicLuka/weblate-test.git | |
cd weblate-test | |
git checkout main | |
- name: List Weblate Commits | |
id: weblate-commits | |
run: | | |
cd weblate-test | |
git fetch origin | |
output=$(git log --grep="Weblate" origin/main --format=%H) | |
declare -a commits=() | |
while IFS= read -r line; do | |
commits+=("$line") | |
done <<< "$output" | |
echo "$commits" | |
git fetch --prune --tags | |
branches_output=$(git branch -r | grep -v "origin/main" | cut -d'/' -f2 | xargs) | |
echo "new output $branches_output" | |
declare -a OTHER_BRANCHES=() | |
while IFS= read -r line; do | |
OTHER_BRANCHES+=("$line") | |
done <<< "$branches_output" | |
MISSING_COMMITS=() | |
MISSING_BRANCHES=() | |
for BRANCH in $OTHER_BRANCHES; do | |
for COMMIT in $COMMITS; do | |
if ! git branch --contains $COMMIT | grep -q "remotes/origin/$BRANCH"; then | |
echo "Commit $COMMIT does not exist in branch $BRANCH" | |
MISSING_COMMITS+=($COMMIT) | |
MISSING_BRANCHES+=($BRANCH) | |
fi | |
done | |
done | |
for ((i=0; i<=${#MISSING_COMMITS[@]}; ++i)); do | |
git checkout ${MISSING_BRANCHES[$i]} | |
git cherry-pick ${MISSING_COMMITS[$i]} | |
done | |
git push origin $OTHER_BRANCHES |