Skip to content

Commit

Permalink
Merge pull request #94 from jsumners/no-major-upgrade
Browse files Browse the repository at this point in the history
Do not auto-update to new major
  • Loading branch information
jsumners authored Oct 18, 2022
2 parents 680b2ab + a791c80 commit d5576cd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [ master, v1 ]
pull_request:
branches: [ master ]
branches: [ master, v1 ]

jobs:
macosx:
Expand Down
10 changes: 10 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ new release is found, it automatically downloads and installs the latest
version of the workflow. All downloads come directly from official [GitHub
releases][releases].

By default, the update check will occur once per day. You can change the
interval by setting the `update_check_frequency` environment variable in the
[workflow environment variables](https://www.alfredapp.com/help/workflows/advanced/variables/#environment).
The value may be any integer, and it defines the number of days between checks.

If a new major version of the workflow is available, the workflow _will not_ be
automatically updated. Major versions indicate potentially breaking changes
or incompatibilities with older Alfred versions. Instead, a notification will
be shown to remind you to manually update.

## Optional Hotkey and Snippet Triggers

Trigger the workflow with either a custom hotkey or a custom snippet.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.12.0",
"version": "1.12.1",
"scripts": {
"webpack": "webpack",
"clean": "rm -f *.alfredworkflow; rm -rf output/*",
Expand Down
16 changes: 15 additions & 1 deletion src/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# THESE VARIABLES MUST BE SET.
readonly github_repo='jsumners/alfred-emoji'
readonly frequency_check='1' # days
readonly frequency_check=${update_check_frequency:-1} # days

# FROM HERE ON, CODE SHOULD BE LEFT UNTOUCHED!
readonly info_plist='info.plist'
Expand All @@ -17,6 +17,10 @@ function notification {
osascript -e "display notification \"${1}\" with title \"${alfred_workflow_name}\" subtitle \"A new version is available\""
}

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

function fetch_remote_version {
curl --silent "https://api.github.com/repos/${github_repo}/releases/latest" | grep 'tag_name' | head -1 | sed -E 's/.*tag_name": "v?(.*)".*/\1/'
}
Expand All @@ -40,6 +44,16 @@ function download_and_install {

# Check for updates
if [[ $(find "${info_plist}" -mtime +"${frequency_check}"d) ]]; then
REMOTE_VERSION=$(fetch_remote_version)
CURRENT_MAJOR=$(echo "${alfred_workflow_version}" | cut -d'.' -f1)
REMOTE_MAJOR=$(echo "${REMOTE_VERSION}" | cut -d'.' -f1)

if [[ $(echo "${REMOTE_MAJOR} > ${CURRENT_MAJOR}") -eq 1 ]]; then
semver_major_notification "alfred-emoji ${REMOTE_VERSION} is available. You have ${alfred_workflow_version}."
touch "${info_plist}"
exit 0
fi

if [[ "${alfred_workflow_version}" == "$(fetch_remote_version)" ]]; then
touch "${info_plist}" # Reset timer by touching local file
exit 0
Expand Down

0 comments on commit d5576cd

Please sign in to comment.