Skip to content

Commit efd2dfc

Browse files
authored
Add headers handling (#5)
1 parent 7dcdeb4 commit efd2dfc

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Do you have other Github actions (Lighthouse, Cypress, etc) that depend on the N
88

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

11+
### `request_headers`
12+
13+
Optional — Stringified HTTP Header object key/value pairs to send in requests (eg. `'{ "Authorization": "Basic YWxhZGRpbjpvcGVuc2VzYW1l }'`)
14+
1115
### `max_timeout`
1216

1317
Optional — The amount of time to spend waiting on Netlify. Defaults to `60` seconds

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ inputs:
77
site_name:
88
description: "The Netlify site name to test against"
99
required: true
10+
request_headers:
11+
description: "Stringified HTTP Header object key/value pairs to send in requests"
12+
required: false
1013
max_timeout:
1114
description: "The max time to run the action"
1215
required: false

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ const core = require("@actions/core");
22
const github = require("@actions/github");
33
const axios = require("axios");
44

5-
const waitForUrl = async (url, MAX_TIMEOUT) => {
5+
const waitForUrl = async (url, MAX_TIMEOUT, { headers }) => {
66
const iterations = MAX_TIMEOUT / 2;
77
for (let i = 0; i < iterations; i++) {
88
try {
9-
await axios.get(url);
9+
await axios.get(url, { headers });
1010
return;
1111
} catch (e) {
1212
console.log("Url unavailable, retrying...");
@@ -31,8 +31,12 @@ const run = async () => {
3131
}
3232
const url = `https://deploy-preview-${PR_NUMBER}--${siteName}.netlify.app`;
3333
core.setOutput("url", url);
34+
const extraHeaders = core.getInput("request_headers");
35+
const headers = !extraHeaders ? {} : JSON.parse(extraHeaders)
3436
console.log(`Waiting for a 200 from: ${url}`);
35-
await waitForUrl(url, MAX_TIMEOUT);
37+
await waitForUrl(url, MAX_TIMEOUT, {
38+
headers,
39+
});
3640
} catch (error) {
3741
core.setFailed(error.message);
3842
}

0 commit comments

Comments
 (0)