From ef258931ed1f294210bd7685396fca5ec116fba0 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Fri, 13 Dec 2024 11:25:10 -0800 Subject: [PATCH] Add workflow to create new branch and PR for generating POT automatically (#242) Signed-off-by: Andy Fragen --------- Signed-off-by: Andy Fragen Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- .github/workflows/generate-pot-pr.yml | 71 +++++++++++++++++++++++++++ .github/workflows/generate-pot.yml | 26 ---------- 2 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/generate-pot-pr.yml delete mode 100644 .github/workflows/generate-pot.yml diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml new file mode 100644 index 0000000..04077e3 --- /dev/null +++ b/.github/workflows/generate-pot-pr.yml @@ -0,0 +1,71 @@ +name: Generate POT PR + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + generate-pot: + name: Generate POT PR + if: github.repository == 'aspirepress/aspireupdate' + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - name: Check out source code + uses: actions/checkout@v4 + + - name: Set up PHP environment + uses: shivammathur/setup-php@v2 + with: + php-version: "7.4" + + - name: Setup WP-CLI + uses: godaddy-wordpress/setup-wp-cli@1 + + - name: Configure git user + run: | + git config --global user.email "andy@thefragens.com" + git config --global user.name "Andy Fragen" + + - 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 + uses: repo-sync/pull-request@v2 + with: + source_branch: generate-pot + destination_branch: ${{ github.event.repository.default_branch }} + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_title: Generate POT + pr_body: "This is an automated pull-request" diff --git a/.github/workflows/generate-pot.yml b/.github/workflows/generate-pot.yml deleted file mode 100644 index e3e39bf..0000000 --- a/.github/workflows/generate-pot.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Generate POT - -on: - push: - branches: - - main - - translations - -jobs: - WP_POT_Generator: - if: github.repository == 'aspirepress/aspireupdate' - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@master - - name: WordPress POT Generator - uses: varunsridharan/action-wp-pot-generator@2.0 - with: - save_path: "./languages" - item_slug: "${{ github.event.repository.name }}" - domain: "${{ github.event.repository.name }}" - package_name: "${{ github.event.repository.name }}" - headers: '{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}