enso/tools/ci/releases/add-release.js

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

55 lines
1.2 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: add-release.js PATH TAG [ASSETS...]
Updates the release list at PATH by adding a new release (if it does not exist)
with the provided TAG and list of ASSETS.`
2020-09-14 12:05:37 +03:00
if (process.argv.length < 4) {
console.log(usage)
process.exit(2)
2020-09-14 12:05:37 +03:00
}
let path = process.argv[2]
let tag = process.argv[3]
let assets = process.argv.slice(4)
2020-09-14 12:05:37 +03:00
if (assets.length == 0) {
console.error('Adding a release with no assets.')
2020-09-14 12:05:37 +03:00
}
function releaseAlreadyExists(root, tag) {
let existing = root['releases'].find(release => release['tag'] == tag)
return existing !== undefined
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 root = JSON.parse(data)
if (releaseAlreadyExists(root, tag)) {
console.error(`Release '${tag}' already exists.`)
console.error('No changes written.')
process.exit(1)
}
2020-09-14 12:05:37 +03:00
let release = {
tag: tag,
assets: assets,
2020-09-14 12:05:37 +03:00
}
root['releases'].push(release)
fs.writeFile(path, JSON.stringify(root, null, 1) + '\n', err => {
if (err) {
console.error(err)
process.exit(2)
} else {
console.error(`Added release ${tag} with assets ${assets}.`)
}
})
})