Skip to content

Commit cc72684

Browse files
authored
Merge pull request #1846 from equalizedigital/make-pot-no-wordpress-any-base
Run make-pot on manual dispatch only, and drop the WordPress+MySQL scaffolding
2 parents 473bd77 + 58296b3 commit cc72684

1 file changed

Lines changed: 42 additions & 86 deletions

File tree

.github/workflows/make-pot.yml

Lines changed: 42 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,31 @@ on:
44
workflow_dispatch:
55
inputs:
66
base:
7-
description: 'Base branch to compare and create PR against.'
7+
description: 'Base branch to build from and create the PR against. Leave empty to use the branch this was dispatched on.'
88
required: false
9-
default: 'develop'
10-
pull_request:
11-
types:
12-
- opened
13-
- synchronize
14-
- reopened
9+
10+
# Manual dispatch only - deliberately no push or pull_request trigger, so this
11+
# never fires off a branch or a PR. That is also why there is no branch gating
12+
# on the job: there is no automatic event left to filter.
1513

1614
jobs:
1715
make-pot:
18-
if: |
19-
github.event_name == 'workflow_dispatch' ||
20-
(
21-
github.event_name == 'pull_request' &&
22-
(
23-
startsWith(github.head_ref, 'automatic_translations_') ||
24-
startsWith(github.head_ref, 'tm_edits_')
25-
)
26-
)
2716
runs-on: ubuntu-latest
28-
services:
29-
mysql:
30-
image: mysql:5.7
31-
env:
32-
MYSQL_ROOT_PASSWORD: root
33-
MYSQL_DATABASE: wordpress
34-
ports:
35-
- 3306:3306
36-
options: >-
37-
--health-cmd="mysqladmin ping --silent" --health-interval=10s --health-timeout=5s --health-retries=3
3817
steps:
18+
# Checked out at `base`, not just PR'd against it. create-pull-request
19+
# commits onto whatever HEAD it finds, so if this built one branch and
20+
# targeted another, every commit between the two would be swept into the
21+
# translation PR. Empty input falls back to the dispatched branch, which
22+
# keeps build and target the same by default.
3923
- name: Checkout code
4024
uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.event.inputs.base || github.ref_name }}
27+
# The dist build runs npm and composer against this checkout, so the
28+
# GITHUB_TOKEN is kept out of .git/config. create-pull-request does
29+
# not need it: it configures its own http.<host>/.extraheader from
30+
# its `token` input when it pushes.
31+
persist-credentials: false
4132

4233
- name: Set up Node.js
4334
uses: actions/setup-node@v4
@@ -60,57 +51,34 @@ jobs:
6051
- name: Build plugin (dotorg dist)
6152
run: npm run dist:dotorg
6253

63-
- name: Install PHP and required extensions
64-
run: |
65-
sudo apt-get update && sudo apt-get install -y php php-mysql php-xml php-curl
66-
echo "xdebug.max_nesting_level=1024" | sudo tee -a /etc/php/$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')/cli/conf.d/20-xdebug.ini
67-
68-
- name: Download wp-cli
69-
run: |
70-
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
71-
chmod +x wp-cli.phar
72-
sudo mv wp-cli.phar /usr/local/bin/wp
73-
74-
- name: Download and configure WordPress
75-
run: |
76-
curl -O https://wordpress.org/latest.tar.gz
77-
tar -xzf latest.tar.gz
78-
cp -r dist/accessibility-checker wordpress/wp-content/plugins/accessibility-checker
79-
cp wordpress/wp-config-sample.php wordpress/wp-config.php
80-
sed -i \
81-
-e "s/database_name_here/wordpress/" \
82-
-e "s/username_here/root/" \
83-
-e "s/password_here/root/" \
84-
-e "s/'DB_HOST', 'localhost'/'DB_HOST', '127.0.0.1:3306'/" \
85-
wordpress/wp-config.php
86-
echo "define('FS_METHOD', 'direct');" >> wordpress/wp-config.php
87-
88-
- name: Wait for MySQL to be ready
89-
run: |
90-
for i in {1..30}; do
91-
if mysqladmin ping -h127.0.0.1 -uroot -proot --silent; then
92-
break
93-
fi
94-
sleep 2
95-
done
96-
97-
- name: Install WordPress
98-
run: |
99-
cd wordpress
100-
wp core install --url=localhost --title=Test --admin_user=admin --admin_password=admin --admin_email=admin@example.com --skip-email --allow-root
101-
54+
# `wp i18n make-pot` is static analysis over the source tree, so it needs
55+
# neither a database nor an installed WordPress.
56+
- name: Set up PHP with wp-cli
57+
uses: shivammathur/setup-php@v2
58+
with:
59+
php-version: '8.2'
60+
tools: wp-cli
61+
coverage: none
62+
63+
# make-pot writes over the committed copy in dist/, which is also the
64+
# baseline the next step diffs against, so that copy is stashed first.
65+
# The source argument stays `.` (the plugin root): make-pot resolves its
66+
# `#:` references against that, not against the working directory.
10267
- name: Generate POT file
10368
run: |
104-
cd wordpress/wp-content/plugins/accessibility-checker
105-
wp i18n make-pot . ./languages/accessibility-checker.pot --allow-root
69+
cd dist/accessibility-checker
70+
if [ -f languages/accessibility-checker.pot ]; then
71+
cp languages/accessibility-checker.pot "${RUNNER_TEMP}/accessibility-checker.pot.baseline"
72+
fi
73+
wp i18n make-pot . languages/accessibility-checker.pot
10674
10775
- name: Check if POT file changed (ignoring some headers)
10876
id: pot_diff
10977
run: |
110-
if [ -f wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot ] && [ -f dist/accessibility-checker/languages/accessibility-checker.pot ]; then
78+
if [ -f dist/accessibility-checker/languages/accessibility-checker.pot ] && [ -f "${RUNNER_TEMP}/accessibility-checker.pot.baseline" ]; then
11179
diff_output=$(diff \
112-
<(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#|$)' wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot) \
113-
<(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#|$)' dist/accessibility-checker/languages/accessibility-checker.pot) || true)
80+
<(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#:|$)' dist/accessibility-checker/languages/accessibility-checker.pot) \
81+
<(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#:|$)' "${RUNNER_TEMP}/accessibility-checker.pot.baseline") || true)
11482
if [ -n "$diff_output" ]; then
11583
echo "pot_changed=true" >> $GITHUB_OUTPUT
11684
else
@@ -120,24 +88,12 @@ jobs:
12088
echo "pot_changed=true" >> $GITHUB_OUTPUT
12189
fi
12290
123-
- name: Comment on PR if POT file changed
124-
if: steps.pot_diff.outputs.pot_changed == 'true' && github.event.pull_request
125-
uses: actions/github-script@v7
126-
with:
127-
script: |
128-
github.rest.issues.createComment({
129-
issue_number: context.issue.number,
130-
owner: context.repo.owner,
131-
repo: context.repo.repo,
132-
body: 'The POT translation file has changed. Please update the POT file in your PR to keep translations up to date.\nThe updated file is available in the artifacts of this workflow run: https://github.com/' + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + process.env.GITHUB_RUN_ID
133-
})
134-
13591
- name: Upload POT file as artifact
13692
if: steps.pot_diff.outputs.pot_changed == 'true'
13793
uses: actions/upload-artifact@v4
13894
with:
13995
name: accessibility-checker-i18n
140-
path: wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot
96+
path: dist/accessibility-checker/languages/accessibility-checker.pot
14197

14298
- name: Set up Git for PR
14399
if: steps.pot_diff.outputs.pot_changed == 'true'
@@ -148,7 +104,7 @@ jobs:
148104
- name: Copy updated POT file to languages folder
149105
if: steps.pot_diff.outputs.pot_changed == 'true'
150106
run: |
151-
cp wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot ./languages/accessibility-checker.pot
107+
cp dist/accessibility-checker/languages/accessibility-checker.pot ./languages/accessibility-checker.pot
152108
153109
- name: Create or Update Pull Request with updated POT file
154110
if: steps.pot_diff.outputs.pot_changed == 'true'
@@ -158,6 +114,6 @@ jobs:
158114
commit-message: Update POT translation file
159115
title: Update POT translation file
160116
body: This PR updates the POT translation file generated by the workflow.
161-
branch: update-translations/${{ github.head_ref || github.ref_name }}
162-
base: ${{ github.event.inputs.base || github.head_ref || github.ref_name }}
117+
branch: update-translations/${{ github.event.inputs.base || github.ref_name }}
118+
base: ${{ github.event.inputs.base || github.ref_name }}
163119
delete-branch: true

0 commit comments

Comments
 (0)