Deploy Standalone Plugin(s) to WordPress.org #5
Workflow file for this run
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: Deploy Standalone Plugin(s) to WordPress.org | |
on: | |
release: | |
types: | |
- published | |
workflow_dispatch: | |
inputs: | |
plugin: | |
type: string | |
description: 'The slug of the plugin to deploy' | |
required: true | |
dry-run: | |
type: boolean | |
description: 'Debug mode (run without publishing).' | |
default: false | |
permissions: {} | |
jobs: | |
pre-run: | |
name: Pre-run | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.plugins }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set matrix | |
id: set-matrix | |
run: | | |
PLUGINS=$(jq -r '.plugins' plugins.json) | |
if ${{ github.event_name == 'workflow_dispatch' }}; then | |
SLUG=${{ inputs.plugin }} | |
if echo $PLUGINS | jq -e '.[] | select(. == "'$SLUG'")' > /dev/null; then | |
PLUGINS="[ \"$SLUG\" ]" | |
else | |
echo "::error::The plugin $SLUG is not in the list of plugins to deploy." | |
exit 1 | |
fi | |
fi | |
# Set the matrix. | |
echo "::notice::Deploying the following plugins: $(echo ${PLUGINS[@]})" | |
echo "plugins=$(echo $PLUGINS | jq -c .)" >> $GITHUB_OUTPUT | |
deploy: | |
name: "Deploy Plugin: ${{ matrix.plugin }}" | |
needs: pre-run | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
deployments: write | |
strategy: | |
matrix: | |
plugin: ${{ fromJSON(needs.pre-run.outputs.matrix) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node.js (.nvmrc) | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
cache: npm | |
- name: Install npm dependencies | |
run: npm ci | |
- name: Check plugin versions | |
run: npm run versions -- --plugin=${{ matrix.plugin }} | |
- name: Build plugin | |
run: npm run build:plugin:${{ matrix.plugin }} | |
- name: Set plugin version | |
working-directory: ./build | |
run: | | |
echo "PLUGIN_VERSION=$(jq -r '."${{ matrix.plugin }}"' manifest.json)" >> $GITHUB_ENV | |
- name: Check if deployment is needed | |
id: check-deployment | |
run: | | |
PLUGIN_VERSION_WPORG=$(curl -sSL https://api.wordpress.org/plugins/info/1.0/${{ matrix.plugin }}.json --retry 3 --retry-delay 5 --retry-all-errors --fail | jq -r '.version') | |
echo "::debug::The ${{ matrix.plugin }} plugin is currently at version $PLUGIN_VERSION_WPORG on WordPress.org." | |
# Bail if the plugin version is not found. | |
if [ -z "$PLUGIN_VERSION_WPORG" ]; then | |
echo "::error::Could not retrieve ${{ matrix.plugin }} information from WordPress.org. The plugin may not exist or the API may be down." | |
exit 1 | |
fi | |
# Bail if the plugin is already up to date. | |
if [ "$PLUGIN_VERSION_WPORG" = "$PLUGIN_VERSION" ]; then | |
echo "::notice::The ${{ matrix.plugin }} plugin is already up to date on WordPress.org. Halting deployment." | |
exit 0 | |
fi | |
echo "deploy=true" >> $GITHUB_OUTPUT | |
- name: Create zip file | |
if: steps.check-deployment.outputs.deploy == 'true' | |
run: | | |
mkdir -p ./build/dist | |
cd ./build/${{ matrix.plugin }} | |
zip -r ../dist/${{ matrix.plugin }}.zip . | |
- name: Generate checksum | |
if: steps.check-deployment.outputs.deploy == 'true' | |
working-directory: ./build/dist | |
run: | | |
mkdir -p $RUNNER_TEMP/plugin-checksums | |
find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/plugin-checksums/checksums.txt | |
shasum -a 256 -U -c $RUNNER_TEMP/plugin-checksums/checksums.txt | |
cat $RUNNER_TEMP/plugin-checksums/checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done | |
- name: Upload artifact | |
if: steps.check-deployment.outputs.deploy == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.plugin }} | |
path: ./build/dist | |
- name: Start deployment | |
if: steps.check-deployment.outputs.deploy == 'true' | |
uses: bobheadxi/deployments@v1 | |
id: wporg-deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: "wp.org plugin: ${{ matrix.plugin }}" | |
- name: Deploy Plugin - ${{ matrix.plugin }} | |
if: steps.check-deployment.outputs.deploy == 'true' | |
uses: 10up/action-wordpress-plugin-deploy@stable | |
with: | |
dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run || false }} | |
env: | |
SLUG: ${{ matrix.plugin }} | |
VERSION: ${{ env.PLUGIN_VERSION }} | |
SVN_USERNAME: ${{ secrets.SVN_USERNAME }} | |
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} | |
BUILD_DIR: ./build/${{ matrix.plugin }} | |
ASSETS_DIR: ./plugins/${{ matrix.plugin }}/.wordpress-org | |
- name: Finish deployment | |
if: ${{ steps.wporg-deployment.outputs.deployment_id && always() }} | |
uses: bobheadxi/deployments@v1 | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
deployment_id: ${{ steps.wporg-deployment.outputs.deployment_id }} | |
env: "wp.org plugin: ${{ matrix.plugin }}" | |
env_url: "https://wordpress.org/plugins/${{ matrix.plugin }}/" | |
release-assets: | |
name: Add release assets | |
needs: [ pre-run, deploy ] | |
runs-on: ubuntu-latest | |
permissions: | |
actions: read | |
contents: write | |
if: github.event_name == 'release' | |
strategy: | |
matrix: | |
plugin: ${{ fromJSON(needs.pre-run.outputs.matrix) }} | |
steps: | |
- name: Check artifact existence | |
id: artifact-existence | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const getArtifact = await github.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts{?name}', { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.runId, | |
name: "${{ matrix.plugin }}" | |
}); | |
if (getArtifact.status !== 200) { | |
throw new Error(`Invalid response from GitHub API: ${getArtifact.status}`); | |
} | |
core.setOutput('exists', getArtifact.data.artifacts.length > 0); | |
core.debug(`Artifact for ${{ matrix.plugin }} exists: ${core.getInput('exists')} ? "true" : "false"`); | |
- name: Download artifact | |
if: steps.artifact-existence.outputs.exists == 'true' | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ matrix.plugin }} | |
path: ./build/dist | |
- name: Upload release assets | |
if: steps.artifact-existence.outputs.exists == 'true' | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
./build/dist/${{ matrix.plugin }}.zip | |
./build/dist/${{ matrix.plugin }}.zip.sha256 |