Update WordPress i18n build files #7
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 }} | |
TOKEN: ${{ secrets.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: Download WordPress build files from the repository branch 'trunk' | |
id: download-files | |
run: | | |
mkdir downloads | |
curl -o downloads/readme.html https://raw.githubusercontent.com/WordPress/wordpress-develop/trunk/src/readme.html | |
curl -o downloads/wp-config-sample.php https://raw.githubusercontent.com/WordPress/wordpress-develop/trunk/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: Check if Pull Request exists | |
id: check_pr | |
run: | | |
BRANCH=main | |
RESPONSE=$(curl -X GET -H "Authorization: token $TOKEN" "https://api.github.com/repos/$REPO/pulls?head=$OWNER:english") | |
PR_NUMBER=$(echo "$RESPONSE" | jq -r '.[].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 new Pull Request | |
id: create_pr | |
if: steps.check_pr.outputs.pr_number == '' | |
run: | | |
BRANCH=main | |
TITLE="Actualizar ficheiros originais em inglês" | |
BODY="Actualização automática para submeter alterações do branch 'english' para o 'main'." | |
URL="https://api.github.com/repos/$REPO/pulls" | |
RESPONSE=$(curl -X POST -H "Authorization: token $TOKEN" -d "{\"title\":\"$TITLE\",\"body\":\"$BODY\",\"head\":\"english\",\"base\":\"$BRANCH\"}" $URL) | |
echo $RESPONSE | |
- name: Steps debug info | |
run: | | |
echo "Steps: ${{ toJson(steps) }}" |