auto update

This commit is contained in:
HolographicHat 2022-11-24 12:54:51 +08:00
parent 881a1d9eb6
commit 29bee51ab6
No known key found for this signature in database
GPG Key ID: 12C8B5B85E5CE5C3
3 changed files with 49 additions and 1 deletions

13
.github/update.js vendored Normal file
View File

@ -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)
}
})()

12
.github/utils.js vendored
View File

@ -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 }

25
.github/workflows/update.yml vendored Normal file
View File

@ -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