-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (106 loc) · 3.84 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
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 trunk branch
uses: actions/checkout@v4
with:
ref: trunk
fetch-depth: 0
- name: Download WordPress build files from 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 trunk/readme.html || ! cmp -s downloads/wp-config-sample.php trunk/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 trunk branch
uses: actions/checkout@v4
with:
ref: trunk
fetch-depth: 0
- name: Get workspace files from artifact
uses: actions/download-artifact@v4
id: download-artifact
with:
name: workspace-files
path: trunk
- name: Commit updated source files
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Update local files with remote changes from 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:trunk")
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="Este pull request automático submete alterações do branch 'trunk' 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\":\"trunk\",\"base\":\"$BRANCH\"}" $URL)
echo $RESPONSE
- name: Steps debug info
run: |
echo "Steps: ${{ toJson(steps) }}"