fix: deployment issues #5
Workflow file for this run
This file contains hidden or 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 and Release Plugin to WP.org | |
| on: | |
| push: | |
| tags: | |
| - "*" | |
| permissions: | |
| contents: write # needed to create GitHub release | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| releaseToWPOrg: | |
| name: Release to WordPress.org | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set plugin name | |
| id: plugin_name | |
| run: | | |
| PLUGIN_SLUG="${{ github.event.repository.name }}" | |
| PLUGIN_FILE="${PLUGIN_SLUG}.php" | |
| # Convert kebab-case to Title Case for display | |
| PLUGIN_NAME=$(echo "$PLUGIN_SLUG" | sed 's/-/ /g' | sed 's/\b\w/\U&/g') | |
| echo "plugin_slug=$PLUGIN_SLUG" >> $GITHUB_OUTPUT | |
| echo "plugin_file=$PLUGIN_FILE" >> $GITHUB_OUTPUT | |
| echo "plugin_name=$PLUGIN_NAME" >> $GITHUB_OUTPUT | |
| - name: Validate tag and plugin version alignment | |
| id: version_check | |
| run: | | |
| TAG_REF="${GITHUB_REF#refs/tags/}" | |
| # Strip leading v if present | |
| if [[ "$TAG_REF" =~ ^v ]]; then TAG_STRIPPED=${TAG_REF#v}; else TAG_STRIPPED=$TAG_REF; fi | |
| # Extract Version from plugin header (first match) | |
| PLUGIN_VERSION=$(grep -E "^[[:space:]]*\*[[:space:]]*Version:" ${{ steps.plugin_name.outputs.plugin_file }} | head -n1 | sed -E 's/.*Version:[[:space:]]*([^ ]+).*/\1/') | |
| echo "Tag: $TAG_REF"; | |
| echo "Stripped Tag: $TAG_STRIPPED"; | |
| echo "Plugin Version: $PLUGIN_VERSION"; | |
| if [ -z "$PLUGIN_VERSION" ]; then echo "Could not determine plugin version from ${{ steps.plugin_name.outputs.plugin_file }}"; exit 1; fi | |
| if [ "$PLUGIN_VERSION" != "$TAG_STRIPPED" ]; then echo "Version mismatch: tag ($TAG_STRIPPED) != plugin header ($PLUGIN_VERSION)"; exit 1; fi | |
| echo "version=$PLUGIN_VERSION" >> $GITHUB_OUTPUT | |
| - name: Ensure composer.lock is present | |
| run: | | |
| if [ ! -f composer.lock ]; then | |
| echo "composer.lock is missing. Please commit it before tagging a release." >&2 | |
| exit 1 | |
| fi | |
| - name: Setup PHP 7.4 | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '7.4' | |
| coverage: none | |
| tools: composer:v2 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.composer/cache | |
| vendor | |
| key: composer-${{ runner.os }}-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| composer-${{ runner.os }}- | |
| - name: Cache Node modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| node_modules | |
| key: node-${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }} | |
| restore-keys: | | |
| node-${{ runner.os }}- | |
| - name: Install PHP dependencies (with dev for build tooling) | |
| run: | | |
| composer install --no-interaction --prefer-dist | |
| - name: Build assets (npm) | |
| run: | | |
| if [ -f yarn.lock ]; then | |
| corepack enable yarn || true | |
| yarn install --frozen-lockfile | |
| yarn build | |
| else | |
| npm ci || npm install | |
| npm run build | |
| fi | |
| - name: Optimize production autoloader (remove dev deps) | |
| run: | | |
| composer install --no-dev --no-interaction --prefer-dist -o | |
| - name: "Guard: composer.lock unchanged after build" | |
| run: | | |
| if ! git diff --quiet --exit-code composer.lock; then | |
| echo "composer.lock changed during build. Commit updated lock file before release." >&2 | |
| git --no-pager diff composer.lock | head -n 100 | |
| exit 1 | |
| fi | |
| - name: Install SVN (Subversion) | |
| run: | | |
| sudo apt-get update -y | |
| sudo apt-get install -y subversion | |
| - name: WordPress Plugin Deploy | |
| id: deploy | |
| uses: 10up/action-wordpress-plugin-deploy@stable | |
| with: | |
| generate-zip: true | |
| env: | |
| SVN_USERNAME: ${{ secrets.SVN_USERNAME }} | |
| SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} | |
| SLUG: ${{ steps.plugin_name.outputs.plugin_slug }} | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ steps.version_check.outputs.version }} | |
| body: | | |
| Release ${{ steps.version_check.outputs.version }} of ${{ steps.plugin_name.outputs.plugin_name }}. | |
| Refer to CHANGELOG.md for full details. | |
| files: ${{ steps.deploy.outputs.zip-path }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |