themekit icon indicating copy to clipboard operation
themekit copied to clipboard

Detecting remote changes to theme

Open monting opened this issue 9 years ago • 56 comments

One of the biggest pain-points when I work with a Shopify client is:

I have my own deployment process using the CLI, but clients want the flexibility to make changes in the Shopify admin as well. When they make changes and forget to tell me, their changes get overwritten when I deploy. The other way is to download the whole theme and merge the changes into my version control system.

Could we get a feature where we get notified of remote changes to the theme? Maybe check the timestamp of the last remote update compared to a timestamp of last upload kept locally? Ideally we'd be able to know which files were updated remotely.

Thanks for all your work!

monting avatar Feb 04 '17 18:02 monting

Right now what shopify people do is download and find the changes with git. How would you expect all of this to work? If I warned every time the updated files have different timestamps it would be terrible for themes being worked on by teams.

tanema avatar Feb 06 '17 15:02 tanema

@tanema Yea that's exactly what I have to do now - download the whole theme and use git. But downloading the whole theme each time takes a long time and wastes API bandwidth.

What about a command "status" that shows the updated_at attribute of the theme, and the API key/user that made the change? That would be enough for me to script what I need around it.

If we can run that "status" command on individual files, to get that file's list of its older versions + timestamp, that would be amazing.

Again, thanks for your work, and humouring me on discussing this 😃

monting avatar Feb 06 '17 17:02 monting

@NathanPJF @macdonaldr93 Do you have any feelings about this functionality? What I am thinking is maybe a --strict flag on upload/replace that will log an error when the dates are different between client and server. The main problem with this is that editing on the server isn't the only reason file dates would be different. They could be different just because people don't always run watch when they change all files.

tanema avatar Feb 06 '17 18:02 tanema

Tracking the theme file changes with Git is the answer.

I always download the theme before starting my work and before deploying. This way I can see if the store owner (or an app!) made any changes.

illarionvk avatar Feb 07 '17 18:02 illarionvk

Thanks @illarionvk I appreciate extra input!

tanema avatar Feb 07 '17 19:02 tanema

@tanema it feels a bit weird to extend themekit in this way. It's kinda like once we start down this path, we'd have to keep going for it to feel complete which, imo would mean way better git integration for themes and that's another beast to tackle in of itself.

@monting do you usually have the admin open too? I have an internal chrome extension I use that adds the theme id and the last updated information to the theme cards in the admin. Maybe I could look at pulling that functionality out into a little chrome extension and make it public. No promises though haha just an idea.

macdonaldr93 avatar Feb 07 '17 19:02 macdonaldr93

@macdonaldr93 I agree with pretty much everything you said.

I do think though, that being able to check versions/timestamps/previous uploads of a particular file seems to fit into themekit.

E.g. theme versions templates/somefile.html.liquid would list previous uploads with their timestamps. With this feature, I could keep track of timestamps and check for timestamp mismatch in my deploy script.

About the extension - it sounds interesting, but more granular, file specific information would be much more helpful. If I wanted information about the whole theme, I could get it through the shopify api, and then download the whole theme if there's a mismatch. This is kinda my backup plan 😆

monting avatar Feb 07 '17 20:02 monting

Something like this would be really helpful for our deployment process. It seems like it is pretty standard for our clients to be modifying things in the Live theme while we are working on code changes locally. Doing a full theme download every time is feasible but doesn't seem like the best solution. Some of our clients have themes that are over 1 GB in size at this point. Being able to quickly diff the changes between my local copy and the copy in Shopify would be hugely helpful in giving me more confidence in deployments not overwriting something.

Some standardized way to integrate with the Shopify versioning system would be awesome.

calebl avatar Feb 09 '17 18:02 calebl

@calebl What about download only downloading files that do not exist or files that have been updated?

tanema avatar Feb 09 '17 18:02 tanema

@tanema That would be a good start. There is still to possibility that I've changed the same files locally which would necessitate a merge of some kind. It would be really easy for my local files to get overwritten without me realizing it unless I followed a pretty strict process:

  1. make sure I have committed everything locally
  2. create a new branch
  3. download new file changes from theme
  4. merge branches

You can't cover everything, but I would recommend having a confirmation of some kind at least with the download showing the files that will be overwritten to make sure the user knows.

In the ideal world, what I want is a git branch that automatically updates itself from the Shopify theme that I can merge from at well. Ha. This would be pretty simple to setup if theme download only downloaded the difference between the local copy and the copy in Shopify.

calebl avatar Feb 09 '17 19:02 calebl

I still think this is beyond ThemeKit's scope and makes things too complex. In the end, it's down to a strict development process with version control.

My process:

  • Duplicate the live theme
  • Make changes to the duplicated theme using default development environment
  • Track my changes in Git
  • Download the live theme using production environment
  • Merge client's changes, if any
  • Deploy and publish

P.S. I was able to reduce the overall theme size greatly for my clients by using the new "image_picker" setting type.

illarionvk avatar Feb 10 '17 09:02 illarionvk

@illarionvk That's exacly what I did (but I essentially stopped doing it, because it wastes too much time, and is error prone).

I'll give you an example where that process you mentioned doesn't scale. For my client, they have multiple Shopify Plus stores, each serving a different country. All the stores are "compiled" from a single codebase, by a deploy script, allowing for customization of each country's store.

In this case, merging is a pain and error-prone, and I'd have to download from multiple production environments.

Also, it sounds like the frequency with which you deploy at isn't that high? For my client, we sometimes deploy multiple times daily, to multiple stores. Downloading the whole theme each time is excessive.

monting avatar Feb 10 '17 14:02 monting

@illarionvk While I agree that some of what I want is beyond the scope of Themekit, being able to only download the differences between my local folder and the files in a Shopify theme does not seem beyond the scope to me. It seems like it would be beneficial to everyone to cut down on downloading files unnecessarily.

calebl avatar Feb 10 '17 16:02 calebl

@monting That's exactly what I meant when I said it's beyond ThemeKit's scope. 90% of ThemeKit's users will never reach your level of complexity.

@calebl I agree, it might be beneficial to download only the difference between local and remote files. But in this case I'd like to have a good difference check too to avoid uncertainty, and that would be costly to implement.

illarionvk avatar Feb 10 '17 17:02 illarionvk

"90% of ThemeKit's users will never reach your level of complexity." - No argument from me there.

But I do believe that Shopify is heavily investing in its Plus/enterprise product, so I think it makes sense to address the tooling needs of enterprise-level customers, whether that be by Shopify or the OSS community

monting avatar Feb 10 '17 19:02 monting

I would love to find a solution that at least alleviates this issue because it is apparent that this is a situation that most theme developers encounter. I am definitely going to keep this VCS independent and hopefully alleviate this situation for most. I will have to experiment to see what I can do because I am not really sure if VCS's like git have effects on file timestamps when you change branches so I may not be able to depend on file timestamps.

tanema avatar Feb 10 '17 20:02 tanema

Okay so there are a few things about this not working very well.

  • I know git changes file timestamps. This means that any time you checkout another branch it will change the timestamps.
  • There is a problem with just checking the difference of time stamps because it would require you to be strict about checking them before you edit anything which is basically more of a hassle than just creating a branch, downloading and merging. Which is what you would have to do anyways if you forgot to download before you started editing the theme.
  • I could list the assets changed time from the server but not the user who made the change because it is not available through the API (and potentially sensitive data that would not be available to all users).

With all this in consideration I would say you are better off just adding file filters (*.mp4, *.png, *.gif, ect...) so that your largest files that are unlikely to be edited are not downloaded in the process.

I could also add an extra list command that could list the info like @monting originally suggested but I could make it so that it could list themes as well as assets and their updated time. This may be possibly useful but not sure how useful.

tanema avatar Feb 14 '17 15:02 tanema

I don't have the same problem as OP but I'm interested in having some kind of user extension feature. I haven't really thought it through completely, but what do you guys think about something like Git hooks?

Example:

  1. $ theme upload templates/page.liquid
  2. execute some shell script
  3. script returns 0 to continue uploading, else exit

This is my use case:

  1. $ theme watch --env=feature-branch-1
  2. file changes
  3. only upload if the current Git branch is feature-branch-1

sdn90 avatar Feb 15 '17 05:02 sdn90

@tanema It seems like this is not an easy fix. I continue to run into issues though, even if I follow the approach outlined by @illarionvk. When I do a full theme download, git puts the file updated at time as the download time instead of when the file was actually modified. This means it's possible that my local changes (which happened later) do not get merged in properly, meaning I have to be very careful at this point that I'm not losing my changes. Maybe there is no good solution that you can implement to help with this. So far it has forced me to a lot of copying and pasting instead of merging, which means I have a lot less confidence that things are correct.

Is there a way to get notified by the Shopify API when a file has changed? If so, we might be able to use that to keep a local branch up to date with the theme in Shopify.

calebl avatar Feb 15 '17 16:02 calebl

As far as I know, Shopify API has notifications only for theme-level events:

Webhook API reference

illarionvk avatar Feb 15 '17 19:02 illarionvk