Skip to content

How to use files from plugin / blueprint repo in wp-cli blueprint step #99

Open

Description

@leewillis77

I'm currently looking to implement a preview for one of our wp.org hosted plugins. In order to set up a meaningful demo we'd like to import some sample data using a wp-cli command. It looks like I can specify a wp-cli step, but I'm unsure what the execution context is of that command and what files it can access.

Ideally I'd be looking at providing this sort of structure in the SVN repo:

  • assets
    • blueprints
      • blueprint.json
      • sample-replacements.csv

I tried referencing the file directly without any path information, as the example below, but that doesn't appear to work.

{
    "step": "wp-cli",
    "command": "wp say-what import sample-replacements.csv"
}

Is there a way to reference asset files in playground steps?

Activity

  1. flexseth commented on Apr 10, 2024

    @flexseth

    I'm currently looking to implement a preview for one of our wp.org hosted plugins. In order to set up a meaningful demo we'd like to import some sample data using a wp-cli command. It looks like I can specify a wp-cli step, but I'm unsure what the execution context is of that command and what files it can access.

    @leewillis77 - a prime example of how to use Playground!

    • Human Made's WordPress Importer package has now been integrated
    • Here's an example blueprint for @helgatheviking's Simple User Listing plugin that imports content
    • Once you have the import working correctly, you'll want to include a blueprint on SVN so uses can use the "Preview Plugin" feature to demo the plugin

    If one of the approaches above works, please let me know which. And if possible if I could include a link to importing demo content to this example use case from the docs, that would be excellent!

  2. leewillis77 commented on Apr 10, 2024

    @leewillis77
    Author

    Hi @flexseth;

    Thanks for the quick reply, but I don't think either of those examples really help.

    Human Made's package is for running a WordPress import, which isn't the case here, the data is plugin-specific, so it's not done via a WordPress import. Even in the Simple User Listing plugin example while the data is not included in the blueprint.json file it looks like it's pulled from an external URL.

    What I'm asking in this issue is the ability to have a way for a step (in this case a wp-cli step) to access a file in the SVN repo. I can't currently see how to do that? See the 'wp-cli' step here https://plugins.svn.wordpress.org/say-what/assets/blueprints/blueprint.json

    The wp-cli command needs to access a file to read the information from, but I can't work out how to point that at https://plugins.svn.wordpress.org/say-what/assets/blueprints/sample-replacements.csv

  3. flexseth commented on Apr 10, 2024

    @flexseth

    The wp-cli command needs to access a file to read the information from, but I can't work out how to point that at https://plugins.svn.wordpress.org/say-what/assets/blueprints/sample-replacements.csv

    Interesting. I'm able to click and download the file, so it should be publicly accessible?

    This may be a limitation of the WP-CLI package or how it's implemented in Playground.

    Definitely a use case we are looking to get ironed out very soon, so I will be following here and also trying to work on an example myself. The only problem is I don't have anything on SVN, or really know how to use Subversion at all. :/

  4. leewillis77 commented on Apr 10, 2024

    @leewillis77
    Author

    This may be a limitation of the WP-CLI package or how it's implemented in Playground.

    Maybe, since essentially wp-cli is expecting a "local" file, not a URL, so I'm not clear on how I can either a) fetch the file from a remote and then have the wp-cli step access it somehow or b) have the wp-cli step use a remote file directly.

  5. helgatheviking commented on Apr 10, 2024

    @helgatheviking

    @leewillis77 My understanding on import was that it needs to be somewhere public with a CORS policy set. I couldn't tell you in the SVN repo has that or not, but in a github repo with the raw github url should be accessible via cli.

  6. flexseth commented on Apr 10, 2024

    @flexseth

    @leewillis77 - try out the demo from @ryanwelcher's livestream

    • Advanced Query Loop by Ryan Welcher demo

    I'm working on the docs, if you're able to get a technique similar to this to work, or however you get this working, please link the blueprint you come up with!

    CORS

    Can totally be a "gotcha"

    @helgatheviking may be correct with the Cross-Origin headers. You can try adding a PHP headers with a RunPHPWithOptionsStep step - providing the CORS headers?

    {
        "steps": [
            {
                "step": "runPHP",
                "options": {
                    "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>",
                    "headers": {
                        "Content-type": "text/plain"
                    }
                }
            }
        ]
    }
  7. leewillis77 commented on Apr 10, 2024

    @leewillis77
    Author

    @helgatheviking @flexseth Thanks both for the comments, but they're not really relevant to the issue at hand - probably I'm explaining things badly, apologies.

    This is not an importFile step, so neither Ryan's example nor the issue with requiring cors headers on importFile fetches are relevant. It's a wp-cli step so I either need to understand if there's a way I can write a step to fetch a remote URL into the local filesystem somewhere that I can point a subsequent wp-cli step at, or in some way allow the wp-cli step to directly access the content from a URL not a local file.

  8. changed the title [-]How to use files from plugin / blueprint repo in blueprint step[/-] [+]How to use files from plugin / blueprint repo in wp-cli blueprint step[/+] on Apr 10, 2024
  9. flexseth commented on Apr 10, 2024

    @flexseth

    write a step to fetch a remote URL into the local filesystem somewhere that I can point a subsequent wp-cli step at

    How about with PHP?

    What if you create a PHP snippet that will achieve what you need, and pass that through the runPHP step - similar to the following blueprint

    In this example, Adam refactors a PHP snippet as a call to a runPHP step

    changes to fetch

    Otherwise, if you search the WordPress Playground repo for "fetch" - you may find more information on the changes they've been making relative to data handling.

    I know there have been a lot of changes made to how fetch works behind the scenes but had to turn off email notifications because there was soo many updates 👍

  10. adamziel commented on Apr 12, 2024

    @adamziel
    Collaborator

    @leewillis77 here's what I would do:

    {
        "steps": [
            {
                 "step": "writeFile",
                 "path": "/wordpress/sample-replacements.csv",
                 "data": {
                     "resource": "url",
                     "url": "https://plugins.svn.wordpress.org/<YOUR PLUGIN>/assets/blueprints/sample-replacements.csv"
                  }
            },
            {
                "step": "wp-cli",
                "command": "wp say-what import /wordpress/sample-replacements.csv"
            }
        ]
    }

    Let me know if that's helpful.

  11. leewillis77 commented on Apr 12, 2024

    @leewillis77
    Author

    Hey @adamziel;

    That looks like exactly what I was asking. It won't work as-is since plugins.svn.wordpress.org doesn't set the appropriate CORS headers to allow the fetch to work. Is that something we could get changed do you think?

    I can confirm that it does work if you (for example) point it at a GitHub raw URL (thanks @helgatheviking!)

  12. adamziel commented on Apr 12, 2024

    @adamziel
    Collaborator

    It won't work as-is since plugins.svn.wordpress.org doesn't set the appropriate CORS headers to allow the fetch to work. Is that something we could get changed do you think?

    cc @tellyworth @dd32 – should plugins.svn.wordpress.org expose the CORS headers to allow using additional assets in Blueprints?

  13. leewillis77 commented on Apr 12, 2024

    @leewillis77
    Author

    The blueprint.json at https://plugins.svn.wordpress.org/say-what/assets/blueprints/ is an example of how this would be used. Ideally the resource would fetch the file from https://plugins.svn.wordpress.org/say-what/assets/blueprints/sample-replacements.csv rather than GitHub.

  14. dd32 commented on Apr 15, 2024

    @dd32
    Member

    should plugins.svn.wordpress.org expose the CORS headers to allow using additional assets in Blueprints?

    We probably don't want plugins.svn being accessed, but the CDN in front of it at ps.w.org can probably be used (We could add some code to playground to rewrite the fetches). But it doesn't currently support CORS and it requires cache-busters be included in the urls..

    Alex requested systems input back in November, and there hasn't been an outcome on whether adding CORS is possible. Private systems request: https://make.wordpress.org/systems/?p=2330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions