- .markdownlint.json: enforce MD004 asterisk style to match project conventions
- .wiki/Contributing.md: convert all dash list markers to asterisks (MD004)
- .wiki/Coding-Standards.md: fix PHPDoc bullet wording (add missing preposition)
- build.sh: add set -euo pipefail for strict error handling
- build.sh: fix SC2115 (use ${var:?} to prevent rm -rf /)
- build.sh: fix SC2164 (cd build || exit 1)
- build.sh: fix SC2028 (use printf instead of echo for escape sequences)
- build.sh: fix SC2035 (use ./*.php glob to avoid dash-named files)
Closes #46
This commit is contained in:
79
build.sh
79
build.sh
@@ -1,13 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# WordPress Plugin Build Script
|
||||
# This script creates a clean build of the plugin for distribution
|
||||
|
||||
# Check if version is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "❌ Error: Version number is required"
|
||||
echo "Usage: ./build.sh <version>"
|
||||
exit 1
|
||||
echo "❌ Error: Version number is required"
|
||||
echo "Usage: ./build.sh <version>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION=$1
|
||||
@@ -22,15 +23,15 @@ mkdir -p "$BUILD_DIR"
|
||||
|
||||
# Run code quality checks
|
||||
echo "Running code quality checks..."
|
||||
if command -v composer &> /dev/null; then
|
||||
echo "Running PHPCS..."
|
||||
composer run phpcs || { echo "⚠️ PHPCS found issues. Consider running 'composer run phpcbf' to fix them."; }
|
||||
if command -v composer &>/dev/null; then
|
||||
echo "Running PHPCS..."
|
||||
composer run phpcs || { echo "⚠️ PHPCS found issues. Consider running 'composer run phpcbf' to fix them."; }
|
||||
|
||||
# Uncomment the following line to automatically fix coding standards issues
|
||||
# echo "Running PHPCBF..."
|
||||
# composer run phpcbf
|
||||
# Uncomment the following line to automatically fix coding standards issues
|
||||
# echo "Running PHPCBF..."
|
||||
# composer run phpcbf
|
||||
else
|
||||
echo "⚠️ Composer not found, skipping code quality checks"
|
||||
echo "⚠️ Composer not found, skipping code quality checks"
|
||||
fi
|
||||
|
||||
# Install composer dependencies
|
||||
@@ -39,7 +40,7 @@ composer install --no-dev --optimize-autoloader
|
||||
|
||||
# Copy plugin files to build directory
|
||||
echo "Copying plugin files..."
|
||||
cp -R *.php "$BUILD_DIR/"
|
||||
cp -R ./*.php "$BUILD_DIR/"
|
||||
cp -R README.md LICENSE CHANGELOG.md readme.txt composer.json "$BUILD_DIR/"
|
||||
|
||||
# Copy directories
|
||||
@@ -54,57 +55,57 @@ mkdir -p "$BUILD_DIR/assets/banner" "$BUILD_DIR/assets/icon" "$BUILD_DIR/assets/
|
||||
|
||||
# Copy assets if they exist
|
||||
if [ -d "assets/banner" ]; then
|
||||
cp -R assets/banner/* "$BUILD_DIR/assets/banner/"
|
||||
cp -R assets/banner/* "$BUILD_DIR/assets/banner/"
|
||||
fi
|
||||
|
||||
if [ -d "assets/icon" ]; then
|
||||
cp -R assets/icon/* "$BUILD_DIR/assets/icon/"
|
||||
cp -R assets/icon/* "$BUILD_DIR/assets/icon/"
|
||||
fi
|
||||
|
||||
if [ -d "assets/screenshots" ]; then
|
||||
cp -R assets/screenshots/* "$BUILD_DIR/assets/screenshots/"
|
||||
cp -R assets/screenshots/* "$BUILD_DIR/assets/screenshots/"
|
||||
fi
|
||||
|
||||
# Copy vendor directory if it exists
|
||||
if [ -d "vendor" ]; then
|
||||
cp -R vendor "$BUILD_DIR/"
|
||||
cp -R vendor "$BUILD_DIR/"
|
||||
fi
|
||||
|
||||
# Create ZIP file
|
||||
echo "Creating ZIP file..."
|
||||
cd build
|
||||
cd build || exit 1
|
||||
zip -r "../$ZIP_FILE" "$PLUGIN_SLUG" -x "*.DS_Store" -x "*.git*" -x "*.github*"
|
||||
cd ..
|
||||
|
||||
# Check if ZIP file was created successfully
|
||||
if [ -f "$ZIP_FILE" ]; then
|
||||
echo "✅ Build successful: $ZIP_FILE created"
|
||||
echo "File path: $(pwd)/$ZIP_FILE"
|
||||
echo "✅ Build successful: $ZIP_FILE created"
|
||||
echo "File path: $(pwd)/$ZIP_FILE"
|
||||
|
||||
# Deploy to local WordPress installation if environment variable is set
|
||||
if [ -n "$WP_LOCAL_PLUGIN_DIR" ]; then
|
||||
echo "\nDeploying to local WordPress installation..."
|
||||
echo "Deploying to local WordPress installation..."
|
||||
# Deploy to local WordPress installation if environment variable is set
|
||||
if [ -n "$WP_LOCAL_PLUGIN_DIR" ]; then
|
||||
printf '\nDeploying to local WordPress installation...\n'
|
||||
echo "Deploying to local WordPress installation..."
|
||||
|
||||
# Remove existing plugin directory
|
||||
rm -rf "$WP_LOCAL_PLUGIN_DIR/$PLUGIN_SLUG"
|
||||
# Remove existing plugin directory
|
||||
rm -rf "${WP_LOCAL_PLUGIN_DIR:?}/$PLUGIN_SLUG"
|
||||
|
||||
# Copy files to local WordPress installation
|
||||
rsync -av --exclude=".git" --exclude=".github" --exclude=".DS_Store" \
|
||||
"$BUILD_DIR/" "$WP_LOCAL_PLUGIN_DIR/$PLUGIN_SLUG"
|
||||
# Copy files to local WordPress installation
|
||||
rsync -av --exclude=".git" --exclude=".github" --exclude=".DS_Store" \
|
||||
"$BUILD_DIR/" "$WP_LOCAL_PLUGIN_DIR/$PLUGIN_SLUG"
|
||||
|
||||
# Clear WordPress transients if WP-CLI is available
|
||||
if command -v wp &> /dev/null; then
|
||||
echo "Clearing WordPress transients..."
|
||||
wp transient delete --all --path="$WP_LOCAL_PLUGIN_DIR/../.."
|
||||
else
|
||||
echo "⚠️ WP-CLI not found, skipping transient clearing"
|
||||
fi
|
||||
# Clear WordPress transients if WP-CLI is available
|
||||
if command -v wp &>/dev/null; then
|
||||
echo "Clearing WordPress transients..."
|
||||
wp transient delete --all --path="$WP_LOCAL_PLUGIN_DIR/../.."
|
||||
else
|
||||
echo "⚠️ WP-CLI not found, skipping transient clearing"
|
||||
fi
|
||||
|
||||
echo "✅ Local deployment successful!"
|
||||
echo "Plugin deployed to: $WP_LOCAL_PLUGIN_DIR/$PLUGIN_SLUG"
|
||||
fi
|
||||
echo "✅ Local deployment successful!"
|
||||
echo "Plugin deployed to: $WP_LOCAL_PLUGIN_DIR/$PLUGIN_SLUG"
|
||||
fi
|
||||
else
|
||||
echo "❌ Build failed: ZIP file was not created"
|
||||
exit 1
|
||||
echo "❌ Build failed: ZIP file was not created"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user