electron / website

:electron: The Electron website
https://electronjs.org
Apache License 2.0
115 stars 126 forks source link

ci: temporary workflow to resolve Electron release versions for PRs #586

Closed dsanders11 closed 3 months ago

dsanders11 commented 3 months ago

This is a temporary workflow in support of @piotrpdev's Google Summer of Code work. Long-term this will be removed from this repo and the code will be refactored to live on electron/release-status, but for now this is the easiest place to put it such that it can be used immediately. Since it is temporary I've kept it isolated entirely to this one file so it doesn't affect anything else in this repo.

Example snippet of how to fetch the content from the latest workflow run is included below. Requires a GitHub token with actions: read perms on electron/website repo.

const AdmZip = require('adm-zip');

const AUTH_HEADER = { Authorization: `Bearer ${ process.env.GH_TOKEN }` };

let resp = await fetch('https://api.github.com/repos/electron/website/actions/artifacts', { headers: AUTH_HEADER });
const latestArtifact = (await resp.json()).artifacts.filter(({ name }) => name === 'resolved-pr-versions').sort((a, b) => a.id > b.id)[0];

resp = await fetch(latestArtifact.archive_download_url, { headers: AUTH_HEADER });
const buffer = Buffer.from(await resp.arrayBuffer());

const zip = new AdmZip(buffer);
const data = JSON.parse(zip.readAsText(zip.getEntries()[0]));