enso/tools/ci/releases/is-broken.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-09-14 12:05:37 +03:00
#!/usr/bin/env node
const fs = require('fs')
2020-09-14 12:05:37 +03:00
let usage = `Usage: is-broken.js PATH
Reads the release metadata at PATH (in JSON format) and checks if it contains
the broken mark. Exit code 0 indicates that the release contains the broken
mark. Other exit codes mean that the release either could not be loaded or is
not marked broken. If the release is marked as broken, it also prints the URL to
download the broken mark file.`
2020-09-14 12:05:37 +03:00
if (process.argv.length != 3) {
console.log(usage)
process.exit(2)
2020-09-14 12:05:37 +03:00
}
let path = process.argv[2]
2020-09-14 12:05:37 +03:00
function findBrokenMark(release) {
let assets = release['assets']
return assets.find(asset => asset['name'] == 'broken')
2020-09-14 12:05:37 +03:00
}
fs.readFile(path, 'utf8', (err, data) => {
if (err) {
console.error(err)
process.exit(2)
}
2020-09-14 12:05:37 +03:00
let release = JSON.parse(data)
let mark = findBrokenMark(release)
if (mark) {
console.error('Release is marked as broken.')
console.log(mark['url'])
process.exit(0)
} else {
console.error('Release is NOT marked as broken.')
process.exit(1)
}
})