-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use autogenerated ABI target list (#83)
* feat: use autogenerated ABI target list `yarn update-abi-registry` generates `abi_registry.json`, which is loaded by the module to determine relatively recent ABI targets, along with their LTS values and whether they are "future" targets. * build: auto-update ABI JSON file via scheduled GitHub Action
- Loading branch information
Showing
6 changed files
with
269 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Auto-update ABI JSON file | ||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
jobs: | ||
autoupdate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '12.x' | ||
- name: Get npm cache directory | ||
id: npm-cache | ||
run: | | ||
echo "::set-output name=dir::$(npm config get cache)" | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ${{ steps.npm-cache.outputs.dir }} | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- run: npm install | ||
- name: Update Releases JSON | ||
run: npm run electron-releases | ||
- name: Commit Changes to Releases JSON | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
echo "machine github.com login $GITHUB_ACTOR password $GITHUB_TOKEN" > ~/.netrc | ||
chmod 600 ~/.netrc | ||
git add abi_registry.json | ||
if test -n "$(git status -s)"; then | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | ||
git diff --cached | ||
git commit -m "build: update Electron releases JSON" | ||
git push origin HEAD:$GITHUB_REF | ||
else | ||
echo No update needed | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
[ | ||
{ | ||
"runtime": "node", | ||
"target": "11.0.0", | ||
"lts": false, | ||
"future": false, | ||
"abi": "67" | ||
}, | ||
{ | ||
"runtime": "electron", | ||
"target": "5.0.0", | ||
"lts": false, | ||
"future": false, | ||
"abi": "70" | ||
}, | ||
{ | ||
"runtime": "node", | ||
"target": "12.0.0", | ||
"lts": [ | ||
"2019-10-21", | ||
"2020-10-20" | ||
], | ||
"future": false, | ||
"abi": "68" | ||
}, | ||
{ | ||
"runtime": "electron", | ||
"target": "6.0.0", | ||
"lts": false, | ||
"future": false, | ||
"abi": "73" | ||
}, | ||
{ | ||
"runtime": "electron", | ||
"target": "7.0.0", | ||
"lts": false, | ||
"future": false, | ||
"abi": "75" | ||
}, | ||
{ | ||
"runtime": "electron", | ||
"target": "8.0.0", | ||
"lts": false, | ||
"future": false, | ||
"abi": "76" | ||
}, | ||
{ | ||
"runtime": "node", | ||
"target": "13.0.0", | ||
"lts": false, | ||
"future": false, | ||
"abi": "74" | ||
}, | ||
{ | ||
"runtime": "electron", | ||
"target": "9.0.0-beta.1", | ||
"lts": false, | ||
"future": true, | ||
"abi": "80" | ||
}, | ||
{ | ||
"runtime": "node", | ||
"target": "14.0.0", | ||
"lts": [ | ||
"2020-10-20", | ||
"2021-10-19" | ||
], | ||
"future": true, | ||
"abi": "81" | ||
}, | ||
{ | ||
"runtime": "electron", | ||
"target": "10.0.0-beta.1", | ||
"lts": false, | ||
"future": true, | ||
"abi": "82" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const got = require('got') | ||
const path = require('path') | ||
const semver = require('semver') | ||
const { writeFile } = require('fs').promises | ||
|
||
async function getJSONFromCDN (urlPath) { | ||
const response = await got(`https://cdn.jsdelivr.net/gh/${urlPath}`) | ||
return JSON.parse(response.body) | ||
} | ||
|
||
async function fetchElectronVersions () { | ||
return (await getJSONFromCDN('electron/releases/lite.json')).map(metadata => metadata.version) | ||
} | ||
|
||
async function fetchNodeVersions () { | ||
const schedule = await getJSONFromCDN('nodejs/Release/schedule.json') | ||
const versions = {} | ||
|
||
for (const [majorVersion, metadata] of Object.entries(schedule)) { | ||
if (majorVersion.startsWith('v0')) { | ||
continue | ||
} | ||
const version = `${majorVersion.slice(1)}.0.0` | ||
const lts = metadata.hasOwnProperty('lts') ? [metadata.lts, metadata.maintenance] : false | ||
versions[version] = { | ||
runtime: 'node', | ||
target: version, | ||
lts: lts, | ||
future: new Date(Date.parse(metadata.start)) > new Date() | ||
} | ||
} | ||
|
||
return versions | ||
} | ||
|
||
async function fetchAbiVersions () { | ||
return (await getJSONFromCDN('nodejs/node/doc/abi_version_registry.json')).NODE_MODULE_VERSION | ||
} | ||
|
||
async function main () { | ||
const nodeVersions = await fetchNodeVersions() | ||
const abiVersions = await fetchAbiVersions() | ||
const electronVersions = await fetchElectronVersions() | ||
|
||
const abiVersionSet = new Set() | ||
const supportedTargets = [] | ||
for (const abiVersion of abiVersions) { | ||
if (abiVersion.modules <= 66) { | ||
// Don't try to parse any ABI versions older than 60 | ||
break | ||
} else if (abiVersion.runtime === 'electron' && abiVersion.modules < 70) { | ||
// Don't try to parse Electron ABI versions below Electron 5 | ||
continue | ||
} | ||
|
||
let target | ||
if (abiVersion.runtime === 'node') { | ||
const nodeVersion = `${abiVersion.versions.replace('.0.0-pre', '')}.0.0` | ||
target = nodeVersions[nodeVersion] | ||
if (!target) { | ||
continue | ||
} | ||
} else { | ||
target = { | ||
runtime: abiVersion.runtime === 'nw.js' ? 'node-webkit' : abiVersion.runtime, | ||
target: abiVersion.versions, | ||
lts: false, | ||
future: false | ||
} | ||
if (target.runtime === 'electron') { | ||
target.target = `${target.target}.0.0` | ||
const constraint = /^[0-9]/.test(abiVersion.versions) ? `>= ${abiVersion.versions}` : abiVersion.versions | ||
if (!electronVersions.find(electronVersion => semver.satisfies(electronVersion, constraint))) { | ||
target.target = `${target.target}-beta.1` | ||
target.future = true | ||
} | ||
} | ||
} | ||
target.abi = abiVersion.modules.toString() | ||
|
||
const key = [target.runtime, target.target].join('-') | ||
if (abiVersionSet.has(key)) { | ||
continue | ||
} | ||
|
||
abiVersionSet.add(key) | ||
supportedTargets.unshift(target) | ||
} | ||
|
||
await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2)) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters