-
Notifications
You must be signed in to change notification settings - Fork 4
97 lines (86 loc) · 3.08 KB
/
update-wp-versions.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
name: Update WordPress versions
on:
schedule:
- cron: '0 9 * * *'
workflow_dispatch:
env:
MAGIC_BRANCH_NAME: auto-update/wordpress-versions
permissions:
contents: read
jobs:
preflight:
name: Preflight check
runs-on: ubuntu-latest
outputs:
branch-exists: ${{ steps.check-branch.outputs.exists }}
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Check if 'update/wordpress-versions' branch exists
id: check-branch
run: |
if git ls-remote --exit-code --heads origin ${MAGIC_BRANCH_NAME}; then
echo "exists=true" >> $GITHUB_OUTPUT
echo ::warning::"Branch '${MAGIC_BRANCH_NAME}' already exists, exiting."
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
update:
name: Update WordPress versions
runs-on: ubuntu-latest
needs: preflight
if: ${{ needs.preflight.outputs.branch-exists == 'false' }}
permissions:
contents: write
pull-requests: write
steps:
- name: Check out source code
uses: actions/checkout@v4
with:
token: ${{ secrets.WPCOM_VIP_BOT_TOKEN }}
- name: Install dependencies
run: |
sudo apt-get -qq update
sudo apt-get install -y moreutils
- name: Get WordPress versions we want
id: wanted
run: |
LATEST=$(wget https://api.wordpress.org/core/version-check/1.7/ -q -O - | jq -r '[.offers[].version] | unique | map(select( . >= "6.0")) | sort | reverse | .[]')
echo latest=${LATEST} >> $GITHUB_OUTPUT
TAGS=
for v in ${LATEST}; do
TAGS="${TAGS} $(echo ${v} | awk -F. '{print $1"."$2}')"
done
TAGS=${TAGS# }
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- name: Remove old WordPress versions from versions.json
run: |
for tag in ${TAGS}; do
./del-version.sh "${tag}"
done
env:
TAGS: ${{ steps.wanted.outputs.tags }}
working-directory: wordpress
- name: Add new WordPress versions to versions.json
run: |
for version in ${LATEST}; do
tag=$(echo ${version} | awk -F. '{print $1"."$2}')
./add-version.sh "${tag}" "${version}" true true
done
env:
LATEST: ${{ steps.wanted.outputs.latest }}
working-directory: wordpress
- name: Commit the changes and create a PR
run: |
if [ "$(git diff --ignore-space-at-eol wordpress/ | wc -l)" -gt "0" ]; then
git checkout -b ${MAGIC_BRANCH_NAME}
git config user.name "WordPress VIP Bot"
git config user.email [email protected]
git add wordpress
git commit -m "Add WordPress ${LATEST}."
git push -u origin "${MAGIC_BRANCH_NAME}"
gh pr create --base master --head "${MAGIC_BRANCH_NAME}" --title "Update versions.json" --body "Add WordPress ${LATEST}."
fi
env:
LATEST: ${{ steps.wanted.outputs.latest }}
GH_TOKEN: ${{ secrets.WPCOM_VIP_BOT_TOKEN }}