Skip to content

Modify updater.json with latest release data #4

Modify updater.json with latest release data

Modify updater.json with latest release data #4

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.indexOf('_aarch64.app.tar.gz') > 0) {
name = 'darwin-aarch64';
} else if (asset.name.indexOf('_x64.app.tar.gz') > 0) {
name = 'darwin-x86_64';
} else if (asset.name.indexOf('_x64_en-US.msi.zip') > 0) {
name = 'windows-x86_64';
} else if (asset.name.indexOf('_amd64.AppImage.tar.gz') > 0) {
name = 'linux-x86_64';
}
if (name) {
const url = asset.browser_download_url;
const obj = await github.request(url);
const signature = new TextDecoder().decode(obj.data);
platforms[name] = { url, signature };
}
}
/*
const linuxAssetUrl = assets[1].browser_download_url;
const linuxSigObj = await github.request(assets[2].browser_download_url);
const linuxSignature = new TextDecoder().decode(linuxSigObj.data);
const macAssetUrl = assets[4].browser_download_url;
const macSigObj = await github.request(assets[5].browser_download_url);
const macSignature = new TextDecoder().decode(macSigObj.data);
const winAssetUrl = assets[8].browser_download_url;
const winSigObj = await github.request(assets[9].browser_download_url);
const winSignature = new TextDecoder().decode(winSigObj.data); */
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: {
"updater.json": {
content: newGistContent
}
}
});
} catch (e) {
console.log(e);
}