Skip to content

workflow 2

workflow 2 #17

Workflow file for this run

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 --grep="Weblate" origin/main --format=%H)
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 "these are the other branches $OTHER_BRANCHES"
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 "these are the missing commits $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