|
| 1 | +name: Generate POT PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - master |
| 9 | + |
| 10 | +jobs: |
| 11 | + generate-pot: |
| 12 | + name: Generate POT PR |
| 13 | + if: github.repository == "${{ github.event.repository.full_name }}" |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Check out source code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up PHP environment |
| 23 | + uses: shivammathur/setup-php@v2 |
| 24 | + with: |
| 25 | + php-version: "7.4" |
| 26 | + |
| 27 | + - name: Setup WP-CLI |
| 28 | + uses: godaddy-wordpress/setup-wp-cli@1 |
| 29 | + |
| 30 | + - name: Configure git user |
| 31 | + run: | |
| 32 | + git config --global user.email "[email protected]" |
| 33 | + git config --global user.name "Andy Fragen" |
| 34 | +
|
| 35 | + - name: Check if remote branch exists |
| 36 | + run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin generate-pot) ]] && echo "0" || echo "1")" >> $GITHUB_ENV |
| 37 | + |
| 38 | + - name: Create branch to base pull request on |
| 39 | + if: env.REMOTE_BRANCH_EXISTS == 0 |
| 40 | + run: | |
| 41 | + git checkout -b generate-pot |
| 42 | +
|
| 43 | + - name: Fetch existing branch to add commits to |
| 44 | + if: env.REMOTE_BRANCH_EXISTS == 1 |
| 45 | + run: | |
| 46 | + git fetch --all --prune |
| 47 | + git checkout generate-pot |
| 48 | + git pull --no-rebase |
| 49 | +
|
| 50 | + - name: Generate POT |
| 51 | + run: | |
| 52 | + wp i18n make-pot . "./languages/${{ github.event.repository.name }}.pot" --headers='{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}' |
| 53 | +
|
| 54 | + - name: Check if there are changes |
| 55 | + run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV |
| 56 | + |
| 57 | + - name: Commit changes |
| 58 | + if: env.CHANGES_DETECTED == 1 |
| 59 | + run: | |
| 60 | + git add "./languages/${{ github.event.repository.name }}.pot" |
| 61 | + git commit -m "Generate POT - $(date +'%Y-%m-%d')" |
| 62 | + git push origin generate-pot |
| 63 | +
|
| 64 | + - name: Create pull request |
| 65 | + if: env.CHANGES_DETECTED == 1 |
| 66 | + run: gh pr create --base main --head generate-pot --title "Generate POT - $(date +'%Y-%m-%d')" --body "Automated PR" |
| 67 | + env: |
| 68 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments