Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foobar #23

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build-plugin-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,35 @@ jobs:
name: release-notes
path: ./release-notes.txt

create-playground-link:
name: Create WordPress Playground Link
runs-on: ubuntu-latest
needs: build
if: always()

steps:
- name: Debug - Event Name
run: echo "Event Name - ${{ github.event_name }}"

- name: Debug - Build Job Status
run: echo "Build Job Status - ${{ needs.build.outputs.job_status }}"

- name: Debug - Is Pull Request Event
if: github.event_name == 'pull_request'
run: echo "This is a pull request event"

- name: Debug - Is Build Job Successful
if: needs.build.outputs.job_status == 'success'
run: echo "The build job was successful"

- name: Create WordPress Playground link comment
uses: actions/github-script@v7
with:
script: |
const { run } = require('./.github/workflows/scripts/generate-playground-blueprint.js');
run({ github, context });


revert-version-bump:
name: Revert version bump if build failed
needs: [bump-version, build]
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/scripts/generate-playground-blueprint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const generateWordpressPlaygroundBlueprint = (prNumber) => {
const defaultSchema = {
landingPage: '/wp-admin/',
steps: [
{
step: 'login',
username: 'admin',
password: 'password',
},
{
step: 'mkdir',
path: '/wordpress/pr',
},
{
step: 'writeFile',
path: '/wordpress/pr/pr.zip',
data: {
resource: 'url',
url: `/plugin-proxy.php?org=WordPress&repo=gutenberg&workflow=Build%20Gutenberg%20Plugin%20Zip&artifact=gutenberg-plugin&pr=${prNumber}`,
caption: `Downloading Gutenberg PR ${prNumber}`,
},
progress: {
weight: 2,
caption: `Applying Gutenberg PR ${prNumber}`,
},
},
{
step: 'unzip',
zipPath: '/wordpress/pr/pr.zip',
extractToPath: '/wordpress/pr',
},
{
step: 'installPlugin',
pluginZipFile: {
resource: 'vfs',
path: '/wordpress/pr/gutenberg.zip',
},
},
],
};

return defaultSchema;
};

async function run({ github, context }) {
const commentInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
};

const comments = (await github.rest.issues.listComments(commentInfo)).data;
let existingCommentId = null;

for (const currentComment of comments) {
if (
currentComment.user.type === 'Bot' &&
currentComment.body.includes('Test using WordPress Playground')
) {
existingCommentId = currentComment.id;
break;
}
}

const defaultSchema = generateWordpressPlaygroundBlueprint(context.issue.number);
const encodedJson = encodeURI(JSON.stringify(defaultSchema));
const url = `https://playground.wordpress.net/#${encodedJson}`;

const body = `
## Test using WordPress Playground
The changes in this pull request can be previewed and tested using a [Wordpress Playground](https://playground.wordpress.net/playground/) instance.

[Test this pull request with Wordpress Playground](${url}).

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.`;

if (existingCommentId) {
await github.rest.issues.updateComment({
owner: commentInfo.owner,
repo: commentInfo.repo,
comment_id: existingCommentId,
body: body,
});
} else {
commentInfo.body = body;
await github.rest.issues.createComment(commentInfo);
}
}

module.exports = { run };
2 changes: 1 addition & 1 deletion lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* Substitutes the implementation of a core-registered block type, if exists,
* with the built result from the plugin.
* with the built result from the plugin. Fooabr.
*/
function gutenberg_reregister_core_block_types() {
// Blocks directory may not exist if working from a fresh clone.
Expand Down
Loading