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