add: getLatestVersion()
This commit is contained in:
parent
e07f1d30e8
commit
457d23d414
3 changed files with 35 additions and 18 deletions
32
get-latest-version.js
Normal file
32
get-latest-version.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
let getLatestVersion = function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// if (typeof milliseconds !== "number") {
|
||||
// throw new Error("milleseconds not a number");
|
||||
// }
|
||||
|
||||
const xmlHttpRequest = new XMLHttpRequest();
|
||||
xmlHttpRequest.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
if (this.response) {
|
||||
const latestURL = this.response["assets"][0].browser_download_url;
|
||||
console.log(latestURL);
|
||||
const latestVersion = latestURL.match(/(\d+).(\d+).(\d+)/g)[0];
|
||||
console.log(latestVersion);
|
||||
return latestVersion;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xmlHttpRequest.open(
|
||||
"GET",
|
||||
"https://api.github.com/repos/gohugoio/hugo/releases/latest",
|
||||
true
|
||||
);
|
||||
xmlHttpRequest.responseType = "json";
|
||||
xmlHttpRequest.send(null);
|
||||
|
||||
resolve(version);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = getLatestVersion;
|
||||
10
index.js
10
index.js
|
|
@ -2,18 +2,14 @@ const core = require("@actions/core");
|
|||
const tc = require("@actions/tool-cache");
|
||||
const io = require("@actions/io");
|
||||
const exec = require("@actions/exec");
|
||||
const getLatestVersion = require("./get-latest-version");
|
||||
|
||||
// most @actions toolkit packages have async methods
|
||||
async function run() {
|
||||
try {
|
||||
let hugoVersion = core.getInput("hugo-version");
|
||||
if (!hugoVersion) {
|
||||
// TODO: get latest version of Hugo
|
||||
// hugoVersion = "latest";
|
||||
hugoVersion = "0.58.2";
|
||||
} else if (hugoVersion === "latest") {
|
||||
// TODO: get latest version of Hugo
|
||||
hugoVersion = "0.58.2";
|
||||
if (!hugoVersion || hugoVersion === "latest") {
|
||||
hugoVersion = getLatestVersion();
|
||||
}
|
||||
core.debug("Hugo version:", hugoVersion);
|
||||
|
||||
|
|
|
|||
11
wait.js
11
wait.js
|
|
@ -1,11 +0,0 @@
|
|||
let wait = function(milliseconds) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof(milliseconds) !== 'number') {
|
||||
throw new Error('milleseconds not a number');
|
||||
}
|
||||
|
||||
setTimeout(() => resolve("done!"), milliseconds)
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = wait;
|
||||
Loading…
Add table
Add a link
Reference in a new issue