Skip to content

Commit

Permalink
Merge pull request #2 from adevinta/initial-features
Browse files Browse the repository at this point in the history
feat: added initial services and features
  • Loading branch information
dvelasquez authored Jul 1, 2024
2 parents 9b0e490 + dacc9b9 commit ba6175a
Show file tree
Hide file tree
Showing 24 changed files with 4,342 additions and 170 deletions.
3 changes: 2 additions & 1 deletion .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ rules:
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'semi': 'off',
'no-extra-semi': 'off',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
Expand All @@ -65,7 +66,7 @@ rules:
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-var-requires': 'error',
Expand Down
41 changes: 39 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,50 @@ jobs:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- name: Install npm Dependencies
id: npm-ci
run: npm ci

- name: Start Mock Server
id: mock-server
run: |
npm run mock-server &
echo $! > "$(pwd)/mock-server.PID"
sleep 1 # Give it a moment before logging
- name: Wait for Mock Server
run: |
for i in {1..10}; do
echo "Attempt $i"
curl --fail http://localhost:3000/v1/ && echo "Mock server is up" && break || echo "Waiting for mock server..."
sleep 5
done
- name: Verify Mock Server is Up
run: |
curl --fail http://localhost:3000/v1/ || (echo "Mock server not accessible" && exit 1)
- name: Test Local Action
id: test-action
uses: ./
with:
milliseconds: 2000
links-filepath: '.lighthouseci/links.json'
base-url: 'http://localhost:3000/v1'
project-id: 'mock-project-id'
current-commit-sha: '59e778936f40d70edb2af15d61fdeb5cae661649'

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
run: |
echo "${{ steps.test-action.outputs.markdown }}"
echo "${{ steps.test-action.outputs.comparedMetrics }}"
- name: Kill Mock Server
if: always()
run: |
kill "$(cat mock-server.PID)"
5 changes: 5 additions & 0 deletions .lighthouseci/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"https://lhci-lighthouse-ci-comparison-lbc.polaris.ariane.leboncoin.ci/": "https://lhci.bon-coin.net/app/projects/ravnext/compare/53a135c7-fc1e-4d7e-8636-f4a2852b1e6c?compareUrl=https%3A%2F%2Flhci-BRANCH_NAME-lbc.polaris.ariane.leboncoin.ci%2F",
"https://lhci-lighthouse-ci-comparison-lbc.polaris.ariane.leboncoin.ci/_maison_jardin_/offres": "https://lhci.bon-coin.net/app/projects/ravnext/compare/53a135c7-fc1e-4d7e-8636-f4a2852b1e6c?compareUrl=https%3A%2F%2Flhci-BRANCH_NAME-lbc.polaris.ariane.leboncoin.ci%2F_maison_jardin_%2Foffres",
"https://lhci-lighthouse-ci-comparison-lbc.polaris.ariane.leboncoin.ci/classified/latest/12": "https://lhci.bon-coin.net/app/projects/ravnext/compare/53a135c7-fc1e-4d7e-8636-f4a2852b1e6c?compareUrl=https%3A%2F%2Flhci-BRANCH_NAME-lbc.polaris.ariane.leboncoin.ci%2Fclassified%2Flatest%2F12"
}
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.6.0
20.6.0
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,105 @@
# Lighthouse CI Compare Action

[![GitHub Super-Linter](https://github.com/adevinta/actions-lighthouseci-compare/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/adevinta/actions-lighthouseci-compare/actions/workflows/ci.yml/badge.svg)
[![Check dist/](https://github.com/adevinta/actions-lighthouseci-compare/actions/workflows/check-dist.yml/badge.svg)](https://github.com/adevinta/actions-lighthouseci-compare/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/adevinta/actions-lighthouseci-compare/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/adevinta/actions-lighthouseci-compare/actions/workflows/codeql-analysis.yml)
[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)

This action helps you to based on the results of running lighthouse ci, compare
the current results with the ancestor commit results.

This comparison can be used to create a Markdown table and a comment on the pull
request.

## Getting started

### Prerequisites

- You need to have a Lighthouse CI server running.
- You need to have a Lighthouse CI project created.
- You need to have a `links.json` file generated by Lighthouse CI (this action
needs to run after the Lighthouse CI action).

### Usage

```yaml
- name: Lighthouse CI Compare
uses: adevinta/actions-lighthouseci-compare@v1
with:
links-filepath: '.lighthouseci/links.json'
base-url: 'https://your-lhci-server.com/v1'
project-id: 'your-project-id'
current-commit-sha: ${{ github.sha }}
```
## Inputs
### `links-filepath`

- **Description**: The location of the links.json file generated by Lighthouse
CI.
- **Required**: Yes
- **Default**: `.lighthouseci/links.json`

### `base-url`

- **Description**: The base URL of your lighthouse ci server, for example
`https://your-lhci-server.com/v1`.
- **Required**: Yes

### `project-id`

- **Description**: The project ID of your Lighthouse CI project. This is a GUID.
- **Required**: Yes

### `current-commit-sha`

- **Description**: The current commit SHA.
- **Required**: Yes

## Outputs

### `markdown`

This is a Markdown table with the results of the comparison.

The table looks like this:

<!-- markdownlint-disable -->

| URL | Performance | LCP | CLS | TBT | Link to Report |
| :---------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------: | --------------------------------------------------: | ------------------------------------------: | --------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [/](https://lhci-lighthouse-ci-comparison-lbc.polaris.ariane.leboncoin.ci/) | [72/100 🟢](## 'Performance has improved in +0 points') | [1338 ms 🔴](## 'The lcp has increased in +110 ms') | [0.059 🟢](## 'The CLS has decreased in 0') | [1747 ms 🟢](## 'The tbt has decreased in -42 ms') | [Report](https://lhci.bon-coin.net/app/projects/ravnext/compare/53a135c7-fc1e-4d7e-8636-f4a2852b1e6c?compareUrl=https%3A%2F%2Flhci-BRANCH_NAME-lbc.polaris.ariane.leboncoin.ci%2F) |
| [/_maison_jardin_/offres](https://lhci-lighthouse-ci-comparison-lbc.polaris.ariane.leboncoin.ci/_maison_jardin_/offres) | [68/100 🔴](## 'Performance has decreased in -3 points') | [2045 ms 🔴](## 'The lcp has increased in +532 ms') | [0.048 🟢](## 'The CLS has decreased in 0') | [2518 ms 🔴](## 'The tbt has increased in +258 ms') | [Report](https://lhci.bon-coin.net/app/projects/ravnext/compare/53a135c7-fc1e-4d7e-8636-f4a2852b1e6c?compareUrl=https%3A%2F%2Flhci-BRANCH_NAME-lbc.polaris.ariane.leboncoin.ci%2F_maison_jardin_%2Foffres) |
| [/classified/latest/12](https://lhci-lighthouse-ci-comparison-lbc.polaris.ariane.leboncoin.ci/classified/latest/12) | [73/100 🔴](## 'Performance has decreased in -2 points') | [1181 ms 🔴](## 'The lcp has increased in +120 ms') | [0.002 🟢](## 'The CLS has decreased in 0') | [1803 ms 🔴](## 'The tbt has increased in +347 ms') | [Report](https://lhci.bon-coin.net/app/projects/ravnext/compare/53a135c7-fc1e-4d7e-8636-f4a2852b1e6c?compareUrl=https%3A%2F%2Flhci-BRANCH_NAME-lbc.polaris.ariane.leboncoin.ci%2Fclassified%2Flatest%2F12) |

<!-- markdownlint-enable -->

### `comparedMetrics`

This is the object used to create the table. You can use this output to create
your own results or programmatically in a different script.

The object looks like the following:

```js
{
/classified/latest/12:
{ performance:{currentValue:73,previousValue:75,diff:-2,isRegression:true},
lcp:{currentValue:1181,previousValue:1061,diff:120,isRegression:true},
cls:{currentValue:0.002,previousValue:0.002,diff:0,isRegression:false},
tbt:{currentValue:1803,previousValue:1456,diff:347,isRegression:true}},
/_maison_jardin_/offres:
{ performance:{currentValue:68,previousValue:71,diff:-3,isRegression:true},
lcp:{currentValue:2045,previousValue:1513,diff:532,isRegression:true},
cls:{currentValue:0.048,previousValue:0.048,diff:0,isRegression:false},
tbt:{currentValue:2518,previousValue:2260,diff:258,isRegression:true}},
/:
{ performance:{currentValue:72,previousValue:72,diff:0,isRegression:false},
lcp:{currentValue:1338,previousValue:1228,diff:110,isRegression:true},
cls:{currentValue:0.059,previousValue:0.059,diff:0,isRegression:false},
tbt:{currentValue:1747,previousValue:1789,diff:-42,isRegression:false}}}
```

Which includes the URL as the key and the metrics as the value.
12 changes: 12 additions & 0 deletions __tests__/action-run.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path from 'path'
import { executeRun } from '../src/main'
import { InputsInterface } from '../src/types.d'

const inputs: InputsInterface = {
linksFilePath: path.resolve(process.cwd(), '.lighthouseci/links.json'), // Resolve path
baseUrl: 'http://localhost:3000/v1',
projectId: 'mock-project-id',
currentCommitSha: '59e778936f40d70edb2af15d61fdeb5cae661649'
}

executeRun({ inputs, debug: console.log })
Loading

0 comments on commit ba6175a

Please sign in to comment.