Implement publishing workflow for standalone plugins that aren't modules #34
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 plugins to WordPress.org | |
on: | |
# TODO The pull_request will be removed once the workflow is tested. | |
pull_request: | |
branches: | |
- trunk | |
- 'release/**' | |
- 'feature/**' | |
paths: | |
- '.github/workflows/deploy-standalone-plugins.yml' | |
types: | |
- opened | |
- reopened | |
- synchronize | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
slug: | |
type: string | |
description: 'The slug of the plugin to deploy' | |
dry-run: | |
type: boolean | |
description: 'Debug mode (run without publishing).' | |
default: false | |
jobs: | |
release: | |
name: Prepare Deployment | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Node.js (.nvmrc) | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
cache: npm | |
- name: Install npm dependencies | |
run: npm ci | |
- name: Get directory | |
id: get-plugin-directory | |
if: ${{ github.event_name == 'workflow_dispatch' }} | |
run: | | |
echo "directory=$(node ./bin/plugin/cli.js get-plugin-dir --slug=${{ inputs.slug }})" >> $GITHUB_OUTPUT | |
- name: Get plugin version | |
id: get-version | |
if: ${{ github.event_name == 'workflow_dispatch' }} | |
run: | | |
echo "version=$(node ./bin/plugin/cli.js get-plugin-version --slug=${{ inputs.slug }})" >> $GITHUB_OUTPUT | |
- name: Set matrix | |
id: set-matrix | |
run: | | |
if ${{ github.event_name == 'workflow_dispatch' }}; then | |
result=$(echo "${{ steps.get-version.outputs.version }}" | awk '/^(\*|[0-9]+(\.[0-9]+){0,2}(-[a-zA-Z0-9.]+)?)$/ {print "Matched"}') | |
if [[ -n "$result" ]]; then | |
# Set the manual input values in JSON format for use in the matrix. | |
echo "matrix={\"include\":[{\"slug\":\"${{ inputs.slug }}\",\"version\":\"${{ steps.get-version.outputs.version }}\",\"directory\":\"${{ steps.get-plugin-directory.outputs.directory }}\",\"dry-run\":\"true\"}]}" >> $GITHUB_OUTPUT | |
else | |
echo "The ${{ inputs.slug }} module slug is missing in the file plugins.json." | |
exit 1 | |
fi | |
else | |
# Load the JSON file and parse from "{name: {slug, version}, ...}" to "include: [{ name, slug, version }, ...]" | |
# for use in the matrix. | |
# For plugins, the "version" parameter is not included here; it will dynamically get it in its own job. | |
# The "dry-run" parameter is included here to set the deployment mode. | |
# When running the manual (workflow_dispatch) workflow, this value will be set from manual input type. | |
echo "matrix=$(jq -c '{include: ([.modules | to_entries[] | {name:.key, slug: .value.slug, version: .value.version, directory: "build", "dry-run": true}] + ([.plugins[] | {name:. , slug:. , directory: "plugins", "dry-run": true}]))}' plugins.json)" >> $GITHUB_OUTPUT | |
fi | |
deploy: | |
name: Deploy Plugin | |
needs: release | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{ fromJSON(needs.release.outputs.matrix) }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Node.js (.nvmrc) | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
cache: npm | |
- name: Install npm dependencies | |
run: npm ci | |
- name: Building standalone plugins | |
if: ${{ matrix.directory != 'plugins' }} | |
run: npm run build-plugins | |
- name: Set version | |
id: set_version | |
run: | | |
if [ -z "${{ matrix.version }}" ]; then | |
echo "version=$(node ./bin/plugin/cli.js get-plugin-version --slug=${{ matrix.slug }})" >> $GITHUB_OUTPUT | |
else | |
echo "version=${{ matrix.version }})" >> $GITHUB_OUTPUT | |
fi | |
- name: Deploy Standalone Plugin - ${{ matrix.slug }} | |
uses: 10up/action-wordpress-plugin-deploy@stable | |
with: | |
dry-run: ${{ matrix.dry-run }} | |
env: | |
# TODO Once the workflow is tested, we will remove the comment and use the secret SVN access. | |
#SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} | |
#SVN_USERNAME: ${{ secrets.SVN_USERNAME }} | |
# TODO Once the workflow is tested, we will remove this test credential. | |
SVN_PASSWORD: SVN_PASSWORD | |
SVN_USERNAME: SVN_USERNAME | |
SLUG: ${{ matrix.slug }} | |
VERSION: ${{ steps.set_version.outputs.version }} | |
BUILD_DIR: ./${{ matrix.directory }}/${{ matrix.slug }} | |
ASSETS_DIR: ./${{ matrix.directory }}/${{ matrix.slug }}/.wordpress-org |