Browse Source

Improve the Ubuntu Server linkbot monitoring

Changelog: None
Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
2.6.x
Ole Petter 4 years ago
parent
commit
9520332ed1
No known key found for this signature in database GPG Key ID: 399DBE0F4D4B02EB
  1. 27
      scripts/linkbot/monitor-ub-server.js

27
scripts/linkbot/monitor-ub-server.js

@ -3,6 +3,7 @@ const { JSDOM } = jsdom;
const fs = require('fs')
const { updateURLLink } = require('./common');
const target = "UBUNTU_SERVER_RPI_IMAGE_URL"
const url = "http://cdimage.ubuntu.com/ubuntu/releases/"
const reg = ".*(?<release>[0-9]{2})\.04\.?(?<minor>[0-9]{1})?.*"
@ -10,7 +11,7 @@ const reg = ".*(?<release>[0-9]{2})\.04\.?(?<minor>[0-9]{1})?.*"
try {
const data = fs.readFileSync('../test/run-tests.sh', 'utf8')
.split('\n')
.filter(line => line.match("UBUNTU_SERVER_RPI_IMAGE_URL=.*"))
.filter(line => line.match(`${target}=.*`))
var line = data[0]
var m = line.match(`.*=\"${reg}\"`)
var imageName = m.groups.release
@ -33,14 +34,20 @@ JSDOM.fromURL(url, {}).then(dom => {
return parseInt(b.groups.release) - parseInt(a.groups.release) || parseFloat(b.groups.minor) - parseFloat(a.groups.minor)
})
var matchOn = matches[0].input
if (matchOn !== imageName) {
console.log("We've got a new release! \\o/");
var newLine = ""
if (matches[0].groups.minor) {
newLine = `UBUNTU_SERVER_RPI_IMAGE_URL=\"${url}${matches[0].groups.release}.04.${matches[0].groups.minor}/release/ubuntu-${matches[0].groups.release}.04.${matches[0].groups.minor}-preinstalled-server-armhf+raspi.img.xz\"`
} else {
newLine = `UBUNTU_SERVER_RPI_IMAGE_URL=\"${url}${matches[0].groups.release}.04/release/ubuntu-${matches[0].groups.release}.04-preinstalled-server-armhf+raspi.img.xz\"`
return matchOn;
// Get the release image url from the releases (sub)-page
// const url = "http://cdimage.ubuntu.com/ubuntu/releases/"
}).then(releaseVersion => {
var releaseVersion = releaseVersion.replace(/\s/g, "").replace(/\//g, "")
JSDOM.fromURL(`${url}${releaseVersion}/release/`, {}).then(dom => {
var document = dom.window.document;
var refs = document.getElementsByTagName("a");
const match = Array.from(refs).find(ref => ref.href.match(`.*ubuntu-${releaseVersion}-preinstalled-server-armhf.*\.img\.xz$`))
if (match) {
console.log(`Ubuntu server image has a new release: ${match}`)
updateURLLink(`${target}=${match}`, target)
}
updateURLLink(newLine)
}
})
});

Loading…
Cancel
Save