workflow #15
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 | |
uses: actions/checkout@v2 | |
- name: List Weblate Commits | |
id: weblate-commits | |
run: | | |
git fetch origin | |
COMMITS=$(git log --format=%H --grep="Weblate" origin/main..) | |
echo "{commits}=$COMMITS" >> $GITHUB_OUTPUT | |
- name: Set Other Branches | |
id: set-other-branches | |
run: | | |
git fetch --prune --tags | |
OTHER_BRANCHES=$(git branch -r | grep -v "origin/main" | cut -d'/' -f2 | xargs) | |
echo "{other_branches}=$OTHER_BRANCHES" >> $GITHUB_OUTPUT | |
- name: Check for Commits in Other Branches | |
id: check-other-branches | |
run: | | |
MISSING_COMMITS=() | |
MISSING_BRANCHES=() | |
for BRANCH in ${{ steps.set-other-branches.outputs.other_branches }}; do | |
for COMMIT in ${{ steps.weblate-commits.outputs.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 | |
echo "{missing_commits}=$MISSING_COMMITS[*]" >> $GITHUB_OUTPUT | |
echo "{missing_branches}=$MISSING_BRANCHES[*]" >> $GITHUB_OUTPUT | |
- name: Pull Weblate Commits to Other Branches | |
run: | | |
MISSING_COMMITS=(${{ steps.check-other-branches.outputs.missing_commits }}) | |
MISSING_BRANCHES=(${{ steps.check-other-branches.outputs.missing_branches }}) | |
echo "$MISSING_COMMITS" | |
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 |