From 96351a72c07f4f54f10aa3c41c0a24f7d8290493 Mon Sep 17 00:00:00 2001 From: Xiaonan Shen Date: Wed, 15 Apr 2020 04:01:07 -0700 Subject: [PATCH] Add update checker --- .github/workflows/main.yaml | 2 ++ .github/workflows/update-check.yaml | 22 ++++++++++++++++++ Dockerfile | 2 +- check-update.sh | 35 +++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update-check.yaml create mode 100644 check-update.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f8efbf1..20355ef 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -4,6 +4,8 @@ on: push: tags: - '*' + repository_dispatch: + types: update env: DOCKER_TAG: shenxn/protonmail-bridge diff --git a/.github/workflows/update-check.yaml b/.github/workflows/update-check.yaml new file mode 100644 index 0000000..320277d --- /dev/null +++ b/.github/workflows/update-check.yaml @@ -0,0 +1,22 @@ +name: update check + +on: + push: + branches: + - update-check + schedule: + - cron: '0 0 * * *' # runs everyday at midnight + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + with: + ref: master + - name: Check Update + run: bash check-update.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 6d41bfd..c89e93b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:buster-slim +FROM ubuntu:latest LABEL maintainer="Xiaonan Shen " EXPOSE 25/tcp diff --git a/check-update.sh b/check-update.sh new file mode 100644 index 0000000..092e2c5 --- /dev/null +++ b/check-update.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -ex + +source ./releaserc + +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_RELEASE=$(echo $URL | sed -n "s/https:\/\/protonmail.com\/download\/protonmail-bridge_\([0-9.-]*\)_amd64.deb/\1/p") + +if [[ RELEASE != CURR_RELEASE ]]; then + echo "New release found: ${CURR_RELEASE}" + + # bump up to new release + sed -i "s/^RELEASE=.*$/RELEASE=${CURR_RELEASE}/" releaserc + + # commit + git config --local user.email "actions@github.com" + git config --local user.name "Github Action" + git add releaserc + git commit -m "Release ${CURR_RELEASE}" --author="Xiaonan Shen " + git tag -a ${CURR_RELEASE} -m "Release ${CURR_RELEASE}" + + # push + REMOTE_REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" + git push "${REMOTE_REPO}" master + git push "${REMOTE_REPO}" master --tags + + # trigger actions + curl -H "Accept: application/vnd.github.everest-preview+json" \ + -H "Authorization: token ${PERSONAL_TOKEN}" \ + --request POST \ + --data '{"event_type": "update"}' \ + https://api.github.com/repos/${GITHUB_REPOSITORY}/dispatches +fi