Skip to content

Merge pull request #396 from namithj/hosts.json #85

Merge pull request #396 from namithj/hosts.json

Merge pull request #396 from namithj/hosts.json #85

name: Generate POT PR
on:
workflow_dispatch:
push:
branches:
- main
permissions:
contents: read
jobs:
generate-pot:
name: Generate POT PR
if: github.repository == 'aspirepress/aspireupdate'
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
with:
egress-policy: audit
- name: Check out source code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up PHP environment
uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2
with:
php-version: "7.4"
- name: Setup WP-CLI
uses: godaddy-wordpress/setup-wp-cli@80c9a89bd347082429795c0f12acf567e2c390d4 # 1.0.0
- name: Configure git user
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
- name: Check if remote branch exists
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin generate-pot) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
- name: Create branch to base pull request on
if: env.REMOTE_BRANCH_EXISTS == 0
run: |
git checkout -b generate-pot
- name: Fetch existing branch to add commits to
if: env.REMOTE_BRANCH_EXISTS == 1
run: |
git fetch --all --prune
git checkout generate-pot
git pull --no-rebase
- name: Generate POT
run: |
wp i18n make-pot . "./languages/${{ github.event.repository.name }}.pot" --headers='{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}'
- name: Check if there are changes
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
- name: Commit changes
if: env.CHANGES_DETECTED == 1
run: |
git add "./languages/${{ github.event.repository.name }}.pot"
git commit -m "Generate POT - $(date +'%Y-%m-%d')"
git push origin generate-pot
- name: Create pull request
if: env.CHANGES_DETECTED == 1 && env.REMOTE_BRANCH_EXISTS == 0
run: gh pr create --base ${BRANCH_NAME} --head generate-pot --title "Generate POT - $(date +'%Y-%m-%d')" --body "Automated PR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}