diff --git a/.github/workflows/make-pot.yml b/.github/workflows/make-pot.yml index 1c2f1bc79..994686562 100644 --- a/.github/workflows/make-pot.yml +++ b/.github/workflows/make-pot.yml @@ -4,40 +4,31 @@ on: workflow_dispatch: inputs: base: - description: 'Base branch to compare and create PR against.' + description: 'Base branch to build from and create the PR against. Leave empty to use the branch this was dispatched on.' required: false - default: 'develop' - pull_request: - types: - - opened - - synchronize - - reopened + +# Manual dispatch only - deliberately no push or pull_request trigger, so this +# never fires off a branch or a PR. That is also why there is no branch gating +# on the job: there is no automatic event left to filter. 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: + # Checked out at `base`, not just PR'd against it. create-pull-request + # commits onto whatever HEAD it finds, so if this built one branch and + # targeted another, every commit between the two would be swept into the + # translation PR. Empty input falls back to the dispatched branch, which + # keeps build and target the same by default. - name: Checkout code uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.base || github.ref_name }} + # The dist build runs npm and composer against this checkout, so the + # GITHUB_TOKEN is kept out of .git/config. create-pull-request does + # not need it: it configures its own http./.extraheader from + # its `token` input when it pushes. + persist-credentials: false - name: Set up Node.js uses: actions/setup-node@v4 @@ -60,57 +51,34 @@ jobs: - 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 - + # `wp i18n make-pot` is static analysis over the source tree, so it needs + # neither a database nor an installed WordPress. + - name: Set up PHP with wp-cli + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + tools: wp-cli + coverage: none + + # make-pot writes over the committed copy in dist/, which is also the + # baseline the next step diffs against, so that copy is stashed first. + # The source argument stays `.` (the plugin root): make-pot resolves its + # `#:` references against that, not against the working directory. - name: Generate POT file run: | - cd wordpress/wp-content/plugins/accessibility-checker - wp i18n make-pot . ./languages/accessibility-checker.pot --allow-root + cd dist/accessibility-checker + if [ -f languages/accessibility-checker.pot ]; then + cp languages/accessibility-checker.pot "${RUNNER_TEMP}/accessibility-checker.pot.baseline" + fi + wp i18n make-pot . languages/accessibility-checker.pot - 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 + if [ -f dist/accessibility-checker/languages/accessibility-checker.pot ] && [ -f "${RUNNER_TEMP}/accessibility-checker.pot.baseline" ]; 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) + <(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#:|$)' dist/accessibility-checker/languages/accessibility-checker.pot) \ + <(grep -vE '^("?(POT-Creation-Date|PO-Revision-Date|X-Generator|Project-Id-Version):|#:|$)' "${RUNNER_TEMP}/accessibility-checker.pot.baseline") || true) if [ -n "$diff_output" ]; then echo "pot_changed=true" >> $GITHUB_OUTPUT else @@ -120,24 +88,12 @@ jobs: 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 + path: dist/accessibility-checker/languages/accessibility-checker.pot - name: Set up Git for PR if: steps.pot_diff.outputs.pot_changed == 'true' @@ -148,7 +104,7 @@ jobs: - 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 + cp dist/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' @@ -158,6 +114,6 @@ jobs: 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 }} + branch: update-translations/${{ github.event.inputs.base || github.ref_name }} + base: ${{ github.event.inputs.base || github.ref_name }} delete-branch: true