Skip to content

Commit

Permalink
feat: adding key param for psi API key - #5 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonJang authored Apr 12, 2021
1 parent 32350dc commit 62436cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ This action utilizes [Google's Page Speed Insights](https://developers.google.co

**Required** The name of the site to reach `https://google.com`

### `key`

Optional - API key (recommended for production) to use when consuming the Page Speed Insights API. This should be stored as a [Github Secret](https://docs.github.com/en/actions/reference/encrypted-secrets). You can request a key [here](https://developers.google.com/speed/docs/insights/v5/get-started)

### `strategy`

Optional — Strategy to use when analyzing the page (mobile/desktop).
Expand All @@ -31,4 +35,5 @@ steps:
url: "https://jake.partus.ch"
threshold: 70
strategy: mobile
key: ${{ secrets.APIKEY }}
```
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ inputs:
description: "Score to pass the PageSpeed test. Useful for setting a performance budget (default 70)."
strategy:
description: "Strategy to use when analyzing the page (mobile/desktop)."
key:
description: "A PageSpeed Insights API key"
runs:
using: "node12"
main: "index.js"
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ const run = async () => {
core.setFailed("Url is required to run Page Speed Insights.");
return;
}

const key = core.getInput('key');

const threshold = Number(core.getInput("threshold")) || 70;
const strategy = core.getInput("strategy") || "mobile";
// Output a formatted report to the terminal
console.log(`Running Page Speed Insights for ${url}`);
await psi.output(url, {
nokey: "true",
...(key ? {key} : undefined),
...(key ? undefined : {nokey: "true"}),
strategy,
format: "cli",
threshold
Expand Down

0 comments on commit 62436cf

Please sign in to comment.