feat(styles): administrator-managed style registry for the embedded editor #42
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: PR Playground Preview | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| concurrency: | |
| group: playground-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| playground-preview: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 2 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Build Playground URL and post comment | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| // Read blueprint from repo | |
| const blueprint = JSON.parse(fs.readFileSync('blueprint.json', 'utf8')); | |
| // Swap plugin URL to PR branch archive | |
| const headRepo = context.payload.pull_request.head.repo.full_name; | |
| const branch = context.payload.pull_request.head.ref; | |
| const prNumber = context.payload.pull_request.number; | |
| const pluginUrl = `https://github.com/${headRepo}/archive/refs/heads/${branch}.zip`; | |
| const fixtureBaseUrl = `https://raw.githubusercontent.com/${headRepo}/refs/heads/${branch}/tests/fixtures`; | |
| // Update blueprint | |
| for (const step of blueprint.steps) { | |
| if (step.step === 'installPlugin' && step.pluginData) { | |
| step.pluginData.url = pluginUrl; | |
| } | |
| if (step.step === 'writeFile' && step.data && step.data.url && step.data.url.includes('/tests/fixtures/')) { | |
| const filename = step.data.url.split('/').pop(); | |
| step.data.url = `${fixtureBaseUrl}/${filename}`; | |
| } | |
| } | |
| blueprint.siteOptions.blogname = `eXeLearning PR #${prNumber} Preview`; | |
| // Base64 encode | |
| const encoded = Buffer.from(JSON.stringify(blueprint)).toString('base64'); | |
| const playgroundUrl = `https://playground.wordpress.net/#${encoded}`; | |
| const marker = '<!-- wp-playground-preview -->'; | |
| const body = [ | |
| marker, | |
| '## Test in WordPress Playground', | |
| '', | |
| 'Test the plugin **with the code from this branch**:', | |
| '', | |
| `<a href="${playgroundUrl}"><img src="https://raw.githubusercontent.com/${context.repo.owner}/${context.repo.repo}/refs/heads/${context.payload.pull_request.head.ref}/.github/playground-preview-button.svg" alt="Preview in WordPress Playground" width="224"></a>`, | |
| '', | |
| '> ⚠️ The embedded eXeLearning editor is not included in this preview. You can install it from **Settings > eXeLearning** using the "Download & Install Editor" button. All other plugin features (ELP upload, shortcode, Gutenberg block, preview) work normally.', | |
| ].join('\n'); | |
| // Find existing comment | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const existing = comments.find(c => c.body.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body, | |
| }); | |
| } |