2020-09-14 12:05:37 +03:00
|
|
|
#!/usr/bin/env node
|
2021-11-08 18:45:29 +03:00
|
|
|
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
|
2021-11-08 18:45:29 +03:00
|
|
|
download the broken mark file.`
|
2020-09-14 12:05:37 +03:00
|
|
|
|
|
|
|
if (process.argv.length != 3) {
|
2021-11-08 18:45:29 +03:00
|
|
|
console.log(usage)
|
|
|
|
process.exit(2)
|
2020-09-14 12:05:37 +03:00
|
|
|
}
|
|
|
|
|
2021-11-08 18:45:29 +03:00
|
|
|
let path = process.argv[2]
|
2020-09-14 12:05:37 +03:00
|
|
|
|
|
|
|
function findBrokenMark(release) {
|
2021-11-08 18:45:29 +03:00
|
|
|
let assets = release['assets']
|
|
|
|
return assets.find(asset => asset['name'] == 'broken')
|
2020-09-14 12:05:37 +03:00
|
|
|
}
|
|
|
|
|
2021-11-08 18:45:29 +03:00
|
|
|
fs.readFile(path, 'utf8', (err, data) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(2)
|
|
|
|
}
|
2020-09-14 12:05:37 +03:00
|
|
|
|
2021-11-08 18:45:29 +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)
|
|
|
|
}
|
|
|
|
})
|