Sync src from upstream (exclude Korean translations) #219
This file contains hidden or 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 src from upstream (exclude Korean translations) | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| jobs: | |
| sync-src: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set git identity | |
| shell: bash | |
| run: | | |
| git config --global user.name "minchodang" | |
| git config --global user.email "[email protected]" | |
| - name: Extract src from origin/master | |
| shell: bash | |
| run: | | |
| rm -rf tmp-src | |
| mkdir -p tmp-src | |
| git archive origin/master src | tar -x -C tmp-src | |
| mv tmp-src/src tmp-src/master-src | |
| - name: Build exclude list | |
| shell: bash | |
| run: | | |
| : > $GITHUB_WORKSPACE/exclude.lst | |
| echo "pages/_app.tsx" >> $GITHUB_WORKSPACE/exclude.lst | |
| echo "pages/_document.tsx" >> $GITHUB_WORKSPACE/exclude.lst | |
| echo "providers/PostHogProvider.tsx" >> $GITHUB_WORKSPACE/exclude.lst | |
| echo "components/layout.tsx" >> $GITHUB_WORKSPACE/exclude.lst | |
| echo "react-ko-form/components/Banner*" >> $GITHUB_WORKSPACE/exclude.lst | |
| echo "src/components/seo.tsx" >> $GITHUB_WORKSPACE/exclude.lst | |
| grep -IPlr --exclude-dir=.git '\p{Hangul}' src/ | sed 's|^src/||' >> $GITHUB_WORKSPACE/exclude.lst | |
| sort -u -o $GITHUB_WORKSPACE/exclude.lst $GITHUB_WORKSPACE/exclude.lst | |
| - name: Detect changes | |
| id: compare | |
| shell: bash | |
| run: | | |
| mkdir -p src | |
| changes=$(rsync -rcnc --delete --out-format='%n' \ | |
| --exclude-from="$GITHUB_WORKSPACE/exclude.lst" \ | |
| tmp-src/master-src/ src/ | grep -v '^$' || true) | |
| if [ -n "$changes" ]; then | |
| echo "pr_needed=true" >> $GITHUB_ENV | |
| else | |
| echo "pr_needed=false" >> $GITHUB_ENV | |
| fi | |
| - name: Update src content | |
| if: ${{ env.pr_needed == 'true' }} | |
| shell: bash | |
| run: | | |
| if git show-ref --quiet refs/remotes/origin/master-ko; then | |
| git checkout -B master-ko origin/master-ko | |
| else | |
| git checkout -B master-ko | |
| fi | |
| rsync -a --delete --exclude-from=$GITHUB_WORKSPACE/exclude.lst tmp-src/master-src/ src/ | |
| git add -A src | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Sync src with origin/master (exclude Korean translations)" | |
| echo "commit_made=true" >> $GITHUB_ENV | |
| else | |
| echo "commit_made=false" >> $GITHUB_ENV | |
| fi | |
| - name: Find existing PR | |
| if: ${{ env.pr_needed == 'true' && env.commit_made == 'true' }} | |
| id: pr-branch | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| shell: bash | |
| run: | | |
| branch=$(gh pr list --json headRefName --jq \ | |
| '.[] | select(.headRefName | startswith("sync-src-")) | .headRefName' \ | |
| | head -n1) | |
| echo "branch=$branch" >> $GITHUB_OUTPUT | |
| - name: Force push to existing branch | |
| if: ${{ env.pr_needed == 'true' && env.commit_made == 'true' && steps.pr-branch.outputs.branch != '' }} | |
| shell: bash | |
| run: | | |
| git push origin master-ko:${{ steps.pr-branch.outputs.branch }} --force | |
| - name: Create new PR | |
| if: ${{ env.pr_needed == 'true' && env.commit_made == 'true' && steps.pr-branch.outputs.branch == '' }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| shell: bash | |
| run: | | |
| new_branch=sync-src-${{ github.run_id }} | |
| git checkout -b "$new_branch" | |
| git push origin "$new_branch" | |
| gh pr create \ | |
| --title "Sync src with upstream (exclude translated files)" \ | |
| --body "Auto-sync src/ with origin/master, excluding Korean translations and preserving custom files." \ | |
| --head "$new_branch" \ | |
| --base master-ko |