Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Fix upgrading #2176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

kenny-evitt
Copy link
Contributor

The goal is to download the appropriate release file for each platform. Currently, the source tarball is being downloaded but that doesn't contain any of the compiled ClojureScript code, so nothing is really upgraded.

This is currently definitely a work-in-progress.

@kenny-evitt
Copy link
Contributor Author

@cldwalker @rundis I've basically got this working. It seems to work entirely on Windows but not on Mac (and I haven't even tested at all on Linux yet).

On my Mac, the code to delete the temp files (the tmp sub-directory and the actual downloaded archive file) is failing (and silently). I'm debugging it now.

I'm also going to separate the current WIP commit into at least two separate commits – the first with just the new Node modules I added. As-is, there are too many files to view the actual code changes in GitHub!

Once I've got the code working for me on all three platforms, then I'll start cleaning up my changes.

'tar-fs' supports passing an 'fs' module explicitly, which is needed to work around Electron patching 'fs' to make '.asar' files behave transparently as native directories (which breaks a lot of code).

'node-stream-zip' is needed to unzip '.zip' release files for upgrading Windows computers.
@kenny-evitt kenny-evitt force-pushed the fix-upgrading branch 3 times, most recently from e6cde6d to a348fbe Compare April 19, 2016 02:09
@kenny-evitt
Copy link
Contributor Author

@cldwalker @rundis I've got this working on all platforms. There's definitely room to cleanup the code. But I'd like to get some feedback from both of you – or at least one of you – before I start working on that.

To test, you can checkout the branch 0.8.0-fix-upgrading-test in my fork and build from source. I cherry-picked my two commits in this PR on top of the code in master as-of the 0.8.0 tag.

@kenny-evitt
Copy link
Contributor Author

Here's the files-changed diffs for just the "WIP" commit (as the other commit only adds files for two Node modules I added).

(-> p
(string/split " ")
(second)))))
;; (defn proxy? []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented this out because it calls tar-path, but that now requires a callback, and I couldn't find any callers of this function anyways.

@kenny-evitt
Copy link
Contributor Author

The shitty change – that I can't figure out how to avoid without even shittier (or much harder) changes – is that I had to explicitly handle .asar files in our (previously) minimally modified shell.js Node module fork.

@kenny-evitt
Copy link
Contributor Author

@cldwalker @rundis This could definitely use a thorough review, ideally from both of you.

@carocad
Copy link

carocad commented Jun 11, 2016

@kenny-evitt: I build LT from the 0.8.0 tag cherry picking the commit WIP and although it correctly builds, I get an error on the console when starting LT. Here is what I've got:

Error: Cannot find module '/home/camilo/Proyectos/LightTable/builds/lighttable-0.8.0-linux/resources/app/core/../core/node_modules/tar-fs'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at lt.util.load.node_module (file:///home/camilo/Proyectos/LightTable/builds/lighttable-0.8.0-linux/resources/app/core/node_modules/lighttable/bootstrap.js:18832:10)
    at file:///home/camilo/Proyectos/LightTable/builds/lighttable-0.8.0-linux/resources/app/core/node_modules/lighttable/bootstrap.js:28913:47

It seems that due to that error LT is completely useless. I can't open workspace nor add folder manually. The search bar barely works and things like "About LT" or the "Plugin manager" don't open either :/

@kenny-evitt
Copy link
Contributor Author

@carocad Thanks! Would you cherry-pick both commits, build, and then try testing the upgrade again please? The error refers to a Node.js package added in the commit prior to the "WIP" commit.

@carocad
Copy link

carocad commented Jun 17, 2016

@kenny-evitt I did as you said. The build process succeds without any problem, LT starts without a problem.
The pop-up requesting me to update LT does work. When I click it I get a text in the console with a git... LT...0.8.1 tar-file download logged out.

But it all ends there :(
After that, there are no more logs, windows or anything like that. I checked the CHANGELOG and it is still 0.8.0, which is quite weird because my pre-built LT did upgraded correctly, so no idea.
Another weird thing is that it requested me to download the javascript plugin which I already had.

A final note: Something not so funny now happens on my normal LT. Everytime that I open my normal LT it asks me to install paredit and rainbow, which I purposely deleted before !
It doesn't matter if I deny the action, next time that I open it, it is there. If you know a way to revert that I would appreciate it. EDIT: I clicked install all plugins, then uninstalled them and the pop-up is no longer on start-up :)

Hope it helps

EDIT2: I was mistaken. The update does succeed !! :D I thought it didn't because there was just no notifo saying anything. After some minutes I got the "Lighttable is updated to its latest and greatest" pop-up.

@kenny-evitt
Copy link
Contributor Author

@carocad Was the CHANGELOG updated? It should include a section for 0.8.1 at the top. And you should have seen a "Light Table has been updated!" popup when the upgrade finished that suggested you restart LT too.

I'll look into this soonish.

@carocad
Copy link

carocad commented Jun 17, 2016

@kenny-evitt yes to all your questions. It works as expected

@kenny-evitt
Copy link
Contributor Author

@carocad Oh! Cool, thanks!

@martinchooooooo
Copy link
Contributor

Hey @kenny-evitt I tested your changes and all looks good to me!

Here's what I did:
git clone git@github.com:kenny-evitt/LightTable.git
git co 0.8.0-fix-upgrading-test
./script/build-app.sh
./builds/lighttable-0.8.0-mac/light

  • Was prompted straight away to update to 0.8.1. Agreed
  • Was prompted that the following plugin dependencies are missing: Javascript 0.2.0. install All.
  • Console printed "https://github.com/LightTable/LightTable/releases/download/0.8.1/lighttable-0.8.1-mac.tar.gz"
  • “Light Table has been updated! …”. Ok
  • Opened File > About.
  • The Changes file shows 0.8.1 with a list of issues, so I guess it went through fine.
  • Ran a quick ‘smoke test’ by opening a CLJ file I commonly use, evaluate how file, tried (+ 2 3) and worked fine. Not the most thorough test, but it works :)

#2193 - Can’t reproduce.
#2136 - Can’t reproduce.
#2131 - Can’t reproduce.

OSX 10.11.5, MBPro Late 2011

@kenny-evitt
Copy link
Contributor Author

@martinchooooooo Thanks!

@sbauer322
Copy link
Contributor

sbauer322 commented Sep 6, 2016

I was able to test this out as well:

Commands to start off:

git clone git@github.com:kenny-evitt/LightTable.git ./kenny-LightTable
cd ./kenny-LightTable
git checkout 0.8.0-fix-upgrading-test
./script/build.sh
./builds/lighttable-0.8.0-linux/light
  • Immediately prompted to update to 0.8.1.
  • Dependencies missing: Clojure 0.3.1, Javascript 0.2.0
  • Console output: https://github.com/LightTable/LightTable/releases/download/0.8.1/lighttable-0.8.1-linux.tar.gz
  • Changelog listed 0.8.1
  • Various simple eval-ing of functions worked
  • Went about my normal development work and no issues encountered

Excellent work @kenny-evitt!

Only comment I can think of is that we should clean up the commented out code and take care of the lingering TODOs introduced in the PR.

@kenny-evitt
Copy link
Contributor Author

@rundis This is a significant enough change that this needs your approval before it can be merged.

We should also decide how to address or resolve (or not) the various points I mentioned in this comment on the issue – #2138 – to which this PR corresponds:

The major change is that we want to download a release file (with the compiled ClojureScript) instead of the source tarball (as the code does now). That's mildly tricky for a few reasons:

  1. There's a separate release for each platform. In the interest of potentially being able to also upgrade Electron itself, I figured we might as well download the relevant release file for the current user.
  2. I'm retrieving the release info from GitHub to retrieve the URLs for the release files so there's a new callback now that propagates thru a few functions just to get that URL. Previously, the URL was very simple to generate.
  3. The Windows release file is a ZIP file so I needed to add a Node module to extract the files. I'm not sure how much we should attempt to avoid this. We could publish .tar.gz release files for Windows because archive utilities, e.g. 7-Zip, can handle them just fine.
  4. Electron patches fs to make .asar files act as directories – this breaks both of the ZIP libraries I tried, probably breaks all ZIP libraries, and it also apparently breaks tar files (tho I haven't confirmed this myself yet). I couldn't get any of the seeming workarounds documented by Electron for forcing Electron to treat an ASAR archive as a normal file to work for me. Others have mentioned needing to use libraries that allow an alternate fs module to be supplied. We can avoid this indefinitely because we don't need to extract the entirety of any of the release archive files – we seem to only need the lighttable-version-platform/resources/app/ directory and the .asar file is in the lighttable-version-platform/resources/ directory. But then we can't really do Electron upgrades per [1].

Related to [2], there's an existing 'edge' setting that seems to control whether the user is running the latest source version. I'm going to defer implementing that for now, but we could potentially use the Travis CI builds to support that.

As-is, I'm going to continue with my current 'solution', i.e. by modifying fetch-and-deploy to call unzip if the platform of the current computer is Windows.

I hazily remember @cldwalker bringing up something about the Node.js packages. I think the first commit in the PR not only adds two packages I used explicitly, but it also included other packages added when I ran npm install. I am very much un-interested in that myself but I'm willing to make changes if anyone else has strong feelings about it.

I also need to do the following before this merged:

  • Cleanup the 'WIP' commit.
  • Rebase master onto this topic branch.

@kenny-evitt
Copy link
Contributor Author

@sbauer322 Thanks for testing this!

v)]
(fetch/xhr release-info-url
{}
(fn [data]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a whole lotta' lets !
How about something like :

(fn [data]
  (->> (-> (js/JSON.parse data)
           (js->clj :keywordize-keys true))
       :assets 
       (filter #(< -1 (.indexOf (:name %) (name platform/platform))))
       first
       :browser_download_url
       cb))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against your suggestion, and it's definitely much more idiomatic Clojure, but it's much harder to read for me. You also subtly changed the behavior; did you deliberately remove using the version (v)? Doing so is probably (?) okay, as I don't think we even have (or want to provide) a way to upgrade to any version that's not the latest, my version was (probably) intended to explicitly use the version specified.

Copy link
Contributor

@sbauer322 sbauer322 Sep 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree this suggestion is harder to read, but feels cleaner once you stare at it for a few minutes. In particular, using the results of -> as the first argument to ->> was initially disorientating.

Maybe use a let binding outside of the ->> instead of:

(-> (js/JSON.parse data)
      (js->clj :keywordize-keys true))

to improve readability?

Not to self-promote poorly written blog posts (of which I am a fine provider of), but I wrote a rather brief guide about arrow macros once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kenny-evitt The v is used for the rest / ajax call, I just didn't bother also using it in the callback traversing the result... as it would be very surprised if we had multiple versioned release artefacts for one release tag.

Both: Yeah I suppose @sbauer322 suggestion is a case where let would help readability.

I'll admit that I use threading quite extensively. Once you get used to them, they read actually quite a lot easier than the normal way to read Clojore/Lisp (inside->out). I think of them like a pipeline which you can just read sequentially.

Anyways I do think that using a let just to set up the following let that sets up the next let etc is a very imperative approach (and all those names doesn't really add that much, because they are just a means to an end - getting that download url. Come to think of it it could be extracted to a separate function) The multiple let approach just doesn't feel particularly functional to me. I guess that was my main point :-)

;; (when (str-contains? p "PROXY")
;; (-> p
;; (string/split " ")
;; (second)))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no biggie, but you don't actually need the parenthesis when threading and the function in question just takes one arg.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I see this is not your doing in the first place...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note also that I'm commenting out this function entirely. My original comment about these changes:

I commented this out because it calls tar-path, but that now requires a callback, and I couldn't find any callers of this function anyways.

@rundis
Copy link
Contributor

rundis commented Sep 11, 2016

@kenny-evitt Maybe this would help with the ASAR stuff ? electron/electron#3641

It would definitely be good if we were also able to make upgrades to Electron itself. Otherwise that will become another source of bitrot too.

@@ -389,8 +389,8 @@ function _rm(options, files) {
// If here, path exists

var stats = fs.statSync(file);
// Remove simple file
if (stats.isFile()) {
// Remove simple file (or Electron package files which 'fs' has been patched by Electron to treat as directories)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that still true with electron/electron#3641 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it's not true with that PR merged. What's weird is that PR was merged on the same date as we last bumped Electron in LT. But we bumped to 0.34.5 and that PR seems to be part of 0.35.3. @sbauer322 might test upgrading to a newer version.

I'll try to do so myself for the changes in this PR too. Given that everyone's going to need to either download the next version or build it themselves from source, upgrading Electron now has no marginal impact. Not having to handle the ASAR workaround should simplify this greatly. Maybe we could even get rid of some other Node.js dependencies.

@rundis
Copy link
Contributor

rundis commented Sep 11, 2016

I hazily remember @cldwalker bringing up something about the Node.js packages. I think the first commit in the PR not only adds two packages I used explicitly, but it also included other packages added when I ran npm install. I am very much un-interested in that myself but I'm willing to make changes if anyone else has strong feelings about it.

Well I do care about dependencies. The fewer the better. I suppose I don't have to mention the left-pad saga with NPM ? There is an npm package for checking whether something is an array or object. That's f*ng oneliners. All these deps are increasing our maintenance burden, bloating the distribution and dumbs us down because we don't care enough about what these things do. It's just a matter of adding a thing to our package.json and behold the internet being pulled down.

I'm going O.T. I'm not saying we should write our own un-taring, but do we need that new dep (and all it's transitives). I'm not sure what's wrong with the one we had. Do we need to keep both ?
Was there any alternatives out there without (that many) transitive deps.

@kenny-evitt
Copy link
Contributor Author

@rundis Thanks for the comments! I'll need some time to go thru them all; at least more thoroughly.

What I meant about the Node.js packages, specifically, was something to do with them being vendored strangely in the repo. I only added two packages and, yes, their dependencies would be expected to be added to the repo too, but there were also other packages added (I think) that are dependencies of other existing packages. I can't find the original conversation, wherever it was, so I don't remember exactly.

I didn't think the packages had that many dependencies but I just checked out the graph for tar-fs:

... and – sigh – you're right that that looks crazy.

@cldwalker cldwalker added this to the 0.8.2 milestone Oct 9, 2016
@sbauer322 sbauer322 added this to Backlog in Technical Debt Apr 17, 2018
@sbauer322 sbauer322 moved this from Backlog to Upgrading/Versioning in Technical Debt Apr 17, 2018
@Mouvedia Mouvedia removed this from the 0.8.2 milestone Feb 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Technical Debt
  
Upgrading/Versioning
Development

Successfully merging this pull request may close these issues.

None yet

8 participants