mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-01-24 20:12:15 +01:00
add: about GitHub API Rate limiting
This commit is contained in:
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
@@ -30,8 +30,10 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
hugo-version: [null, 'latest', '0.58.2']
|
||||
extended: [null, false, true]
|
||||
hugo-version: [null, '0.58.2']
|
||||
# hugo-version: [null, 'latest', '0.58.2']
|
||||
extended: [null, true]
|
||||
# extended: [null, false, true]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
||||
|
||||
function getLatestVersion() {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
const url = "https://api.github.com/repos/gohugoio/hugo/releases/latest";
|
||||
xhr.open("GET", url);
|
||||
@@ -15,11 +15,11 @@ function getLatestVersion() {
|
||||
|
||||
resolve(latestVersion);
|
||||
} else {
|
||||
throw new Error(`ERROR: got status ${xhr.status}`);
|
||||
// reject(`ERROR: got status ${xhr.status}`);
|
||||
reject(`ERROR: got status ${xhr.status}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = getLatestVersion;
|
||||
v
|
||||
74
index.js
74
index.js
@@ -6,39 +6,49 @@ const getLatestVersion = require("./get-latest-version");
|
||||
// most @actions toolkit packages have async methods
|
||||
async function run() {
|
||||
try {
|
||||
getLatestVersion().then(async function(latestVersion) {
|
||||
let hugoVersion = core.getInput("hugo-version");
|
||||
if (!hugoVersion || hugoVersion === "latest") {
|
||||
hugoVersion = latestVersion;
|
||||
getLatestVersion().then(
|
||||
async function(latestVersion) {
|
||||
let hugoVersion = core.getInput("hugo-version");
|
||||
if (!hugoVersion || hugoVersion === "latest") {
|
||||
hugoVersion = latestVersion;
|
||||
}
|
||||
core.debug(`Hugo version: ${hugoVersion}`);
|
||||
|
||||
let extended = core.getInput("extended");
|
||||
core.debug(`Hugo extended: ${extended}`);
|
||||
|
||||
let extendedStr = "";
|
||||
if (extended === "true") {
|
||||
extendedStr = "extended_";
|
||||
}
|
||||
|
||||
console.log(`Operating System: ${process.platform}`);
|
||||
|
||||
const hugoName = `hugo_${extendedStr}${hugoVersion}_Linux-64bit`;
|
||||
core.debug(`hugoName: ${hugoName}`);
|
||||
|
||||
const hugoURL = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/${hugoName}.tar.gz`;
|
||||
core.debug(`hugoURL: ${hugoURL}`);
|
||||
|
||||
const hugoPath = "/home/runner/bin";
|
||||
await io.mkdirP(hugoPath);
|
||||
core.addPath(hugoPath);
|
||||
|
||||
// Download and extract Hugo binary
|
||||
const hugoTarball = await tc.downloadTool(hugoURL);
|
||||
const hugoExtractedFolder = await tc.extractTar(hugoTarball, "/tmp");
|
||||
core.debug("hugoExtractedFolder:", hugoExtractedFolder);
|
||||
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
|
||||
},
|
||||
function(error) {
|
||||
console.error(error);
|
||||
console.log(
|
||||
"HINT: GitHub API Rate limiting\n" +
|
||||
" https://developer.github.com/v3/#rate-limiting\n" +
|
||||
" Use a specific version of Hugo"
|
||||
);
|
||||
}
|
||||
core.debug(`Hugo version: ${hugoVersion}`);
|
||||
|
||||
let extended = core.getInput("extended");
|
||||
core.debug(`Hugo extended: ${extended}`);
|
||||
|
||||
let extendedStr = "";
|
||||
if (extended === "true") {
|
||||
extendedStr = "extended_";
|
||||
}
|
||||
|
||||
console.log(`Operating System: ${process.platform}`);
|
||||
|
||||
const hugoName = `hugo_${extendedStr}${hugoVersion}_Linux-64bit`;
|
||||
core.debug(`hugoName: ${hugoName}`);
|
||||
|
||||
const hugoURL = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/${hugoName}.tar.gz`;
|
||||
core.debug(`hugoURL: ${hugoURL}`);
|
||||
|
||||
const hugoPath = "/home/runner/bin";
|
||||
await io.mkdirP(hugoPath);
|
||||
core.addPath(hugoPath);
|
||||
|
||||
// Download and extract Hugo binary
|
||||
const hugoTarball = await tc.downloadTool(hugoURL);
|
||||
const hugoExtractedFolder = await tc.extractTar(hugoTarball, "/tmp");
|
||||
core.debug("hugoExtractedFolder:", hugoExtractedFolder);
|
||||
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
|
||||
});
|
||||
);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user