whomwah / alfred-github-workflow

An Alfred 5 workflow for working with Github. Uses Deno, written in TypeScript
MIT License
11 stars 1 forks source link

feat: Use script to actually download and install new version #18

Closed whomwah closed 2 years ago

whomwah commented 2 years ago

This now uses a script to attempt to download and install a new version when triggered. Can be improved by only making one api request.

# Inspired by:
# https://github.com/jsumners/alfred-emoji#automatic-updates

# Setting github variables
readonly gh_repo='whomwah/alfred-github-workflow'
readonly gh_url="https://api.github.com/repos/${gh_repo}/releases/latest"

# Fetch latest version
function fetch_remote_version {
  curl --silent "${gh_url}" | grep 'tag_name' | head -1 | sed -E 's/.*tag_name": "v?(.*)".*/\1/'
}

# Fetch download url
function fetch_download_url {
  curl --silent "${gh_url}" | grep 'browser_download_url.*\.alfredworkflow"' | head -1 | sed -E 's/.*browser_download_url": "(.*)".*/\1/'
}

# Download and install workflow
function download_and_install {
  readonly tmpfile="$(mktemp).alfredworkflow"
  echo "Downloading and installing version ${2}…"
  curl --silent --location --output "${tmpfile}" "${1}"
  open "${tmpfile}"
  exit 0;
}
# Setting version and download url for later use
readonly version="$(fetch_remote_version)"
readonly download_url="$(fetch_download_url)"

# Compare current version to installed version and download if required
[ $(printf "%d%03d%03d%03d\n" $(echo ${alfred_workflow_version} | tr '.' ' ')) -lt $(printf "%d%03d%03d%03d\n" $(echo ${version} | tr '.' ' ')) ] && download_and_install ${download_url} ${version}

echo "You are running the latest version (${alfred_workflow_version})
whomwah commented 2 years ago

:tada: This PR is included in version 1.6.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: