From 750acfcb9633d8a6df10a91ad55681467f500d57 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 10 Dec 2024 13:08:19 -0800 Subject: [PATCH 01/12] testing generate-pot-branch-pr workflow --- .github/workflows/pot-update-branch-pr.yml | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/pot-update-branch-pr.yml diff --git a/.github/workflows/pot-update-branch-pr.yml b/.github/workflows/pot-update-branch-pr.yml new file mode 100644 index 0000000..561c703 --- /dev/null +++ b/.github/workflows/pot-update-branch-pr.yml @@ -0,0 +1,71 @@ +name: generate POT branch-PR + +on: + workflow_dispatch: + push: + +jobs: + + generate-pot: #---------------------------------------------------------- + name: Generate POT PR + 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 && + env.REMOTE_BRANCH_EXISTS == 0 + 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" From bef5bc47b9359255c5b623970d82a6b5a211ddab Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 10 Dec 2024 13:14:11 -0800 Subject: [PATCH 02/12] update workflow --- .github/workflows/pot-update-branch-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pot-update-branch-pr.yml b/.github/workflows/pot-update-branch-pr.yml index 561c703..514794a 100644 --- a/.github/workflows/pot-update-branch-pr.yml +++ b/.github/workflows/pot-update-branch-pr.yml @@ -44,9 +44,9 @@ jobs: git checkout generate-pot git pull --no-rebase - - name: Generate POT + - name: Generate POT PR 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"}'" + 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 From 6771cab3c8963b603226522b6dd22066ea5a9ccd Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 10 Dec 2024 13:31:50 -0800 Subject: [PATCH 03/12] update workflow for testing --- .../{pot-update-branch-pr.yml => generate-pot-pr.yml} | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) rename .github/workflows/{pot-update-branch-pr.yml => generate-pot-pr.yml} (95%) diff --git a/.github/workflows/pot-update-branch-pr.yml b/.github/workflows/generate-pot-pr.yml similarity index 95% rename from .github/workflows/pot-update-branch-pr.yml rename to .github/workflows/generate-pot-pr.yml index 514794a..0e8b5cc 100644 --- a/.github/workflows/pot-update-branch-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -1,11 +1,10 @@ -name: generate POT branch-PR +name: Generate POT PR on: workflow_dispatch: push: jobs: - generate-pot: #---------------------------------------------------------- name: Generate POT PR permissions: @@ -19,7 +18,7 @@ jobs: - name: Set up PHP environment uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: "7.4" - name: Setup WP-CLI uses: godaddy-wordpress/setup-wp-cli@1 @@ -61,7 +60,7 @@ jobs: - name: Create pull request if: | env.CHANGES_DETECTED == 1 && - env.REMOTE_BRANCH_EXISTS == 0 + env.REMOTE_BRANCH_EXISTS == 1 uses: repo-sync/pull-request@v2 with: source_branch: generate-pot From cc2ccd0cd7079ce382f3edd05fbe0084396eb36e Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 10 Dec 2024 13:34:54 -0800 Subject: [PATCH 04/12] add back post-testing data --- .github/workflows/generate-pot-pr.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index 0e8b5cc..7ad7050 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -3,10 +3,14 @@ name: Generate POT PR on: workflow_dispatch: push: + branches: + - main + - master jobs: generate-pot: #---------------------------------------------------------- name: Generate POT PR + if: github.repository == 'aspirepress/aspireupdate' permissions: contents: write pull-requests: write From ffa0dcb733fcf94712641e992070add6c697bd4b Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 10 Dec 2024 13:36:20 -0800 Subject: [PATCH 05/12] remove GA workflow for POT --- .github/workflows/generate-pot.yml | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 .github/workflows/generate-pot.yml 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 }} From c32235dd04405e3554b84c9be8f429ad9de4c4cb Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 10 Dec 2024 13:50:27 -0800 Subject: [PATCH 06/12] update name --- .github/workflows/generate-pot-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index 7ad7050..b70fc58 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -47,7 +47,7 @@ jobs: git checkout generate-pot git pull --no-rebase - - name: Generate POT PR + - 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"}' From 418ed2a4644cc1bfc53c16f92f3931e0c2c8c661 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 10 Dec 2024 14:05:15 -0800 Subject: [PATCH 07/12] not certain this check is needed as remote branch created if it didn't previously exist --- .github/workflows/generate-pot-pr.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index b70fc58..f5c4dee 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -63,8 +63,7 @@ jobs: - name: Create pull request if: | - env.CHANGES_DETECTED == 1 && - env.REMOTE_BRANCH_EXISTS == 1 + env.CHANGES_DETECTED == 1 uses: repo-sync/pull-request@v2 with: source_branch: generate-pot From 3bda719c82f089f0f90fcc902d78fae3ae1b5404 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 11 Dec 2024 06:25:29 -0800 Subject: [PATCH 08/12] Update generate-pot-pr.yml Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> Signed-off-by: Andy Fragen --- .github/workflows/generate-pot-pr.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index f5c4dee..b1b537b 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -5,7 +5,6 @@ on: push: branches: - main - - master jobs: generate-pot: #---------------------------------------------------------- From f071964559fb732ed37fc99ceb8bf48764b240af Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 11 Dec 2024 06:25:56 -0800 Subject: [PATCH 09/12] Update generate-pot-pr.yml Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> Signed-off-by: Andy Fragen --- .github/workflows/generate-pot-pr.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index b1b537b..b6b78f9 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -61,8 +61,7 @@ jobs: git push origin generate-pot - name: Create pull request - if: | - env.CHANGES_DETECTED == 1 + if: env.CHANGES_DETECTED == 1 uses: repo-sync/pull-request@v2 with: source_branch: generate-pot From 13f496c10f98d3a2fcf0b5e9ed9dcabf0f78c01d Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 11 Dec 2024 07:49:58 -0800 Subject: [PATCH 10/12] Update generate-pot-pr.yml Remove comment spacer Signed-off-by: Andy Fragen --- .github/workflows/generate-pot-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index b6b78f9..04077e3 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -7,7 +7,7 @@ on: - main jobs: - generate-pot: #---------------------------------------------------------- + generate-pot: name: Generate POT PR if: github.repository == 'aspirepress/aspireupdate' permissions: From 4b83110b18d915f38a180a165c7f61596934b7b5 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Tue, 7 Jan 2025 20:07:18 -0800 Subject: [PATCH 11/12] create PR natively --- .github/workflows/generate-pot-pr.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index 04077e3..23acd12 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -62,10 +62,7 @@ jobs: - 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" + 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 }} From 8c6c2f7317d06a923523c46409e9d0a2a7b7bc3a Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Thu, 9 Jan 2025 11:00:39 -0800 Subject: [PATCH 12/12] get git user from push --- .github/workflows/generate-pot-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/generate-pot-pr.yml b/.github/workflows/generate-pot-pr.yml index 23acd12..8b5b1d4 100644 --- a/.github/workflows/generate-pot-pr.yml +++ b/.github/workflows/generate-pot-pr.yml @@ -28,8 +28,8 @@ jobs: - name: Configure git user run: | - git config --global user.email "andy@thefragens.com" - git config --global user.name "Andy Fragen" + 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