Skip to content

Commit

Permalink
improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseykulikov committed Nov 25, 2019
1 parent 1240c56 commit 5e11f28
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 31 deletions.
8 changes: 4 additions & 4 deletions .github/lighthouse/budget.json
Expand Up @@ -4,19 +4,19 @@
"resourceSizes": [
{
"resourceType": "document",
"budget": 14
"budget": 60
},
{
"resourceType": "script",
"budget": 12
"budget": 40
},
{
"resourceType": "stylesheet",
"budget": 5
"budget": 10
},
{
"resourceType": "total",
"budget": 300
"budget": 600
}
]
}
Expand Down
Expand Up @@ -3,8 +3,8 @@
"assert": {
"preset": "lighthouse:recommended",
"assertions": {
"render-blocking-resources": ["warn", {"numericValue": 0}]
"first-contentful-paint": ["error", { "minScore": 0.6 }]
}
}
}
}
}
Expand Up @@ -6,4 +6,4 @@
}
}
}
}
}
@@ -1,5 +1,5 @@
# This is an advanced fully hermetic run of Lighthouse, using custom config.
name: LHCI-hermetic-advanced
name: LHCI-advanced-config
on: push
jobs:
hermetic-advanced:
Expand All @@ -9,8 +9,8 @@ jobs:
- name: Run Lighthouse on urls with lighthouserc
uses: ./
with:
urls: 'https://alekseykulikov.com/'
configPath: '.github/lighthouse/lighthouserc_custom_config.json'
urls: 'https://example.com/'
configPath: '.github/lighthouse/lighthouserc-custom-config.json'
- name: Save .lighthouseci artifacts
uses: actions/upload-artifact@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/LHCI-assert-on-budget.yml
Expand Up @@ -9,5 +9,5 @@ jobs:
- name: Run Lighthouse on urls and validate with budgets.json
uses: ./
with:
urls: 'https://alekseykulikov.com/'
urls: 'https://treo.sh/'
budgetPath: '.github/lighthouse/budget.json'
7 changes: 4 additions & 3 deletions .github/workflows/LHCI-assert-on-lighthouserc.yml
@@ -1,13 +1,14 @@
# This pass/fails a build with LHCI assertions via an rc-file.
name: LHCI-assert-on-lighthouserc
on: push
jobs:
# This pass/fails a build with LHCI assertions via an rc-file.
assert-on-lighthouserc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run Lighthouse on urls and validate with lighthouserc
uses: ./
with:
urls: 'https://exterkamp.codes/'
configPath: '.github/lighthouse/lighthouserc_assertions.json'
urls: 'https://example.com/'
runs: 3
configPath: '.github/lighthouse/lighthouserc-assertions.json'
3 changes: 2 additions & 1 deletion .github/workflows/LHCI-static-dist-dir.yml
Expand Up @@ -9,4 +9,5 @@ jobs:
- name: Run Lighthouse against a static dist dir
uses: ./
with:
configPath: '.github/lighthouse/lighthouserc_static_dist_dir.json'
# no urls needed, since it uses local folder to scan .html files
configPath: '.github/lighthouse/lighthouserc-static-dist-dir.json'
@@ -1,5 +1,5 @@
# This is a basic Lighthouse run over multiple URLs that uses temporary-public-storage.
name: LHCI-multiple-urls
name: LHCI-temporary-storage
on: push
jobs:
multiple-urls:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/LHCI-urls-interpolation.yml
@@ -0,0 +1,16 @@
# Interpolate URLs with env variables.
name: LHCI-urls-interpolation
on: push
jobs:
multiple-urls:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run Lighthouse on multiple URLs and interpolate env variables.
uses: ./
with:
urls: |
https://$DOMAIN/
https://$DOMAIN/demo
env:
DOMAIN: treo.sh
17 changes: 7 additions & 10 deletions CONTRIBUTING.md
Expand Up @@ -20,29 +20,26 @@ yarn test
INPUT_URLS="https://example.com/" INPUT_RUNS="1" node src/index.js

# run many urls
INPUT_URLS="https://alekseykulikov.com/
https://alekseykulikov.com/blog" INPUT_RUNS="1" node src/index.js

# fail with budget
INPUT_URLS="https://alekseykulikov.com/" INPUT_BUDGETPATH=".github/lighthouse/impossible_budget.json" INPUT_RUNS="1" node src/index.js
INPUT_URLS="https://example.com/
https://example.com/blog" INPUT_RUNS="1" node src/index.js

# fail with assertions
INPUT_URLS="https://alekseykulikov.com/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc_assertions.json" INPUT_RUNS="1" node src/index.js
INPUT_URLS="https://example.com/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-assertions.json" INPUT_RUNS="1" node src/index.js

# run with custom config
INPUT_URLS="https://alekseykulikov.com/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc_custom_config.json" INPUT_RUNS="1" node src/index.js
INPUT_URLS="https://example.com/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-custom-config.json" INPUT_RUNS="1" node src/index.js

# run with Chrome flags
INPUT_URLS="https://alekseykulikov.com/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc_chrome_flags.json" INPUT_RUNS="1" node src/index.js
INPUT_URLS="https://example.com/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-chrome-flags.json" INPUT_RUNS="1" node src/index.js

# debug custom headers
python script/simple-server.py # start basic server in a separate tab
INPUT_URLS="http://localhost:3000/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc_extra_headers.json" INPUT_RUNS="1" node src/index.js # run and see headers output
INPUT_URLS="http://localhost:3000/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-extra-headers.json" INPUT_RUNS="1" node src/index.js # run and see headers output

# run locally, with env var interpolation
python script/simple-server.py # start basic server in a separate tab
PAGE="src/" INPUT_URLS="http://localhost:3000/\$PAGE" INPUT_RUNS="1" node src/index.js

# run with a static dist dir
INPUT_CONFIGPATH=".github/lighthouse/lighthouserc_static_dist_dir.json" INPUT_RUNS="1" node src/index.js
INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-static-dist-dir.json" INPUT_RUNS="1" node src/index.js
```
15 changes: 10 additions & 5 deletions README.md
Expand Up @@ -62,7 +62,7 @@ URLs support interpolation of process env vars so that you can write URLs like:
PR_NUMBER: ${{ github.event.pull_request.number }}
```

[⚙️ See this workflow in use](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-multiple-urls)
[⚙️ See this workflow in use](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-urls-interpolation)

> **Note**: to view the reports download the JSON files from the artifacts and open them with the [Lighthouse Viewer App](https://googlechrome.github.io/lighthouse/viewer/) or follow the `temporary-public-storage` link printed in the action.
Expand All @@ -88,7 +88,7 @@ All results are private by default. Use this option to upload reports to LHCI's
temporaryPublicStorage: true
```

[⚙️ See an example workflow in use](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-temporary-storage)
[⚙️ See an example workflow with this option](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-temporary-storage)

#### `runs` (default: 1)

Expand All @@ -111,6 +111,8 @@ Learn more about the [budget.json spec](https://github.com/GoogleChrome/budget.j
budgetPath: ./budget.json
```

[⚙️ See an example workflow with this option](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-assert-on-budget)

#### `configPath`

Set a path to a custom [lighthouserc file](https://github.com/GoogleChrome/lighthouse-ci/blob/master/docs/cli.md#configuration) for full control of the Lighthouse environment and assertions.
Expand All @@ -121,6 +123,8 @@ Use `lighthouserc` to configure the collection of data (via Lighthouse config an
configPath: ./lighthouserc.json
```

[⚙️ See an example workflow with this option](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-assert-on-lighthouserc)

#### `upload`

Upload Lighthouse results to a private [LHCI server](https://github.com/GoogleChrome/lighthouse-ci) by specifying both `upload.serverBaseUrl` and `upload.token`.
Expand All @@ -135,7 +139,7 @@ upload.token: ${{ secrets.LHCI_TOKEN }}

Specify an API token for the LHCI server. [Learn how to generate a token](https://github.com/GoogleChrome/lighthouse-ci/blob/master/docs/getting-started.md#historical-reports--diffing-lighthouse-ci-server).

[⚙️ See an example workflow in use](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-upload-to-private-server)
[⚙️ See an example workflow with this option](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-upload-to-private-server)

## Recipes

Expand Down Expand Up @@ -224,7 +228,7 @@ Make a `lighthouserc.json` file with [LHCI assertion syntax](https://github.com/
"ci": {
"assert": {
"assertions": {
"first-contentful-paint": ["error", { "minScore": 0.8 }]
"first-contentful-paint": ["error", { "minScore": 0.6 }]
}
}
}
Expand Down Expand Up @@ -342,7 +346,7 @@ module.exports = {
}
```

[⚙️ See this workflow in use](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-hermetic-advanced)
[⚙️ See this workflow in use](https://github.com/treosh/lighthouse-ci-action/actions?workflow=LHCI-advanced-config)

</details>

Expand All @@ -365,6 +369,7 @@ jobs:
- name: Run Lighthouse against a static dist dir
uses: treosh/lighthouse-ci-action@v2
with:
# no urls needed, since it uses local folder to scan .html files
configPath: './lighthouserc.json'
```

Expand Down

0 comments on commit 5e11f28

Please sign in to comment.