Skip to content

Commit

Permalink
Create PR via workflow when ClassicPress is released (#38)
Browse files Browse the repository at this point in the history
* Create workflow to automatically create a PR when a new version of ClassicPress is released

* Add WordPress release check and improvements to ClassicPress release checks

* Run these actions at 1am, after build process completes on nightly

* Make searches and substitutions more precise

Co-authored-by: mattyrob <mattyrobuk@gmail.com>
  • Loading branch information
nylen and mattyrob committed Feb 3, 2022
1 parent 7ebdda9 commit bd5b247
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/classicpress-release.yml
@@ -0,0 +1,60 @@
name: Check for ClassicPress release

on:
pull_request:
schedule:
- cron: '0 1 * * *'

jobs:
release-check:
runs-on: ubuntu-latest
steps:
- name: Check release repository
run: |
echo "Collect and process json"
RELEASE_URL=$(wget -cq "https://api.github.com/repos/ClassyBot/ClassicPress-nightly/releases?per_page=3" -O - | jq -r '.[].html_url' | grep '%2Bnightly\.' | head -n1)
CURRENT_VERSION=$(echo "${RELEASE_URL}" | sed 's#.*/##; s#%2B.*##')
RELEASE_DATE=$(echo "${RELEASE_URL: -8}")
if [ -z "$CURRENT_VERSION" ] || [ -z "$RELEASE_DATE" ]; then
echo "Determining release info FAILED!"
exit 1
fi
if [[ "$CURRENT_VERSION" = *-* ]]; then
echo "Latest nightly version is beta/RC/etc: $CURRENT_VERSION"
echo "Not proceeding!"
echo "proceed=false" >> $GITHUB_ENV
else
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_ENV
echo "release_date=${RELEASE_DATE}" >> $GITHUB_ENV
echo "proceed=true" >> $GITHUB_ENV
fi
- name: Checkout repository
uses: actions/checkout@v2
if: ${{ env.proceed == 'true' }}

- name: Compare to Repository
if: ${{ env.proceed == 'true' }}
run: |
API_VERSION=$(grep '^\$build_version =' v1/migration/index.php | cut -d\' -f2)
if [ "${{ env.current_version }}" != "${API_VERSION}" ]; then
sed -ri "s#^\\\$build_version =.*\$#\$build_version = '${{ env.current_version }}';#" v1/migration/index.php
sed -ri "s#^\\\$build_date =.*\$#\$build_date = '${{ env.release_date }}';#" v1/migration/index.php
fi
- name: Create Pull Request
id: createpr
uses: peter-evans/create-pull-request@v3
if: ${{ env.proceed == 'true' }}
with:
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
base: master
branch: release/${{ env.current_version }}
commit-message: Update API for ClassicPress ${{ env.current_version }} release
title: Update API for ClassicPress ${{ env.current_version }} release
body: |
Update API endpoint for migration
- Update release version to ${{ env.current_version }}
- Update release date to ${{ env.release_date }}
See also https://github.com/ClassicPress/ClassicPress-APIs/pull/38.
38 changes: 38 additions & 0 deletions .github/workflows/wordpress-release.yml
@@ -0,0 +1,38 @@
name: Check for WordPress release

on:
schedule:
- cron: '0 1 * * *'

jobs:
release-check:
runs-on: ubuntu-latest
steps:
- name: Check release repository
run: |
echo "Collect and process json"
RELEASE_DATA=$(wget -cq "https://api.wordpress.org/core/version-check/1.7/" -O - | jq --compact-output '.[] | limit( 1; .[] ) | {current}')
CURRENT_VERSION=$(echo "${RELEASE_DATA}" | grep -Eo -m1 '[[:digit:]]\.[[:digit:]]\.[[:digit:]]')
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
- name: Compare to Repository
run: |
MAX_WP_VERSION=$(grep -Eo -m1 "'max'\s*=>\s'([[:digit:]]\.[[:digit:]]\.[[:digit:]]*)'" ./v1/migration/index.php)
WP_VERSION=$(echo "${MAX_WP_VERSION}" | grep -Eo -m1 '[[:digit:]]\.[[:digit:]]\.[[:digit:]]')
if [ ${{ env.current_version }} != ${WP_VERSION} ]; then
sed "s|${WP_VERSION}|${{ env.current_version }}|" ./v1/migration/index.php
fi
- name: Create Pull Request
id: createpr
uses: peter-evans/create-pull-request@v3
with:
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
branch: release/${{ env.current_version }}
commit-message: Update API for new WordPressPress Release
title: Update API for ${{ env.current_version }} release
body: |
Update API Endpoint
- Update endpoint to release ${{ env.current_version }}
- Update release date to ${{ env.release_date }}

0 comments on commit bd5b247

Please sign in to comment.