GitHub Actions: Get the latest WordPress version in a step

In a GitHub Action workflow, grab the latest WordPress version in a step and set it as an environment variable.

Over the past year, I have been slowly migrating my personal packages and plugins from Travis CI to GitHub Actions. This was due to Travis removing their forever free tier.

Many of my open source WordPress plugins previously ran their CI pipelines through Travis. But after that news, and the fact my pipelines were dead, had me on the move to update the popular ones to GitHub Actions.

Fast forward, and I previously was working on a couple Actions that required building a complete project. One requirement was to grab the current or latest version of WordPress. Below is the “step”.

Get the latest WordPress version

    steps:
      - name: Set WordPress version
        id: set-wordpress-version
        run: |
          echo 'WORDPRESS_VERSION<<EOF' >> $GITHUB_ENV
          curl -s "https://api.wordpress.org/core/version-check/1.7/" | jq -r '[.offers[]|select(.response=="upgrade")][0].version' >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV

      - name: Get WordPress version
        run: |
          echo "WordPress version: ${{ env.WORDPRESS_VERSION }}"

While two steps aren’t required, you can’t access the new global environment variable from within the step that creates it. This can be seen in their docs here.

In any future step you can now access the global environment variable ${{ env.WORDPRESS_VERSION }} to the current WordPress version. Of course, if you are familiar with JQ, you could modify the curl part and grab different versions. To do that, check out the JQ play site.

Austin
Austin

πŸ’πŸ½β€β™‚οΈ Husband to Jeana.
⚾️ Dodgers & Brewers.
πŸ’» PHP Engineer.
πŸŒπŸΌβ€β™‚οΈGolfer; ~13 HDC.
🌱 Hydroponic Gardner.
🍿 Plex nerd.
πŸš™ '15 WRX, '22 Model 3 LR, & '66 Corvette C2.

Follow me on Twitter @TheFrosty & Instagram @TheFrosty.

Articles: 293