Update WordPress versions #770
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 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 }} |