Skip to content

Modify updater.json with latest release data #8

Modify updater.json with latest release data

Modify updater.json with latest release data #8

name: Modify updater.json with latest release data
on:
workflow_dispatch:
workflow_call:
jobs:
modify-updater-gist:
name: Modify updater.json gist
runs-on: ubuntu-latest
steps:
- name: update download urls and signatures for updater gist
uses: actions/github-script@v7
env:
updater_gist_id: ${{ secrets.UPDATER_GIST_ID }}
with:
github-token: ${{ secrets.DEV_OPS_BOT_TOKEN }}
script: |
const { data } = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
});
console.log('data', data);
const { name, body, published_at, assets } = data;
const platforms = {};
for (const asset of assets) {
let name;
if (asset.name.endsWith('_aarch64.app.tar.gz') > 0) {
name = 'darwin-aarch64';
} else if (asset.name.endsWith('_x64.app.tar.gz') > 0) {
name = 'darwin-x86_64';
} else if (asset.name.endsWith('_x64_en-US.msi.zip') > 0) {
name = 'windows-x86_64';
} else if (asset.name.endsWith('_amd64.AppImage.tar.gz') > 0) {
name = 'linux-x86_64';
}
if (name) {
const url = asset.browser_download_url;
const sig = assets.find((a) => a.name === asset.name + '.sig');
let signature;
if (sig) {
const obj = await github.request(sig.browser_download_url);
signature = new TextDecoder().decode(obj.data);
}
platforms[name] = { url, signature };
}
}
const notes = body.replace(/ *\([^)]*\)|#|\) */g, '');
const newGistContent = JSON.stringify({
version: name,
notes,
pub_date: published_at,
platforms,
}, null, 2);
try {
await github.rest.gists.update({
gist_id: process.env.updater_gist_id,
files: {
"latest.json": {
content: newGistContent
}
}
});
} catch (e) {
console.log(e);
}