From 29bee51ab6b9b4a106e37fecad66d64cd7da4c43 Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Thu, 24 Nov 2022 12:54:51 +0800 Subject: [PATCH] auto update --- .github/update.js | 13 +++++++++++++ .github/utils.js | 12 +++++++++++- .github/workflows/update.yml | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .github/update.js create mode 100644 .github/workflows/update.yml diff --git a/.github/update.js b/.github/update.js new file mode 100644 index 0000000..012dbab --- /dev/null +++ b/.github/update.js @@ -0,0 +1,13 @@ +const utils = require("./utils"); + +(async () => { + try { + const latestVersionInfo = await utils.getAppVersion() + let releaseInfo = await utils.getLatestRelease() + if (releaseInfo.name !== latestVersionInfo["package_version"]) { + await utils.runWorkflow(41172724) + } + } catch (e) { + console.log(e) + } +})() diff --git a/.github/utils.js b/.github/utils.js index 38b49b6..e6b9bd0 100644 --- a/.github/utils.js +++ b/.github/utils.js @@ -50,4 +50,14 @@ const uploadReleaseAsset = async (url, path) => { }) } -module.exports = { getAppVersion, getLatestRelease, createRelease, uploadReleaseAsset } +const runWorkflow = async id => { + return await axios.post(`https://api.github.com/repos/${repo}/actions/workflows/${id}/dispatches`, { + ref: "master" + }, { + headers: { + "Authorization": `Bearer ${token}`, + } + }) +} + +module.exports = { getAppVersion, getLatestRelease, createRelease, uploadReleaseAsset, runWorkflow } diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..23cfa95 --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,25 @@ +name: Update Check + +on: + schedule: + - cron: '0 12 * * *' + +jobs: + + build: + runs-on: ubuntu-latest + env: + GHP_TOKEN: ${{ secrets.GHP_TOKEN }} + SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} + SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up Node 16 + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Install depencies + run: npm install axios@0.27.2 + - name: Run script + run: node .github/update.js \ No newline at end of file