-
Notifications
You must be signed in to change notification settings - Fork 19
161 lines (143 loc) · 6.26 KB
/
Copy pathmake-pot.yml
File metadata and controls
161 lines (143 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Generate POT file
on:
workflow_dispatch:
inputs:
base:
description: 'Base branch to compare and create PR against.'
required: false
default: 'develop'
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
make-pot:
if: |
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'pull_request' &&
(
startsWith(github.head_ref, 'automatic_translations_') ||
startsWith(github.head_ref, 'tm_edits_')
)
)
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install --ignore-scripts
- name: Build plugin (dotorg dist)
run: npm run dist:dotorg
- name: Install PHP and required extensions
run: |
sudo apt-get update && sudo apt-get install -y php php-mysql php-xml php-curl
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
- name: Download wp-cli
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
- name: Download and configure WordPress
run: |
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cp -r dist/accessibility-checker wordpress/wp-content/plugins/accessibility-checker
cp wordpress/wp-config-sample.php wordpress/wp-config.php
sed -i \
-e "s/database_name_here/wordpress/" \
-e "s/username_here/root/" \
-e "s/password_here/root/" \
-e "s/'DB_HOST', 'localhost'/'DB_HOST', '127.0.0.1:3306'/" \
wordpress/wp-config.php
echo "define('FS_METHOD', 'direct');" >> wordpress/wp-config.php
- name: Wait for MySQL to be ready
run: |
for i in {1..30}; do
if mysqladmin ping -h127.0.0.1 -uroot -proot --silent; then
break
fi
sleep 2
done
- name: Install WordPress
run: |
cd wordpress
wp core install --url=localhost --title=Test --admin_user=admin --admin_password=admin --admin_email=admin@example.com --skip-email --allow-root
- name: Generate POT file
run: |
cd wordpress/wp-content/plugins/accessibility-checker
wp i18n make-pot . ./languages/accessibility-checker.pot --allow-root
- name: Check if POT file changed (ignoring some headers)
id: pot_diff
run: |
if [ -f wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot ] && [ -f dist/accessibility-checker/languages/accessibility-checker.pot ]; then
diff_output=$(diff \
<(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#|$)' wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot) \
<(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#|$)' dist/accessibility-checker/languages/accessibility-checker.pot) || true)
if [ -n "$diff_output" ]; then
echo "pot_changed=true" >> $GITHUB_OUTPUT
else
echo "pot_changed=false" >> $GITHUB_OUTPUT
fi
else
echo "pot_changed=true" >> $GITHUB_OUTPUT
fi
- name: Comment on PR if POT file changed
if: steps.pot_diff.outputs.pot_changed == 'true' && github.event.pull_request
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
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
})
- name: Upload POT file as artifact
if: steps.pot_diff.outputs.pot_changed == 'true'
uses: actions/upload-artifact@v4
with:
name: accessibility-checker-i18n
path: wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot
- name: Set up Git for PR
if: steps.pot_diff.outputs.pot_changed == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Copy updated POT file to languages folder
if: steps.pot_diff.outputs.pot_changed == 'true'
run: |
cp wordpress/wp-content/plugins/accessibility-checker/languages/accessibility-checker.pot ./languages/accessibility-checker.pot
- name: Create or Update Pull Request with updated POT file
if: steps.pot_diff.outputs.pot_changed == 'true'
uses: peter-evans/create-pull-request@v6
with:
add-paths: ./languages/accessibility-checker.pot
commit-message: Update POT translation file
title: Update POT translation file
body: This PR updates the POT translation file generated by the workflow.
branch: update-translations/${{ github.head_ref || github.ref_name }}
base: ${{ github.event.inputs.base || github.head_ref || github.ref_name }}
delete-branch: true