-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (109 loc) · 3.73 KB
/
update-build-files.yml
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
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) }}"