From 9520332ed18242adb67b4ba52cb10ad28f6955ff Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Tue, 29 Jun 2021 14:56:00 +0200 Subject: [PATCH] Improve the Ubuntu Server linkbot monitoring Changelog: None Signed-off-by: Ole Petter --- scripts/linkbot/monitor-ub-server.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/linkbot/monitor-ub-server.js b/scripts/linkbot/monitor-ub-server.js index 39db954..836166d 100644 --- a/scripts/linkbot/monitor-ub-server.js +++ b/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 = ".*(?[0-9]{2})\.04\.?(?[0-9]{1})?.*" @@ -10,7 +11,7 @@ const reg = ".*(?[0-9]{2})\.04\.?(?[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) - } + }) });