Skip to content

Merge pull request #22 from searchcraft-inc/development #6

Merge pull request #22 from searchcraft-inc/development

Merge pull request #22 from searchcraft-inc/development #6

Workflow file for this run

name: Deploy to WordPress.org
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
dry_run:
description: 'Run in dry-run mode (no actual deployment)'
required: false
type: boolean
default: false
concurrency:
group: wordpress-deploy
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub repo
uses: actions/checkout@v4
- name: Setup SVN
run: |
sudo apt-get update
sudo apt-get install -y subversion rsync
- name: Export GitHub code to a clean folder
run: |
rm -rf /tmp/wordpress-svn
mkdir -p /tmp/wordpress-svn
svn checkout https://plugins.svn.wordpress.org/searchcraft/ /tmp/wordpress-svn
# Sync plugin code to trunk (excluding assets and dev files)
rsync -av --delete \
--exclude='.git' \
--exclude='.github' \
--exclude='vendor/bin' \
--exclude='vendor/dealerdirect' \
--exclude='vendor/phpcsstandards' \
--exclude='vendor/php-stubs' \
--exclude='vendor/squizlabs' \
--exclude='vendor/wp-coding-standards' \
--exclude='tests' \
--exclude='scripts' \
--exclude='.gitignore' \
--exclude='.vscode' \
--exclude='intelephense.json' \
--exclude='local_publish_prep.sh' \
--exclude='assets' \
./ /tmp/wordpress-svn/trunk/
# Sync assets to top-level assets directory (separate from trunk)
if [ -d "assets" ]; then
rsync -av --delete \
assets/ /tmp/wordpress-svn/assets/
echo "✓ Assets synced to SVN assets directory"
fi
- name: Get plugin version
id: get_version
run: |
VERSION=$(grep -i "Version:" searchcraft.php | head -n1 | awk -F: '{print $2}' | tr -d ' ')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected plugin version: $VERSION"
- name: Check Stable tag matches version
run: |
STABLE=$(grep -i "Stable tag:" readme.txt | awk -F: '{print $2}' | tr -d ' ')
VERSION=${{ steps.get_version.outputs.version }}
if [ "$STABLE" != "$VERSION" ]; then
echo "Error: Stable tag ($STABLE) does not match plugin version ($VERSION)"
exit 1
fi
echo "✓ Stable tag matches plugin version: $VERSION"
- name: Check if version already exists in SVN
run: |
cd /tmp/wordpress-svn
VERSION=${{ steps.get_version.outputs.version }}
# Check if tags directory exists and if version exists
if svn list tags 2>/dev/null | grep -q "^$VERSION/$"; then
echo "Error: Version $VERSION already exists in WordPress.org SVN"
echo "Please increment the version number before deploying"
exit 1
fi
echo "✓ Version $VERSION is new and ready to deploy"
- name: Commit to WordPress.org SVN
if: ${{ !inputs.dry_run }}
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
cd /tmp/wordpress-svn
# Add trunk files
svn add --force trunk/* --auto-props --parents --depth infinity
# Add assets files (if directory exists)
if [ -d "assets" ]; then
svn add --force assets/* --auto-props --parents --depth infinity
# Set proper mime types for images
svn propset svn:mime-type image/png assets/*.png 2>/dev/null || true
svn propset svn:mime-type image/jpeg assets/*.jpg 2>/dev/null || true
svn propset svn:mime-type image/gif assets/*.gif 2>/dev/null || true
fi
# Remove deleted files
svn status | grep '^!' | sed 's/^! *//' | xargs -r svn delete
svn commit -m "Deploy version ${{ steps.get_version.outputs.version }}" \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive --no-auth-cache
- name: Tag version in WordPress.org SVN
if: ${{ !inputs.dry_run }}
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
cd /tmp/wordpress-svn
VERSION=${{ steps.get_version.outputs.version }}
svn copy trunk tags/$VERSION
svn commit -m "Tagging version $VERSION" \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive --no-auth-cache
- name: Dry run summary
if: ${{ inputs.dry_run }}
run: |
echo "🔍 DRY RUN MODE - No changes were committed to WordPress.org SVN"
echo "Version ${{ steps.get_version.outputs.version }} would have been deployed"
echo "Review the changes in /tmp/wordpress-svn/trunk/ if needed"
- name: Send Discord notification on success
if: ${{ success() && !inputs.dry_run }}
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
if [ -n "$DISCORD_WEBHOOK" ]; then
curl -H "Content-Type: application/json" \
-d "{\"content\": \"✅ **Searchcraft v${{ steps.get_version.outputs.version }}** successfully deployed to WordPress.org\", \"embeds\": [{\"title\": \"Deployment Success\", \"color\": 3066993, \"fields\": [{\"name\": \"Version\", \"value\": \"${{ steps.get_version.outputs.version }}\", \"inline\": true}, {\"name\": \"Repository\", \"value\": \"${{ github.repository }}\", \"inline\": true}]}]}" \
"$DISCORD_WEBHOOK"
fi
- name: Send Discord notification on failure
if: ${{ failure() && !inputs.dry_run }}
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
if [ -n "$DISCORD_WEBHOOK" ]; then
curl -H "Content-Type: application/json" \
-d "{\"content\": \"❌ **Searchcraft deployment failed**\", \"embeds\": [{\"title\": \"Deployment Failed\", \"color\": 15158332, \"fields\": [{\"name\": \"Version\", \"value\": \"${{ steps.get_version.outputs.version }}\", \"inline\": true}, {\"name\": \"Repository\", \"value\": \"${{ github.repository }}\", \"inline\": true}, {\"name\": \"Workflow\", \"value\": \"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\", \"inline\": false}]}]}" \
"$DISCORD_WEBHOOK"
fi