From ded640c91b202b751ec8411e69a93e22bd22b9da Mon Sep 17 00:00:00 2001 From: Xiaonan Shen Date: Thu, 19 Nov 2020 20:11:20 -0800 Subject: [PATCH] Fix update checker (#13) --- .github/workflows/update-check.yaml | 6 +++- deb/VERSION | 2 +- deb/update-check.sh | 28 ----------------- update-check.sh | 47 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 30 deletions(-) delete mode 100644 deb/update-check.sh create mode 100644 update-check.sh diff --git a/.github/workflows/update-check.yaml b/.github/workflows/update-check.yaml index 99c3fcf..5e53c66 100644 --- a/.github/workflows/update-check.yaml +++ b/.github/workflows/update-check.yaml @@ -8,6 +8,10 @@ on: paths: - .github/workflows/update-check.yaml - update-check.sh + pull_request: + paths: + - .github/workflows/update-check.yaml + - update-check.sh schedule: - cron: '0 0 * * *' # runs everyday at midnight @@ -20,4 +24,4 @@ jobs: with: token: ${{ secrets.PERSONAL_TOKEN }} - name: Check Update - run: bash update-check.sh + run: bash update-check.sh ${{ github.event_name == 'pull_request' }} diff --git a/deb/VERSION b/deb/VERSION index a0744ce..ba9fc00 100644 --- a/deb/VERSION +++ b/deb/VERSION @@ -1 +1 @@ -1.5.0-1 +1.4.5-1 diff --git a/deb/update-check.sh b/deb/update-check.sh deleted file mode 100644 index c1c4c8d..0000000 --- a/deb/update-check.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -ex - -VERSION=`cat VERSION` - -JSON_CONTENT=$(curl -q https://protonmail.com/download/current_version_linux.json) -URL=$(echo ${JSON_CONTENT} | sed -n "s/^.*\"DebFile\":\"\([a-z0-9:/._-]*\)\".*$/\1/p") -CURR_VERSION=$(echo $URL | sed -n "s/https:\/\/protonmail.com\/.*_\([0-9.-]*\)_.*.deb/\1/p") - -if [[ -z $CURR_VERSION ]]; then - echo "Failed to get new version. Existing." - exit 1 -fi - -if [[ $VERSION != $CURR_VERSION ]]; then - echo "New release found: ${CURR_VERSION}" - - # bump up to new release - echo ${CURR_VERSION} > VERSION - - # commit - git config --local user.email "actions@github.com" - git config --local user.name "Github Action" - git add VERSION - git commit -m "Bump version to ${CURR_VERSION}" --author="Xiaonan Shen " - git push -fi diff --git a/update-check.sh b/update-check.sh new file mode 100644 index 0000000..11622d7 --- /dev/null +++ b/update-check.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -ex + +IS_PULL_REQUEST=$1 + + +check_version() { + DIR=$1 + CURR_VERSION=$2 + + echo "Checking version for ${DIR}" + + VERSION=`cat ${DIR}/VERSION` + + if [[ -z $CURR_VERSION ]]; then + echo "Failed to get new version. Existing." + exit 1 + fi + + if [[ $VERSION != $CURR_VERSION ]]; then + echo "New release found: ${CURR_VERSION}" + + if [[ $IS_PULL_REQUEST == "true" ]]; then + echo "Action triggered by pull request. Do not bump version." + else + # bump up to new release + echo ${CURR_VERSION} > ${DIR}/VERSION + + # commit + git config --local user.email "actions@github.com" + git config --local user.name "Github Action" + git add ${DIR}/VERSION + git commit -m "Bump ${DIR} version to ${CURR_VERSION}" --author="Xiaonan Shen " + git push + fi + else + echo "Already newest version ${VERSION}" + fi + +} + + +JSON_CONTENT=$(curl -q https://protonmail.com/download/current_version_linux.json) +URL=$(echo ${JSON_CONTENT} | sed -n "s/^.*\"DebFile\":\"\([a-z0-9:/._-]*\)\".*$/\1/p") +CURR_VERSION=$(echo $URL | sed -n "s/https:\/\/protonmail.com\/.*_\([0-9.-]*\)_.*.deb/\1/p") +check_version deb $CURR_VERSION