Update WordPress i18n build files #205
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update WordPress i18n build files | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Runs every day at midnight. | |
# Allows you to run this workflow manually from the Actions tab. | |
workflow_dispatch: | |
env: | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.repository }} | |
GH_TOKEN: "${{ github.token }}" | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
check-file-updates: | |
name: Check for file updates | |
runs-on: ubuntu-latest | |
outputs: | |
files_changed: ${{ steps.compare-files.outputs.files_changed }} | |
steps: | |
- name: Checkout english branch | |
uses: actions/checkout@v4 | |
with: | |
ref: english | |
fetch-depth: 0 | |
- name: Checkout WordPress/wordpress-develop | |
uses: actions/checkout@v4 | |
with: | |
repository: WordPress/wordpress-develop | |
fetch-depth: 1 | |
path: wordpress-develop | |
- name: Copy WordPress build files | |
run: | | |
mkdir downloads | |
cp --force wordpress-develop/src/readme.html downloads/readme.html | |
cp --force wordpress-develop/wp-config-sample.php downloads/wp-config-sample.php | |
- name: Check if source files have changed | |
id: compare-files | |
run: | | |
if ! cmp -s downloads/readme.html en_US/readme.html || ! cmp -s downloads/wp-config-sample.php en_US/wp-config-sample.php; then | |
echo "The build files have been updated!" | |
echo "files_changed=true" >> $GITHUB_OUTPUT | |
else | |
echo "The build files remain unchanged." | |
echo "files_changed=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Save workspace files to artifact | |
uses: actions/upload-artifact@v4 | |
id: upload-artifact | |
if: steps.compare-files.outputs.files_changed == 'true' | |
with: | |
name: workspace-files | |
path: downloads/ | |
- name: Steps debug info | |
run: | | |
echo "Steps: ${{ toJson(steps) }}" | |
commit-updated-files: | |
name: Commit updated files | |
runs-on: ubuntu-latest | |
needs: check-file-updates | |
if: ${{ needs.check-file-updates.outputs.files_changed == 'true' }} | |
steps: | |
- name: Checkout english branch | |
uses: actions/checkout@v4 | |
with: | |
ref: english | |
fetch-depth: 0 | |
- name: Get workspace files from artifact | |
uses: actions/download-artifact@v4 | |
id: download-artifact | |
with: | |
name: workspace-files | |
path: en_US | |
- name: Commit updated source files | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: Update english files according to remote changes in WordPress 'trunk' | |
- name: Steps debug info | |
run: | | |
echo "Steps: ${{ toJson(steps) }}" | |
create-pull-request: | |
name: Create Pull Request | |
runs-on: ubuntu-latest | |
needs: commit-updated-files | |
if: ${{ needs.commit-updated-files.result == 'success' }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Check if Pull Request exists | |
id: check_pr | |
run: | | |
PR_NUMBER="$(gh pr list --head "${OWNER}:english" --json "number" --jq '.[0]."number"')" | |
if [ -n "$PR_NUMBER" ]; then | |
echo "PR number found: $PR_NUMBER" | |
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
else | |
echo "No pull request found." | |
fi | |
- name: Create Pull Request | |
id: create_pr | |
if: steps.check_pr.outputs.pr_number == '' | |
env: | |
TITLE: "Actualizar ficheiros originais em inglês" | |
BODY: "Actualização automática para submeter alterações do branch 'english' para o 'main'." | |
run: | | |
gh pr create --title "${TITLE}" --body "${BODY}" --head "english" --base "main" | |
- name: Steps debug info | |
run: | | |
echo "Steps: ${{ toJson(steps) }}" |