StreakyCobra / gws

Colorful KISS helper for git workspaces
https://streakycobra.github.io/gws/
MIT License
235 stars 22 forks source link

offer to download gws script only #46

Closed oupala closed 6 years ago

oupala commented 6 years ago

For version 0.1.8, it was possible to download the gws script only, with a well formed url.

Since version, 0.1.10, we can only download the whole source code, in a zip or in a tar.gz format. It is quite bad as we only need the gws script, not all the test and libs.

Do you think it could be possible to make the gws script available on its own for future versions?

emlun commented 6 years ago

Ah, I see. Sorry, I hadn't even considered that. That can certainly be arranged!

emlun commented 6 years ago

The standalone script is now attached to all releases from 0.1.10 onward, along with a PGP signature. I hope you don't mind I also added the version number to the file name - let me know if that is a problem.

oupala commented 6 years ago

I understand that you added the version number in the filename so that each file can be signed individually.

But would it be possible to propose a standalone script without the version number in the filename? This makes my install process cleaner as my ansible playbook can now check if the file has changed before updating it:

See ansible get_url module:

If dest is a directory, the file will always be downloaded (regardless of the force option), but replaced only if the contents changed..

If yes and dest is not a directory, will download the file every time and replace the file if the contents change. If no, the file will only be downloaded if the destination does not exist.

emlun commented 6 years ago

Hm, I don't think I understand your use case. The whole point of downloading a new version is that the file has definitely changed, no?

oupala commented 6 years ago

Ok, I have to explain a bit more. Maybe you don't have experienced ansible, have you?

There is two way to download a file using the get_url module of ansible:

I really want to use the second solution, but I need the script to be name gws without the version in its name, otherwise, it won't be easy to use.

Is it clearer with these explanations?

This second solution is the only way to achieve idempotency, which is a quite important feature of ansible.

emlun commented 6 years ago

Sorry, no, I have not used ansible. Ok, so if I try to enumerate the different combinations of options, as far as I can tell there are these possible scenarios. I will assume there is some way to substitue a version number into the url option.

  1. url: "https://github.com/StreakyCobra/gws/releases/download/$version/gws-$version", dest: "/usr/bin/"
    • Destination: /usr/bin/gws-$version
    • force ignored
    • Always download the file. Replace only if contents changed.
  2. url: "https://github.com/StreakyCobra/gws/releases/download/$version/gws-$version", dest: "/usr/bin/gws", force: "no"
    • Destination: /usr/bin/gws
    • If destination does not exist, download the file. Otherwise do nothing.
  3. url: "https://github.com/StreakyCobra/gws/releases/download/$version/gws-$version", dest: "/usr/bin/gws", force: "yes"
    • Destination: /usr/bin/gws
    • Always download the file. Replace only if contents changed.
  4. url: "https://github.com/StreakyCobra/gws/releases/download/$version/gws", dest: "/usr/bin/"
    • Destination: /usr/bin/gws
    • force ignored
    • Always download the file. Replace only if contents changed.

I'll assume you want the file to end up at /usr/bin/gws, so option (1) is of course immediately disqualified, and option (2) is disqualified because it would not update the script to new releases. So far so good.

You are proposing option (4). However, I cannot tell a difference in effect between option (4) and option (3). Am I misreading the ansible docs?

Please know that I'm not trying to fight you - I'd be happy to be proven wrong and change my mind on this, but it currently seems to me like what you want to achieve is already possible.

oupala commented 6 years ago

I don't assume that you're trying to fight me. In fact, I do appreciate the way you try to analyze the situation, and possible solutions.

I'll try to explain the differences between (3) and (4).

For (3), replace only if contents changed is false, as force is set to yes, the file will always be downloaded and the ansible task will always be reported as changed, or updated, whatever the file has really changed or not. From an ops view, it becomes hard to guess if the gws script has really changed or not. The task is always reported to be changed.

When an ansible task is idempotent, it is reported as changed the first time it is executed, but it should be reported as ok if the task is executed again. That's why (4) seems to be a better solution for ansible automation.

emlun commented 6 years ago

So are you saying that these two very similar statements in the docs mean different things?

oupala commented 6 years ago

You make me doubt. I'll double check and come back here once tested...

oupala commented 6 years ago

I tested the two usecases and it appears that you were right.

I don't have anything to add except that your last statement was right, and that my task is idempotent.

Here is how I use ansible to install gws (just after installing git) on my servers:

- name: download gws script
  get_url:
    url: "{{ _git.gws_download_url }}"
    dest: /home/{{ _git.user }}/bin/gws
    force: yes
  register: _gws_download_status
  until: _gws_download_status | success
  retries: 3
  delay: 10

Thanks @emlun for finding the best solution with me!

emlun commented 6 years ago

Great! Glad I could help!