Jump to content
vitor

OneUpdater — Update workflows with a single node

Recommended Posts

@nikivi From that screenshot, you’ve downloaded an old version of OneUpdater. Where did you get it from?

 

If you want to distribute the Workflow via github releases, then put the releases page url in workflow_url and change workflow_type to page.

 

If you don’t want to keep making new github releases, do what I do: add the Workflow as any other file in the repo and update that.

Edited by vitor

Share this post


Link to post

I found the workflow in my library. It was this one (https://transfer.sh/LdatR/t-oneupdater.alfredworkflow).


I have updated it though from your github repository. :)

 

I have changed all values, here is the finished version, I hope that works, I can't really test it I think. https://transfer.sh/25Qdk/research.alfredworkflow

 

I like the idea of keeping the .alfredworkflow in the root of the repository. Thank you for your help.

 

Share this post


Link to post
24 minutes ago, nikivi said:

I found the workflow in my library.

 

It can self-update from there by calling :updateoneupdater.

 

24 minutes ago, nikivi said:

I hope that works, I can't really test it I think.

 

You can, by running the workflow and looking at the debugger. Currently, you’ll see [ERROR: action.script] You need to set a workflow version in the configuration sheet.. So you need to fix that. Also, on the remote_plist variable you’re not actually linking to the plist, you’re linking to a github web page. You need to link to the raw file: https://raw.githubusercontent.com/nikitavoloboev/alfred-my-mindmaps/master/info.plist

Edited by vitor

Share this post


Link to post
55 minutes ago, vitor said:

@xilopaint Looking good. Everything seems to be setup correctly.

 

You can, however, simplify the connections on the Workflow itself:

w0yS43H.png

 

I tried to downgrade the version number on configuration sheet to test if OneUpdater does its job and nothing has changed. I may be missing something.

Edited by xilopaint

Share this post


Link to post
12 hours ago, xilopaint said:

I may be missing something.

 

You need to change frequency_check to 0 to test. You have it at 15, meaning it’ll only try to check for updates 15 days from now.

Share this post


Link to post

Update.

  • Add support for notificator.
  • Add support for the newer versions of terminal-notifier, where it is no longer distributed as an app but as a CLI binary.

This only adds new features, so there’s no need to update it in your current workflows.


To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater.
 

Share this post


Link to post

Any chance of shortening the default update interval to a day or two?

 

It seems I always end up downloading the updates manually, as the interval is so long and there's no "check for update now" mechanism :( 

Share this post


Link to post
On 31/07/2017 at 4:55 PM, deanishe said:

Any chance of shortening the default update interval to a day or two?

 

It seems I always end up downloading the updates manually, as the interval is so long and there's no "check for update now" mechanism :( 

 

Sure, I’ll consider it. My though process for the 15 days is something like “after a while it’s so seldom updated, it’s a waste to keep checking frequently”. It’d make sense to have a low limit at first and then bring it up.


Also note I don’t warn of every update on every Workflow. Some are so minor I just release them.


Next time I release an update to a Workflow, I’ll try to remember to shorten the time (no point in doing it now).

Share this post


Link to post

Hey @vitor, would it be possible to change OneUpdater for downloading the workflow file of the latest release instead of the one in the repo? It would be a nice feature that would allow us to keep track of the download count of the latest release of our workflows using the GitHub API.

Share this post


Link to post

@xilopaint Yes. Mind giving some help with testing? Since it’s not the method I use, I need someone else for feedback.

 

Replace the code in your OneUpdater node with this one:

# YOU MUST SET THESE VARIABLES. SEE THE README FOR AN EXPLANATION OF EACH.
readonly remote_info_plist='https://someserver.tld/myworkflow/info.plist'
readonly workflow_url='xilopaint/alfred-things'
readonly download_type='github_release'
readonly frequency_check='0'

# FROM HERE ON, CODE SHOULD BE LEFT UNTOUCHED UNLESS YOU KNOW WHAT YOU ARE DOING!
function abort {
  echo "${1}" >&2
  exit 1
}

function url_exists {
  curl --silent --location --output /dev/null --fail --range 0-0 "${1}"
}

function notification {
  readonly local notificator="$(find . -type d -name 'Notificator.app')"
  if [[ -n "${notificator}" ]]; then
    "${notificator}/Contents/Resources/Scripts/notificator" --message "${1}" --title "${alfred_workflow_name}" --subtitle 'A new version is available'
    return
  fi

  readonly local terminal_notifier="$(find . -type f -name 'terminal-notifier')"
  if [[ -n "${terminal_notifier}" ]]; then
    "${terminal_notifier}" -title "${alfred_workflow_name}" -subtitle 'A new version is available' -message "${1}"
    return
  fi

  osascript -e "display notification \"${1}\" with title \"${alfred_workflow_name}\" subtitle \"A new version is available\""
}

# Local sanity checks
readonly local_info_plist='info.plist'
readonly local_version="$(/usr/libexec/PlistBuddy -c 'print version' "${local_info_plist}")"

[[ -n "${local_version}" ]] || abort 'You need to set a workflow version in the configuration sheet.'
[[ "${download_type}" =~ ^(direct|page|github_release)$ ]] || abort "'download_type' (${download_type}) needs to be one of 'direct', 'page', or 'github_release'."
[[ "${frequency_check}" =~ ^[0-9]+$ ]] || abort "'frequency_check' (${frequency_check}) needs to be a number."

# Check for updates
if [[ $(find "${local_info_plist}" -mtime +"${frequency_check}"d) ]]; then
  if ! url_exists "${remote_info_plist}"; then abort "'remote_info_plist' (${remote_info_plist}) appears to not be reachable."; fi # Remote sanity check

  readonly tmp_file="$(mktemp)"
  curl --silent --location --output "${tmp_file}" "${remote_info_plist}"
  readonly remote_version="$(/usr/libexec/PlistBuddy -c 'print version' "${tmp_file}")"

  if [[ "${local_version}" == "${remote_version}" ]]; then
    touch "${local_info_plist}" # Reset timer by touching local file
    exit 0
  fi

  if [[ "${download_type}" == 'page' ]]; then
    notification 'Opening download page…'
    open "${workflow_url}"
    exit 0
  fi

  download_url="$([[ "${download_type}" == 'github_release' ]] && curl --silent "https://api.github.com/repos/${workflow_url}/releases/latest" | grep 'browser_download_url' | head -1 | sed -E 's/.*browser_download_url": "(.*)"/\1/' || echo "${workflow_url}")"

  if url_exists "${download_url}"; then
    notification 'Downloading and installing…'
    curl --silent --location --output "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow" "${download_url}"
    open "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow"
  else
    abort "'workflow_url' (${download_url}) appears to not be reachable."
  fi
fi

As you can see (you need only care about the top variables, as before), I’ve already set it up to work with your Things workflow, and to check on every run. It should be clear how to change (and to what) to make it work on another Workflow.

Edited by vitor

Share this post


Link to post

Perhaps I am missing something, but wasn't OneUpdater been able to do this before?

 

I have this setup for my OneUpdater objects : 

 

HQD9Ajz.png 

 

And it grabs the update from releases.

Share this post


Link to post
41 minutes ago, nikivi said:

And it grabs the update from releases.

 

Not exactly. What it’s doing in that case (workflow_type='page') is opening the releases page from which the user will have to manually download. With this new change, it directly downloads the URL as if you had input a direct link.

 

2 minutes ago, xilopaint said:

It works perfectly! Thanks!

 

Good to know. Should put out an official release soon (still have to rework the README).

 

Also note that if you add more than one file to the Github releases page, it always gets just the first one.

Share this post


Link to post
1 hour ago, vitor said:

Good to know. Should put out an official release soon (still have to rework the README).

 

This change makes the configuration even more easy.

Edited by xilopaint

Share this post


Link to post
2 minutes ago, nikivi said:

Just a small question. Isn't `


readonly frequency_check='0'

`Too low. Should it be 4 there. Or was it just for example.

 

It was set to 0 for the test so the download action is triggered in the first run.

Share this post


Link to post
36 minutes ago, nikivi said:

Thank you @vitor

 

Works perfectly for me too. I set my interval to 5. I think it's a pretty good interval.

 

You shouldn't have edited your post. I will repost it here for the sake of discussion:

 

Quote

Okay I tested it and it doesn't work for me.


I tried to use it on this workflow. I released new version v1.4.2


And changed current workflow version of the workflow I linked to 1.4.1.


Running the workflow then gets me no update prompt.

 

I downloaded your workflow and didn't manage to update in the first attempts as well (don't have a clue why). After some attempts it started to work. The same thing occurred when I tried to test with my workflow, but I didn't tell anything here because I thought I was missing something.

 

Now I'm afraid there's some unpredictable behaviour with @vitor's implementation of the new feature. I hope I am not misleading here. It's a very welcome feature.

Share this post


Link to post

I think it was because the raw info.plist didn't update instantly. So the version that OneUpdater saw in the raw info.plist was old. I think it was some kind of bug or delay with GitHub.

 

But if the version it reads is correct from that info.plist and is indeed higher than what you have, it will trigger an update. It worked for me in the end. :) 

Edited by nikivi

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...