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

GitDirectoryResource #1858

Merged
merged 3 commits into from
Oct 8, 2024
Merged

GitDirectoryResource #1858

merged 3 commits into from
Oct 8, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Oct 7, 2024

Related to #1787, Follows up on #1793

Implements GitDirectoryResource to enable loading files directly from git repositories as follows:

{
	"landingPage": "/guides/for-plugin-developers.md",
	"steps": [
		{
			"step": "writeFiles",
			"writeToPath": "/wordpress/guides",
			"filesTree": {
				"resource": "git:directory",
				"url": "https://github.com/WordPress/wordpress-playground.git",
				"ref": "trunk",
				"path": "packages/docs/site/docs/main/guides"
			}
		}
	]
}

Implementation details

Uses git client functions merged in #1764 to sparse checkout the requested files. It also leans on the PHP CORS proxy which is now started as a part of the npm run dev command.

The CORS proxy URL is configurable per compileBlueprint() call so that each Playground runtime may choose to either use it or not. For example, it wouldn't be very useful in the CLI version of Playground.

Testing plan

Go to

http://localhost:5400/website-server/#{%20%22landingPage%22:%20%22/guides/for-plugin-developers.md%22,%20%22steps%22:%20[%20{%20%22step%22:%20%22writeFiles%22,%20%22writeToPath%22:%20%22/wordpress/guides%22,%20%22filesTree%22:%20{%20%22resource%22:%20%22git:directory%22,%20%22url%22:%20%22https://github.com/WordPress/wordpress-playground.git%22,%20%22ref%22:%20%22trunk%22,%20%22path%22:%20%22packages/docs/site/docs/main/guides%22%20}%20}%20]%20}

And confirm the Playground loads a markdown file.

Related to #1787, Follows up on #1793

Implements GitDirectoryResource to enable loading files directly from
git repositories as follows:

```ts
{
	"landingPage": "/guides/for-plugin-developers.md",
	"steps": [
		{
			"step": "writeFiles",
			"writeToPath": "/wordpress/guides",
			"filesTree": {
				"resource": "git:directory",
				"url": "https://github.com/WordPress/wordpress-playground.git",
				"ref": "trunk",
				"path": "packages/docs/site/docs/main/guides"
			}
		}
	]
}
```

 ## Implementation details

Uses git client functions merged in
#1764 to sparse
checkout the requested files. It also leans on the PHP CORS proxy which
is now started as a part of the `npm run dev` command.

The CORS proxy URL is configurable per `compileBlueprint()` call so that each
Playground runtime may choose to either use it or not. For example, it
wouldn't be very useful in the CLI version of Playground.

 ## Testing plan

Go to
`http://localhost:5400/website-server/#{%20%22landingPage%22:%20%22/guides/for-plugin-developers.md%22,%20%22steps%22:%20[%20{%20%22step%22:%20%22writeFiles%22,%20%22writeToPath%22:%20%22/wordpress/guides%22,%20%22filesTree%22:%20{%20%22resource%22:%20%22git:directory%22,%20%22url%22:%20%22https://github.com/WordPress/wordpress-playground.git%22,%20%22ref%22:%20%22trunk%22,%20%22path%22:%20%22packages/docs/site/docs/main/guides%22%20}%20}%20]%20}`
and confirm Playground loads a markdown file.
@adamziel adamziel merged commit 70a6c2c into trunk Oct 8, 2024
9 checks passed
@adamziel adamziel deleted the support-git-directory-resource branch October 8, 2024 08:31
adamziel added a commit to adamziel/playground-content-converters that referenced this pull request Oct 8, 2024
Replaces the clunky "Zip, unzip, move files" workflow with a direct git clone built on top of WordPress/wordpress-playground#1858. It's so much nicer!
adamziel added a commit that referenced this pull request Oct 8, 2024
GitDirectoryResource was merged in #1858. Unfortunately,
it didn't provide an easy way of saying "checkout all the files from the
repo". This PR adds support for three root path syntaxes:

* `"path": "/"`
* `"path": "."`
* `"path": ""`

 ## Testing instructions

Run this Blueprint locally and confirm it installs the blocky formats
plugin:

```json
{
	"$schema": "https://playground.wordpress.net/blueprint-schema.json",
	"login": true,
	"landingPage": "/wp-admin/",
    "steps": [
        {
            "step": "installPlugin",
            "pluginData": {
                "resource": "git:directory",
                "url": "https://github.com/dmsnell/blocky-formats.git",
                "ref": "trunk",
                "path": "/"
            }
        }
    ]
}
```
adamziel added a commit that referenced this pull request Oct 8, 2024
GitDirectoryResource was merged in
#1858.
Unfortunately, it didn't provide an easy way of saying "checkout all the
files from the repo". This PR adds support for three root path syntaxes:

* `"path": "/"`
* `"path": "."`
* `"path": ""`

 ## Testing instructions

Run this Blueprint locally and confirm it installs the blocky formats
plugin:

```json
{
	"$schema": "https://playground.wordpress.net/blueprint-schema.json",
	"login": true,
	"landingPage": "/wp-admin/",
    "steps": [
        {
            "step": "installPlugin",
            "pluginData": {
                "resource": "git:directory",
                "url": "https://github.com/dmsnell/blocky-formats.git",
                "ref": "trunk",
                "path": "/"
            }
        }
    ]
}
```
adamziel added a commit that referenced this pull request Oct 15, 2024
Makes GitDirectoryResource (introduced in #1858) relay the
requests through `/cors-proxy.php?{url}` instead of
`/cors-proxy.php/{url}`. This makes it compatible with the actual
`cors-proxy.php` script Playground ended up shipping.

 ## Testing instructions

None, this only works in production.
adamziel added a commit that referenced this pull request Oct 15, 2024
Makes GitDirectoryResource (introduced in #1858) relay the requests
through `/cors-proxy.php?{url}` instead of `/cors-proxy.php/{url}`. This
makes it compatible with the actual `cors-proxy.php` script Playground
ended up shipping.

 ## Testing instructions

None, this only works in production. Maybe you could run the Blueprint
from #1858 and
confirm in the network tools that it's actually using the `?` instead of
`/`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant