Files
thatguygriff e9d6c189bc
CI / Coding Standards (pull_request) Successful in 52s
CI / PHPStan (pull_request) Successful in 1m1s
CI / Tests (PHP 8.1) (pull_request) Successful in 52s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 47s
CI / No Debug Code (pull_request) Successful in 3s
CI / Build Plugin Zip (pull_request) Has been skipped
Add plugin zip build task and CI release artifact
- bin/build-zip.sh + `composer build`: stage runtime files only, generate a
  production (no-dev) optimized autoloader, and emit
  dist/<slug>-<version>.zip with a single top-level plugin folder, ready to
  upload via wp-admin. Tests, tooling configs, docs, and dev dependencies
  are excluded; version is read from the plugin header.
- CI `build` job: on push to main (post-merge), after lint/static-analysis/
  test/no-debug pass, runs the build and uploads the zip via
  actions/upload-artifact.
- Ignore build/ and dist/.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 11:44:53 -03:00

61 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Build a distributable WordPress plugin zip.
#
# Produces dist/<slug>-<version>.zip containing a single top-level <slug>/
# folder, ready to upload via wp-admin → Plugins → Add New → Upload Plugin.
#
# The package ships only runtime files plus an optimised, production
# (no-dev) Composer autoloader — tests, tooling configs, docs, and dev
# dependencies are excluded.
set -euo pipefail
SLUG="unsupervised-schedular"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
MAIN="$ROOT/$SLUG.php"
BUILD_DIR="$ROOT/build"
STAGE="$BUILD_DIR/$SLUG"
DIST_DIR="$ROOT/dist"
# Runtime files/directories to ship (relative to repo root).
INCLUDE=(
"$SLUG.php"
"uninstall.php"
"composer.json"
"src"
"templates"
"assets"
"languages"
)
command -v composer >/dev/null 2>&1 || { echo "composer is required" >&2; exit 1; }
command -v zip >/dev/null 2>&1 || { echo "zip is required" >&2; exit 1; }
# Read the version from the plugin header so the zip is named per release.
VERSION="$(sed -nE 's/^[[:space:]]*\*?[[:space:]]*Version:[[:space:]]*([^[:space:]]+).*/\1/p' "$MAIN" | head -1)"
VERSION="${VERSION:-0.0.0}"
echo "Building $SLUG $VERSION..."
rm -rf "$BUILD_DIR"
mkdir -p "$STAGE" "$DIST_DIR"
for item in "${INCLUDE[@]}"; do
if [ -e "$ROOT/$item" ]; then
cp -R "$ROOT/$item" "$STAGE/"
fi
done
# Generate a production autoloader inside the staged copy.
( cd "$STAGE" && composer install --no-dev --optimize-autoloader --no-interaction --no-progress --quiet )
# Composer metadata is not needed in the shipped plugin.
rm -f "$STAGE/composer.json" "$STAGE/composer.lock"
ZIP="$DIST_DIR/$SLUG-$VERSION.zip"
rm -f "$ZIP"
( cd "$BUILD_DIR" && zip -rq "$ZIP" "$SLUG" -x '*.DS_Store' )
echo "Built $ZIP"