|
| 1 | +name: Release and Deploy to WordPress.org |
| 2 | + |
| 3 | +# Single consolidated workflow that: |
| 4 | +# 1. Creates GitHub releases using changesets |
| 5 | +# 2. Deploys to WordPress.org automatically |
| 6 | +# Matches wp-graphql's proven approach for consistency across the organization |
| 7 | + |
| 8 | +# Prevent multiple releases from running simultaneously |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +on: |
| 14 | + push: |
| 15 | + branches: |
| 16 | + - main |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + release_type: |
| 20 | + description: 'Force a specific release type (leave empty for auto-detection)' |
| 21 | + required: false |
| 22 | + type: choice |
| 23 | + options: |
| 24 | + - auto |
| 25 | + - major |
| 26 | + - minor |
| 27 | + - patch |
| 28 | + default: 'auto' |
| 29 | + deploy_only: |
| 30 | + description: 'Only deploy an existing tag (skip release creation)' |
| 31 | + required: false |
| 32 | + type: boolean |
| 33 | + default: false |
| 34 | + deploy_tag: |
| 35 | + description: 'Specific tag to deploy (required if deploy_only is true)' |
| 36 | + required: false |
| 37 | + type: string |
| 38 | + default: '' |
| 39 | + |
| 40 | +jobs: |
| 41 | + prepare-release: |
| 42 | + name: Prepare Release |
| 43 | + if: github.event.inputs.deploy_only != 'true' |
| 44 | + runs-on: ubuntu-22.04 |
| 45 | + outputs: |
| 46 | + published: ${{ steps.changesets.outputs.published }} |
| 47 | + version: ${{ steps.get-version.outputs.version }} |
| 48 | + release_created: ${{ steps.changesets.outputs.published == 'true' }} |
| 49 | + steps: |
| 50 | + - name: Debug workflow information |
| 51 | + run: | |
| 52 | + echo "=== RELEASE WORKFLOW DEBUG INFO ===" |
| 53 | + echo "Event name: ${{ github.event_name }}" |
| 54 | + echo "Event inputs: ${{ toJSON(github.event.inputs) }}" |
| 55 | + echo "Deploy only: ${{ github.event.inputs.deploy_only }}" |
| 56 | + echo "Release type: ${{ github.event.inputs.release_type }}" |
| 57 | + echo "Current ref: ${{ github.ref }}" |
| 58 | + echo "Repository: ${{ github.repository }}" |
| 59 | + echo "Workflow run ID: ${{ github.run_id }}" |
| 60 | + echo "=====================================" |
| 61 | +
|
| 62 | + - name: Checkout Repository |
| 63 | + uses: actions/checkout@v4 |
| 64 | + with: |
| 65 | + fetch-depth: 0 |
| 66 | + token: ${{ secrets.GH_PAT }} |
| 67 | + |
| 68 | + - name: Setup Node.js |
| 69 | + uses: actions/setup-node@v4 |
| 70 | + with: |
| 71 | + node-version: '18' |
| 72 | + cache: 'npm' |
| 73 | + |
| 74 | + - name: Install Dependencies |
| 75 | + run: npm ci |
| 76 | + |
| 77 | + - name: Create Release Pull Request or Create GitHub Release |
| 78 | + id: changesets |
| 79 | + uses: changesets/action@v1 |
| 80 | + with: |
| 81 | + version: npm run version |
| 82 | + publish: npm run release |
| 83 | + title: "release: 📦 Release Plugin" |
| 84 | + commit: "release: 📦 Release Plugin" |
| 85 | + env: |
| 86 | + GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
| 87 | + |
| 88 | + - name: Check published output |
| 89 | + run: | |
| 90 | + echo "Published: ${{ steps.changesets.outputs.published }}" |
| 91 | + echo "Published packages: ${{ steps.changesets.outputs.publishedPackages }}" |
| 92 | +
|
| 93 | + - name: Get version from published packages |
| 94 | + id: get-version |
| 95 | + if: steps.changesets.outputs.published == 'true' |
| 96 | + run: | |
| 97 | + VERSION=$(echo '${{ steps.changesets.outputs.publishedPackages }}' | jq -r '.[0].version') |
| 98 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 99 | + echo "Published version: ${VERSION}" |
| 100 | +
|
| 101 | + - name: Validate version consistency |
| 102 | + if: steps.changesets.outputs.published == 'true' |
| 103 | + run: | |
| 104 | + RELEASE_VERSION="${{ steps.get-version.outputs.version }}" |
| 105 | +
|
| 106 | + # Check package.json |
| 107 | + PACKAGE_VERSION=$(grep -o '"version": "[^"]*"' package.json | sed 's/"version": "//' | sed 's/"//') |
| 108 | +
|
| 109 | + echo "Version in package.json: ${PACKAGE_VERSION}" |
| 110 | + echo "Release version: ${RELEASE_VERSION}" |
| 111 | +
|
| 112 | + if [[ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ]]; then |
| 113 | + echo "::error::Version mismatch! package.json: ${PACKAGE_VERSION}, expected: ${RELEASE_VERSION}" |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | +
|
| 117 | + echo "✅ Version consistency validated" |
| 118 | +
|
| 119 | + - name: Release Summary |
| 120 | + if: always() |
| 121 | + run: | |
| 122 | + echo "=== RELEASE WORKFLOW SUMMARY ===" |
| 123 | + echo "Version: ${{ steps.get-version.outputs.version }}" |
| 124 | + echo "Published: ${{ steps.changesets.outputs.published }}" |
| 125 | + echo "Workflow run ID: ${{ github.run_id }}" |
| 126 | + echo "=================================" |
| 127 | +
|
| 128 | + deploy-wordpress: |
| 129 | + name: Deploy to WordPress.org |
| 130 | + needs: prepare-release |
| 131 | + if: | |
| 132 | + always() && |
| 133 | + ( |
| 134 | + (needs.prepare-release.outputs.release_created == 'true') || |
| 135 | + (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_only == 'true' && github.event.inputs.deploy_tag != '') |
| 136 | + ) |
| 137 | + runs-on: ubuntu-22.04 |
| 138 | + environment: actions |
| 139 | + steps: |
| 140 | + - name: Determine tag and version to deploy |
| 141 | + id: get_version_info |
| 142 | + run: | |
| 143 | + if [[ "${{ github.event.inputs.deploy_only }}" == "true" ]]; then |
| 144 | + DEPLOY_TAG="${{ github.event.inputs.deploy_tag }}" |
| 145 | + # Ensure deploy_tag starts with 'v' if provided for deploy_only |
| 146 | + if [[ ! "$DEPLOY_TAG" =~ ^v ]]; then |
| 147 | + echo "::warning::Deploy tag '${DEPLOY_TAG}' does not start with 'v'. Prepending 'v'." |
| 148 | + DEPLOY_TAG="v${DEPLOY_TAG}" |
| 149 | + fi |
| 150 | + else |
| 151 | + DEPLOY_TAG="v${{ needs.prepare-release.outputs.version }}" |
| 152 | + fi |
| 153 | +
|
| 154 | + # Validate tag format (vX.Y.Z) |
| 155 | + if [[ ! "$DEPLOY_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.].+)?$ ]]; then |
| 156 | + echo "::error::Invalid tag format: '$DEPLOY_TAG'. Expected format: vX.Y.Z or vX.Y.Z-suffix" |
| 157 | + exit 1 |
| 158 | + fi |
| 159 | +
|
| 160 | + # Extract version number without 'v' |
| 161 | + VERSION_NUMBER=$(echo "$DEPLOY_TAG" | sed 's/^v//') |
| 162 | +
|
| 163 | + echo "tag_name=${DEPLOY_TAG}" >> $GITHUB_OUTPUT |
| 164 | + echo "version_number=${VERSION_NUMBER}" >> $GITHUB_OUTPUT |
| 165 | + echo "Deploying Tag: ${DEPLOY_TAG}, Version Number: ${VERSION_NUMBER}" |
| 166 | +
|
| 167 | + - name: Checkout Repository |
| 168 | + uses: actions/checkout@v4 |
| 169 | + with: |
| 170 | + ref: ${{ steps.get_version_info.outputs.tag_name }} |
| 171 | + fetch-depth: 0 |
| 172 | + |
| 173 | + - name: Setup PHP |
| 174 | + uses: shivammathur/setup-php@v2 |
| 175 | + with: |
| 176 | + php-version: 8.2 |
| 177 | + extensions: mbstring, intl |
| 178 | + tools: composer |
| 179 | + |
| 180 | + - name: Setup Node.js |
| 181 | + uses: actions/setup-node@v4 |
| 182 | + with: |
| 183 | + node-version: '18' |
| 184 | + cache: 'npm' |
| 185 | + |
| 186 | + - name: Install Subversion |
| 187 | + run: sudo apt-get update && sudo apt-get install -y subversion |
| 188 | + |
| 189 | + - name: Install PHP dependencies |
| 190 | + run: composer install --no-dev --optimize-autoloader |
| 191 | + |
| 192 | + - name: Install Node dependencies and build |
| 193 | + run: | |
| 194 | + npm ci |
| 195 | + npm run build |
| 196 | +
|
| 197 | + - name: Debug SVN secret presence |
| 198 | + run: | |
| 199 | + if [ -z "${{ secrets.SVN_USERNAME }}" ] || [ -z "${{ secrets.SVN_PASSWORD }}" ]; then |
| 200 | + echo "::error::SVN credentials are NOT set!" |
| 201 | + exit 1 |
| 202 | + else |
| 203 | + echo "✅ SVN credentials are detected" |
| 204 | + fi |
| 205 | +
|
| 206 | + - name: Exclude unchanged assets from deployment |
| 207 | + run: | |
| 208 | + if [ -d ".wordpress-org" ]; then |
| 209 | + echo "Temporarily moving .wordpress-org to prevent property-only SVN changes" |
| 210 | + mv .wordpress-org .wordpress-org-backup |
| 211 | + fi |
| 212 | +
|
| 213 | + - name: WordPress Plugin Deploy |
| 214 | + uses: 10up/action-wordpress-plugin-deploy@stable |
| 215 | + env: |
| 216 | + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} |
| 217 | + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} |
| 218 | + SLUG: wpgraphql-ide |
| 219 | + VERSION: ${{ steps.get_version_info.outputs.version_number }} |
| 220 | + |
| 221 | + - name: Create plugin artifact |
| 222 | + run: npm run build:zip |
| 223 | + |
| 224 | + - name: Upload artifact to workflow |
| 225 | + uses: actions/upload-artifact@v4 |
| 226 | + with: |
| 227 | + name: wpgraphql-ide |
| 228 | + path: wpgraphql-ide.zip |
| 229 | + |
| 230 | + - name: Upload artifact to release |
| 231 | + if: github.event.inputs.deploy_only != 'true' |
| 232 | + uses: softprops/action-gh-release@v2 |
| 233 | + with: |
| 234 | + tag_name: ${{ steps.get_version_info.outputs.tag_name }} |
| 235 | + files: wpgraphql-ide.zip |
| 236 | + env: |
| 237 | + GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
| 238 | + |
| 239 | + - name: Deploy Summary |
| 240 | + if: always() |
| 241 | + run: | |
| 242 | + echo "=== DEPLOY WORKFLOW SUMMARY ===" |
| 243 | + echo "Tag: ${{ steps.get_version_info.outputs.tag_name }}" |
| 244 | + echo "Version: ${{ steps.get_version_info.outputs.version_number }}" |
| 245 | + echo "Deploy only mode: ${{ github.event.inputs.deploy_only }}" |
| 246 | + echo "=================================" |
0 commit comments