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 obsessed.
πŸ’» WordPress Engineer.
πŸŒπŸΌβ€β™‚οΈGolfer.
🌱 Hydroponic Gardner.
🍿 Plex nerd.
πŸš™ '15 WRX & '66 Corvette C2.
🐢 Missing my love Keiki; RIP 😒.

Follow me on Twitter @TheFrosty & Instagram @TheFrosty.

Articles: 288

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: