mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-01-24 20:12:15 +01:00
Refactor: Get the latest version from Homebrew (#28)
Refactoring * feat: Add reject to Promise * feat: Add printing inputs * feat: Add error handling to getLatestVersion() * feat: show version of Hugo, Go, and Git (Close #23) * refactor: Get the latest version from Homebrew (Close #26) * refactor: enhance error message of promise reject Enhancement for workflow * gha: Add deps (test-prod job needs test job) * gha: Fix matrix testing * gha: comment out Build production step * gha: remove Dump step Update README * docs: update readme
This commit is contained in:
@@ -1,22 +1,18 @@
|
||||
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
||||
|
||||
function getLatestVersion() {
|
||||
// return new Promise((resolve, reject) => {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
const url = "https://api.github.com/repos/gohugoio/hugo/releases/latest";
|
||||
const url = "https://formulae.brew.sh/api/formula/hugo.json";
|
||||
xhr.open("GET", url);
|
||||
xhr.send();
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
const result = JSON.parse(xhr.responseText);
|
||||
const latestURL = result["assets"][0].browser_download_url;
|
||||
const latestVersion = latestURL.match(/(\d+).(\d+).(\d+)/g)[0];
|
||||
|
||||
const latestVersion = result.versions.stable;
|
||||
resolve(latestVersion);
|
||||
// } else {
|
||||
// reject(`ERROR: got status ${xhr.status}`);
|
||||
} else if (xhr.readyState === 4 && xhr.status !== 200) {
|
||||
reject(`ERROR: got status ${xhr.status} of ${url}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user