This guide will show you how to integrate the GitHub Action into your workflow. You can automate your build and release processes with ease. This method works for public and private repositories.

Prerequisites

  • Basic knowledge of GitHub and GitHub Actions
  • A GitHub repository (public or private)
  • A WordPress plugin (or any project) to automate

Setting up GitHub Action

This action consists of two main steps:

  • Building your project and uploading the artifact
  • Creating a new version on WPLatest

The following example demonstrates how to set up a GitHub Actions workflow to automate the release process for your WordPress plugin on WPLatest. This workflow triggers on a new release event and uploads the build artifact to WPLatest. This works for both public and private repositories because we’re using the GitHub API to download the artifact.

In this example, the wplatest/action GitHub Action is pinned to the main branch. It’s good practice to pin the action to a version to avoid breaking changes (e.g. wplatest/action@1.0.0) after testing the workflow.

Ensure that your GitHub token has the necessary permissions to access the repository and perform the required actions. This is crucial for the workflow to function correctly because we use the GitHub token to get the artifact download URL. An example on setting the right permissions is provided in the permissions section.

.github/workflows/release.yml
name: Release Build

on:
release:
    types: [created]

jobs:
build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
        uses: actions/checkout@v4

    # Optional: Set up PHP
    - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
            php-version: '8.2'

    # Optional: Build your project
    - name: Install Composer dependencies
        run: composer install --no-dev --optimize-autoloader

    - name: Upload artifact
        uses: actions/upload-artifact@v4
        id: upload-artifact-zip
        with:
        name: 'plugin-zip'
        path: |
            ./
            !./composer.json
            !./.vscode
            !./.github
            !./.git
            !./phpcs.xml
            !./composer.lock
            !./README.md
            !./.sftpignore
            !./.gitignore

    - name: Get artifact details
        id: get-artifact-details
        run: |
        ARTIFACT_ID=${{ steps.upload-artifact-zip.outputs.artifact-id }}
        echo "{\"id\": \"$ARTIFACT_ID\"}" > artifact_id.json

    - name: Upload artifact ID
        uses: actions/upload-artifact@v4
        with:
        name: artifact-id
        path: artifact_id.json
        overwrite: true

wp-deploy:
    runs-on: ubuntu-latest
    needs: build
    permissions:
        contents: read
        actions: write
    steps:
    - name: Set up authorization
        env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: echo "TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV

    - name: Download artifact ID
        uses: actions/download-artifact@v4
        with:
        name: artifact-id
        path: .

    - name: Get artifact download URL
        id: get-artifact-url
        run: |
        ARTIFACT_ID=$(cat artifact_id.json | jq -r '.id')
        API_URL="https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${ARTIFACT_ID}/zip"
        LOCATION=$(curl -s -H "Authorization: token ${TOKEN}" -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" -D - "${API_URL}" | grep -i location: | awk '{print $2}' | tr -d '\r')

        if [ -z "${LOCATION}" ]; then
            echo "No location header found in response"
            exit 1
        fi

        echo "::set-output name=ARTIFACT_URL::${LOCATION}"

    - name: Create new version on WPlatest
        uses: wplatest/action@main
        id: new-version
        with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        wplatest-plugin-id: ${{ secrets.WPLATEST_PLUGIN_ID }}
        wplatest-action: create-new-version
        wplatest-artifact-zip-url: ${{ steps.get-artifact-url.outputs.ARTIFACT_URL }}
        wplatest-secret: ${{ secrets.WPLATEST_SECRET }}

Walkthrough

Ensure that you replace placeholder values such as:

  • WPLATEST_PLUGIN_ID with your WPLatest plugin ID (you can retrieve this from the “Settings” page of your plugin)
  • WPLATEST_SECRET with your WPLatest API secret

After setting up the workflow, create a new release in your repository. This triggers the workflow, which builds your project, uploads the artifact, and creates a new version on WPLatest.

Next Steps

After setting up your GitHub Actions workflow, you can further automate your release process. Check out the following resources for more advanced configurations:

WordPress plugin integration

Learn how to set up automatic updates for your private WordPress plugin.

API Reference

Check out the API reference to learn how to automate the release process and manage your plugins programmatically.

Troubleshooting

If you have any other issues or questions, please reach out to support [at] wplatest.co for assistance.