jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Jetpack CLI: Add new subcommand and script to rsync plugin files to remote destinations.

Open dereksmart opened this issue 2 years ago • 6 comments

Sometimes I find myself not wanting to use Docker and tunneling. I've also sometimes wanted to develop against a JN site... this makes it pretty easy.

image

Changes proposed in this Pull Request:

New jetpack rsync command for things in projects/plugins.

Jetpack product discussion

Gives more options for developers.

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Rsync different plugins
  • Try jetpack rsync --watch while also jetpack watch plugins/something. Make some changes to JS files. Make some changes to symlinked packages for that plugin. Etc Etc
  • Do all changes make it to the dest as expected?

Spin up a JN site and point the rsync to it? Try all the things.

dereksmart avatar Mar 11 '22 20:03 dereksmart

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • :white_check_mark: Include a description of your PR changes.
  • :warning: All commits were linted before commit.
  • :white_check_mark: Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • :white_check_mark: Add testing instructions.
  • :white_check_mark: Specify whether this PR includes any changes to data or privacy.
  • :white_check_mark: Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation :robot:


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Then, add the "[Status] Needs Team review" label and ask someone from your team review the code. Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.

github-actions[bot] avatar Mar 11 '22 20:03 github-actions[bot]

@anomiex thanks for the great suggestions! Think I'll implement them all.

Also, I'm currently writing a way to store the destination path for easy reuse. Do you have a recommendation where would make sense to store it? Right now it's being stored in /usr/local/bin/rsync-dest/dest-target.txt, and using fs to manage it. I looked at mimicking JT and Docker config storage, but decided not to since it's not actually docker stuff?

dereksmart avatar Mar 14 '22 15:03 dereksmart

I don't think we have any real data storage for the CLI going on yet. There's jetpack draft that creates or removes a .jetpack-draft file in the root dir of the monorepo, that's about it.

anomiex avatar Mar 15 '22 20:03 anomiex

We can also use configstore

import Configstore from 'configstore';

const conf = new Configstore( 'automattic/jetpack-cli' );
conf.set( 'rsync.path', path );
conf.get( 'resync.path' );

kraftbj avatar Mar 17 '22 18:03 kraftbj

Ok it's seeming functional enough for my use case now. @anomiex please tear it apart :)

Also maybe we shouldn't assume the slug on the remote side matches the slug locally?

I still haven't accounted for this, as it's not breaking my use-case. I looked briefly but didn't find any helpers related to this. You know if we have any prior art that would help?

dereksmart avatar Mar 25 '22 12:03 dereksmart

Are you an Automattician? You can now test your Pull Request on WordPress.com. On your sandbox, run bin/jetpack-downloader test jetpack add/jetpack-cli-rsync to get started. More details: p9dueE-5Nn-p2

github-actions[bot] avatar Sep 23 '22 16:09 github-actions[bot]

@anomiex super appreciate all the feedback thus far. I think it's in a pretty good state, though I want to do a little more testing, update the docs, and add some mapping for real plugin slugs (jetpack-backup instead of backup etc). Shouldn't take long but I'm done with my day. Will get the review label up when ready

dereksmart avatar Sep 29 '22 23:09 dereksmart

Tried this out against wpcom, didn't go so well.

$ jetpack rsync jetpack <host>:/home/wpcom/public_html/wp-content/mu-plugins/jetpack-plugin/production/
Destination path is expected to end in a /plugins dir. Got: <host>:/home/wpcom/public_html/wp-content/mu-plugins/jetpack-plugin/production/
[ 'Create new' ]
? Choose destination: Create new
? Input destination path to the plugins dir:  <host>:/home/wpcom/public_html/wp-content/mu-plugins/jetpack-plugin/production
building file list ... 
[ ... synced a bunch of files ... ]

At first there was an unhelpful error message when I included a trailing slash on the path.

And then on wpcom I see this unexpected result:

$ git status
On branch trunk
Your branch is up to date with 'origin/trunk'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	wp-content/mu-plugins/jetpack-plugin/production/jetpack/

anomiex avatar Oct 04 '22 18:10 anomiex

Just spent a good amount of time testing this - JN sites and with the most recent merge, wpcom works great. Let's merge this and we can iterate on it further.

This is really, really cool and closes a big gap!

sdixon194 avatar Oct 07 '22 19:10 sdixon194