From c23deb2d4085e7816b47ca55e17b7210f2c14c67 Mon Sep 17 00:00:00 2001 From: "adamlui@protonmail.com" Date: Thu, 10 Oct 2024 21:37:59 -0700 Subject: [PATCH] Created .github/workflows/sync-changes.yml --- .github/workflows/sync-changes.yml | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/sync-changes.yml diff --git a/.github/workflows/sync-changes.yml b/.github/workflows/sync-changes.yml new file mode 100644 index 0000000..765b4c3 --- /dev/null +++ b/.github/workflows/sync-changes.yml @@ -0,0 +1,88 @@ +name: Sync _locales/* between /extension/, then * to adamlui/ai-apps/you.com-omnibox/* + +on: + push: + branches: [main] + paths: ["**", "!.*", "!package*json", "!eslint.config*"] + +jobs: + build: + if: (github.repository == 'adamlui/you.com-omnibox') && (github.event.commits[0].committer.username != 'kudo-sync-bot') + runs-on: ubuntu-latest + + steps: + + - name: Checkout adamlui/you.com-omnibox + uses: actions/checkout@v4 + with: + token: ${{ secrets.REPO_SYNC_PAT }} + repository: adamlui/you.com-omnibox + path: adamlui/you.com-omnibox + fetch-depth: 2 + + - name: Checkout adamlui/ai-apps + uses: actions/checkout@v4 + with: + token: ${{ secrets.REPO_SYNC_PAT }} + repository: adamlui/ai-apps + path: adamlui/ai-apps + + - name: Sync _locales/* between /extension/ + run: | + cd ${{ github.workspace }}/adamlui/you.com-omnibox + ff_dir="firefox/extension/_locales" + chromium_dir="chromium/extension/_locales" + + # Loop thru all lang dirs in firefox + for locale in $(find "$ff_dir" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) ; do + ff_file="$ff_dir/$locale/messages.json" + chromium_file="$chromium_dir/$locale/messages.json" + if [[ -f "$ff_file" && -f "$chromium_file" ]] ; then + + # Get the latest commit timestamps for both files + ff_timestamp=$(git log -1 --format="%ct" -- "$ff_file" 2>/dev/null || echo 0) + chromium_timestamp=$(git log -1 --format="%ct" -- "$chromium_file" 2>/dev/null || echo 0) + + # Sync the most recently updated file to the other dir + if [[ $ff_timestamp -gt $chromium_timestamp ]] ; then + cp -f "$ff_file" "$chromium_file" + elif [[ $chromium_timestamp -gt $ff_timestamp ]] ; then + cp -f "$chromium_file" "$ff_file" + fi + fi + done + + - name: Sync * to adamlui/ai-apps/you.com-omnibox/* + run: | + rsync -avhr --delete --exclude={'.*','eslint*','package*json'} \ + ${{ github.workspace }}/adamlui/you.com-omnibox/ \ + ${{ github.workspace }}/adamlui/ai-apps/you.com-omnibox/ + + - name: Escape backticks in commit msg + env: + COMMIT_MSG: ${{ github.event.head_commit.message }} + run: | + echo "ESCAPED_MSG<> $GITHUB_ENV + echo "$COMMIT_MSG" | sed 's/`/\`/g' >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Config committer + run: | + gpg --batch --import <(echo "${{ secrets.GPG_PRIVATE_KEY }}") + git config --global user.name "kudo-sync-bot" + git config --global user.email "auto-sync@kudoai.com" + git config --global user.signingkey "${{ secrets.GPG_PRIVATE_ID }}" + + - name: Push changes to adamlui/you.com-omnibox + run: | + cd ${{ github.workspace }}/adamlui/you.com-omnibox + git add . + git commit -S -n -m "$ESCAPED_MSG ↞ [auto-sync from \`adamlui/you.com-omnibox\`]" || true + git push + + - name: Push changes to adamlui/ai-apps + run: | + cd ${{ github.workspace }}/adamlui/ai-apps + git add . + git commit -S -n -m "$ESCAPED_MSG ↞ [auto-sync from \`adamlui/you.com-omnibox\`]" || true + git push