Skip to content

Commit

Permalink
Add headers handling (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
gslama-akqa authored May 1, 2020
1 parent 7dcdeb4 commit efd2dfc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Do you have other Github actions (Lighthouse, Cypress, etc) that depend on the N

**Required** The name of the Netlify site to reach `https://{site_name}.netlify.app`

### `request_headers`

Optional — Stringified HTTP Header object key/value pairs to send in requests (eg. `'{ "Authorization": "Basic YWxhZGRpbjpvcGVuc2VzYW1l }'`)

### `max_timeout`

Optional — The amount of time to spend waiting on Netlify. Defaults to `60` seconds
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
site_name:
description: "The Netlify site name to test against"
required: true
request_headers:
description: "Stringified HTTP Header object key/value pairs to send in requests"
required: false
max_timeout:
description: "The max time to run the action"
required: false
Expand Down
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const core = require("@actions/core");
const github = require("@actions/github");
const axios = require("axios");

const waitForUrl = async (url, MAX_TIMEOUT) => {
const waitForUrl = async (url, MAX_TIMEOUT, { headers }) => {
const iterations = MAX_TIMEOUT / 2;
for (let i = 0; i < iterations; i++) {
try {
await axios.get(url);
await axios.get(url, { headers });
return;
} catch (e) {
console.log("Url unavailable, retrying...");
Expand All @@ -31,8 +31,12 @@ const run = async () => {
}
const url = `https://deploy-preview-${PR_NUMBER}--${siteName}.netlify.app`;
core.setOutput("url", url);
const extraHeaders = core.getInput("request_headers");
const headers = !extraHeaders ? {} : JSON.parse(extraHeaders)
console.log(`Waiting for a 200 from: ${url}`);
await waitForUrl(url, MAX_TIMEOUT);
await waitForUrl(url, MAX_TIMEOUT, {
headers,
});
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit efd2dfc

Please sign in to comment.