diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbe4c28..19cf994 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,7 @@ concurrency: permissions: contents: read + pull-requests: write env: COMPOSER_NO_INTERACTION: 1 @@ -172,3 +173,68 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: artifacts/coverage/clover.xml fail_ci_if_error: false + + playground: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + timeout-minutes: 2 + permissions: + pull-requests: write + steps: + - name: Find existing Playground comment + uses: peter-evans/find-comment@v3 + id: find-comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: '' + + - name: Build Playground URL + if: steps.find-comment.outputs.comment-id == '' + id: playground-url + run: | + PLUGIN_URL="https://github.com/${{ github.repository }}/archive/refs/heads/${{ github.head_ref }}.zip" + + BLUEPRINT=$(cat <<'BLUEPRINT_EOF' + { + "$schema": "https://playground.wordpress.net/blueprint-schema.json", + "preferredVersions": { "php": "latest", "wp": "latest" }, + "siteOptions": { "blogname": "eXeLearning PR Test" }, + "steps": [ + { "step": "setSiteLanguage", "language": "es_ES" }, + { + "step": "installPlugin", + "pluginData": { "resource": "url", "url": "PLUGIN_URL_PLACEHOLDER" }, + "options": { "activate": true } + }, + { + "step": "runPHP", + "code": "set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(true); ?>" + } + ], + "features": { "networking": true }, + "login": true, + "landingPage": "/wp-admin/upload.php" + } + BLUEPRINT_EOF + ) + + BLUEPRINT=$(echo "$BLUEPRINT" | sed "s|PLUGIN_URL_PLACEHOLDER|${PLUGIN_URL}|g") + ENCODED=$(echo "$BLUEPRINT" | base64 -w 0) + PLAYGROUND_URL="https://playground.wordpress.net/#${ENCODED}" + echo "url=${PLAYGROUND_URL}" >> $GITHUB_OUTPUT + + - name: Add Playground link comment + if: steps.find-comment.outputs.comment-id == '' + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + + ## Test in WordPress Playground + + Test the plugin **with the code from this branch**: + + **[Open in WordPress Playground](${{ steps.playground-url.outputs.url }})** + + > ⚠️ The embedded eXeLearning editor is not available in this preview (requires build). All other plugin features (ELP upload, shortcode, Gutenberg block, preview) work normally.