Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add headers handling #5

Merged
merged 1 commit into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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