auto release

This commit is contained in:
HolographicHat 2022-11-23 14:30:13 +08:00
parent 72e3a00d5a
commit 4000b0bfeb
No known key found for this signature in database
GPG Key ID: 12C8B5B85E5CE5C3
3 changed files with 81 additions and 10 deletions

18
.github/postbuild.js vendored Normal file
View File

@ -0,0 +1,18 @@
const fs = require("fs")
const utils = require("./utils");
(async () => {
try {
const latestVersionInfo = await utils.getAppVersion()
let releaseInfo = await utils.getLatestRelease()
if (releaseInfo.name !== latestVersionInfo["package_version"]) {
releaseInfo = await utils.createRelease(latestVersionInfo["package_version"], undefined)
}
for (const path of fs.readdirSync("out")) {
console.log(`upload ${path}...`)
await utils.uploadReleaseAsset(releaseInfo["upload_url"], path)
}
} catch (e) {
console.log(e)
}
})()

52
.github/utils.js vendored Normal file
View File

@ -0,0 +1,52 @@
const fs = require("fs")
const axios = require("axios").create({
validateStatus: _ => true
})
const repo = "HolographicHat/GetToken"
const token = process.env.GHP_TOKEN
const getAppVersion = async () => {
const latestVersionRsp = await axios.get("https://api-takumi.mihoyo.com/ptolemaios/api/getLatestRelease", {
headers: {
"x-rpc-client_type": "2",
"x-rpc-app_version": "2.37.1",
"x-rpc-channel": "miyousheluodi"
}
})
return latestVersionRsp.data.data
}
const getLatestRelease = async () => {
const repoLatestVersionRsp = await axios.get(`https://api.github.com/repos/${repo}/releases/latest`)
return repoLatestVersionRsp.data.name
}
const createRelease = async (name, desc) => {
const result = await axios.post(`https://api.github.com/repos/${repo}/releases`, {
tag_name: name,
name: name,
body: desc,
generate_release_notes: true
}, {
headers: {
"Authorization": `Bearer ${token}`,
}
})
return result.data
}
const uploadReleaseAsset = async (url, path) => {
const uri = url.substring(0, url.indexOf("{")) + "?name=" + require("path").basename(path)
const size = fs.statSync(path).size
const data = fs.readFileSync(path)
await axios.post(uri, data, {
headers: {
"Content-Type": "application/vnd.android.package-archive",
"Content-Length": `${size}`,
"Authorization": `Bearer ${token}`,
}
})
}
module.exports = { getAppVersion, getLatestRelease, createRelease, uploadReleaseAsset }

View File

@ -12,6 +12,7 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
GHP_TOKEN: ${{ secrets.GHP_TOKEN }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
steps: steps:
@ -30,19 +31,19 @@ jobs:
- name: Install jq - name: Install jq
run: sudo apt-get install -y jq run: sudo apt-get install -y jq
- name: Download package - name: Download package
run: "curl -H 'x-rpc-client_type: 2' -H 'x-rpc-app_version: 2.37.1' -H 'x-rpc-channel: miyousheluodi' https://api-takumi.mihoyo.com/ptolemaios/api/getLatestRelease | jq --raw-output '.data.package_url' | xargs curl -o origin.apk" run: "curl -H 'x-rpc-client_type: 2' -H 'x-rpc-app_version: 2.37.1' -H 'x-rpc-channel: miyousheluodi' https://api-takumi.mihoyo.com/ptolemaios/api/getLatestRelease | jq --raw-output '.data.package_url' | xargs curl -o miyoushe.apk"
- name: Patch package - name: Patch package
run: "mkdir out && mv app/build/outputs/apk/release/app-release.apk out && java -jar gradle/lspatch/jar-v0.5.1-361-release.jar -f -l 2 -m out/app-release.apk -o out/patched.apk origin.apk" run: "mkdir out && mv app/build/outputs/apk/release/app-release.apk . && java -jar gradle/lspatch/jar-v0.5.1-361-release.jar -f -l 2 -m app-release.apk -o out miyoushe.apk && mv app-release.apk out"
- name: Upload build artifacts - name: Upload build artifacts
uses: actions/upload-artifact@v3.1.0 uses: actions/upload-artifact@v3.1.0
with: with:
name: Artifacts name: Artifacts
path: out path: out
#- name: Set up Node 16 - name: Set up Node 16
# uses: actions/setup-node@v3 uses: actions/setup-node@v3
# with: with:
# node-version: 16 node-version: 16
#- name: Install depencies - name: Install dependencies
# run: npm install axios@0.27.2 run: npm install axios@0.27.2
#- name: Run post build script - name: Run post build script
# run: run: node .github/postbuild.js