Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin(s) build setup for distribution #1033

Merged
merged 35 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
981dc73
Remove .gitattributes
thelovekesh Mar 6, 2024
8e50a25
Add .distignore
thelovekesh Mar 6, 2024
33f405d
Add copy-webpack-plugin
thelovekesh Mar 6, 2024
c092893
Add webpackbar
thelovekesh Mar 6, 2024
a186414
Add misc files to .distignore
thelovekesh Mar 6, 2024
263fc19
Remove plugins directory
thelovekesh Mar 6, 2024
c10198b
Add webpack config for plugins dist bundling
thelovekesh Mar 6, 2024
79fbbfe
Update plugin build command(s)
thelovekesh Mar 6, 2024
cbc54dc
Remove CLI based plugin building
thelovekesh Mar 6, 2024
6c3d3c7
Update perflab with performance-lab
thelovekesh Mar 6, 2024
7e92669
Update performance-lab deployment workflow
thelovekesh Mar 6, 2024
2bfbe7c
Update standalone plugins deployment workflow
thelovekesh Mar 6, 2024
61f601e
Add npm-run-all
thelovekesh Mar 6, 2024
234df60
Run npm audit fix
thelovekesh Mar 6, 2024
84a85db
Fix workflow steps in standlaone plugins deploy workflow
thelovekesh Mar 6, 2024
52a60cc
Add utils for webpack config
thelovekesh Mar 7, 2024
f7aa3cf
Add step to generate build manifest
thelovekesh Mar 7, 2024
b40c338
Fix manifest creation error if build dir is not found
thelovekesh Mar 7, 2024
583a07d
Update deploy workflow to handle all uses cases with single workflow
thelovekesh Mar 7, 2024
0416f3d
Add debug steps
thelovekesh Mar 7, 2024
19d29c6
Add build dir deletion and manifest generation on appropriate hooks
thelovekesh Mar 7, 2024
c08ed0f
Remove redundant error handling
thelovekesh Mar 7, 2024
0a5310d
Remove get-plugin-version and get-plugin-dir command
thelovekesh Mar 7, 2024
a7371d8
Add deployments step in the release workflow
thelovekesh Mar 7, 2024
4aa56af
Fix status in deployments step in the release worflow
thelovekesh Mar 7, 2024
d5dc998
Update deployment status name
thelovekesh Mar 7, 2024
be8c207
Move deploy.yml to deploy-standalone-plugins.yml
thelovekesh Mar 7, 2024
8f22f4a
Revert deploy-dotorg.yml workflow
thelovekesh Mar 7, 2024
6a5173e
Add empty line in EOF
thelovekesh Mar 7, 2024
3dfa114
Remove build step for PL plugin
thelovekesh Mar 8, 2024
eeb26db
Remove .distignore
thelovekesh Mar 8, 2024
e03fca0
Revert "Remove .gitattributes"
thelovekesh Mar 8, 2024
d471080
Add build-cs and webpack config
thelovekesh Mar 8, 2024
bb98c66
Update build command
thelovekesh Mar 8, 2024
0d5451d
Update standalone plugins workflow to only deploy if not deployed alr…
thelovekesh Mar 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/tests export-ignore
/plugin-tests export-ignore
/plugins export-ignore
/build-cs export-ignore
thelovekesh marked this conversation as resolved.
Show resolved Hide resolved

/*.DS_store export-ignore
/.DS_store? export-ignore
Expand All @@ -26,6 +27,7 @@ phpcs.xml.dist export-ignore
/phpcs.ruleset.xml export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/webpack.config.js export-ignore

/CONTRIBUTING.md export-ignore
/SECURITY.md export-ignore
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/deploy-dotorg.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Deploy to WordPress.org

on:
Expand All @@ -7,17 +8,19 @@ on:

jobs:
release:
name: New Release
name: Release Performance Lab Plugin
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: WordPress plugin deploy
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: performance-lab

- name: Upload release assets
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
Expand Down
222 changes: 162 additions & 60 deletions .github/workflows/deploy-standalone-plugins.yml
Original file line number Diff line number Diff line change
@@ -1,99 +1,201 @@
name: Deploy standalone plugins to WordPress.org
---
name: Deploy Standalone Plugin(s) to WordPress.org

on:
release:
types: [published]
types:
- published
workflow_dispatch:
inputs:
slug:
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:
release:
name: Prepare Deployment
pre-run:
name: Pre-run
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
matrix: ${{ steps.set-matrix.outputs.plugins }}
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
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
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: 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
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\":\"${{ inputs.dry-run }}\"}]}" >> $GITHUB_OUTPUT
SLUG=${{ inputs.plugin }}
thelovekesh marked this conversation as resolved.
Show resolved Hide resolved
if echo $PLUGINS | jq -e '.[] | select(. == "'$SLUG'")' > /dev/null; then
PLUGINS="[ \"$SLUG\" ]"
else
echo "The ${{ inputs.slug }} module slug is missing in the file plugins.json."
echo "::error::The plugin $SLUG is not in the list of plugins to deploy."
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": false}] + ([.plugins[] | {name:. , slug:. , directory: "plugins", "dry-run": false}]))}' plugins.json)" >> $GITHUB_OUTPUT
fi

# Set the matrix.
echo "::notice::Deploying the following plugins: $(echo ${PLUGINS[@]})"
echo "plugins=$(echo $PLUGINS | jq -c .)" >> $GITHUB_OUTPUT

deploy:
name: Deploy Plugin
needs: release
name: "Deploy Plugin: ${{ matrix.plugin }}"
needs: pre-run
runs-on: ubuntu-latest
permissions:
actions: write
deployments: write
strategy:
matrix: ${{ fromJSON(needs.release.outputs.matrix) }}
matrix:
plugin: ${{ fromJSON(needs.pre-run.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v3
uses: actions/setup-node@v4
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
felixarntz marked this conversation as resolved.
Show resolved Hide resolved

- 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

swissspidy marked this conversation as resolved.
Show resolved Hide resolved
- name: Check if deployment is needed
id: check-deployment
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
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
- name: Deploy Standalone Plugin - ${{ matrix.slug }}

# 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
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
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: ${{ matrix.dry-run }}
dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run || false }}
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SLUG: ${{ matrix.plugin }}
VERSION: ${{ env.PLUGIN_VERSION }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: ${{ matrix.slug }}
VERSION: ${{ steps.set_version.outputs.version }}
BUILD_DIR: ./${{ matrix.directory }}/${{ matrix.slug }}
thelovekesh marked this conversation as resolved.
Show resolved Hide resolved
ASSETS_DIR: ./${{ matrix.directory }}/${{ matrix.slug }}/.wordpress-org
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
33 changes: 0 additions & 33 deletions bin/plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,10 @@ const {
handler: translationsHandler,
options: translationsOptions,
} = require( './commands/translations' );
const {
handler: buildPluginsHandler,
options: buildPluginsOptions,
} = require( './commands/build-plugins' );
const {
handler: testPluginsHandler,
options: testPluginsOptions,
} = require( './commands/test-plugins' );
const {
handler: getPluginVersionHandler,
options: getPluginVersionOptions,
} = require( './commands/get-plugin-version' );
const {
handler: getPluginDirHandler,
options: getPluginDirOptions,
} = require( './commands/get-plugin-dir' );
const {
handler: enabledModulesHandler,
options: enabledModulesOptions,
Expand Down Expand Up @@ -85,32 +73,11 @@ withOptions( program.command( 'module-translations' ), translationsOptions )
)
.action( catchException( translationsHandler ) );

withOptions(
program.command( 'build-standalone-plugins' ),
buildPluginsOptions
)
.alias( 'build-plugins' )
.description( 'Build standalone plugins' )
.action( catchException( buildPluginsHandler ) );

withOptions( program.command( 'test-standalone-plugins' ), testPluginsOptions )
.alias( 'test-plugins' )
.description( 'Test standalone plugins' )
.action( catchException( testPluginsHandler ) );

withOptions(
program.command( 'get-standalone-plugin-version' ),
getPluginVersionOptions
)
.alias( 'get-plugin-version' )
.description( 'Get standalone plugin version' )
.action( catchException( getPluginVersionHandler ) );

withOptions( program.command( 'get-plugin-dir' ), getPluginDirOptions )
.alias( 'get-plugin-directory' )
.description( 'Get plugin directory' )
.action( catchException( getPluginDirHandler ) );

withOptions(
program.command( 'default-enabled-modules' ),
enabledModulesOptions
Expand Down
Loading
Loading