Skip to content

Commit

Permalink
build(package): ajoute la config pour avoir un package npm
Browse files Browse the repository at this point in the history
  • Loading branch information
thierry behin authored and thierry behin committed Mar 17, 2023
1 parent 62d1ebb commit ec270e1
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 56 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Lint
run: |
npm ci
npm run lint
- name: Test
run: |
npm run test
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Lint
run: |
npm ci
npm run lint
- name: Test
run: |
npm run test
90 changes: 90 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: lighthouse-ecoindex-aggregator

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
skip_ci:
runs-on: ubuntu-latest
outputs:
canSkip: ${{ steps.check.outputs.canSkip }}
steps:
- id: check
uses: Legorooj/skip-ci@main
build:
runs-on: ubuntu-latest
if: ${{ needs.skip_ci.outputs.canSkip != 'true' }}
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.GIT_TOKEN }}

- name: Bump version and push tag
id: tag_version
if: github.ref == 'refs/heads/master'
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/setup-node@v2
with:
node-version: 18

- name: set user name
run: |
git config --global user.email "ci@axa.fr"
git config --global user.name "ci@axa.fr"
- name: npm version ${{ steps.tag_version.outputs.new_tag }}
if: github.ref == 'refs/heads/master'
run: npm version ${{ steps.tag_version.outputs.new_tag }}

- name: npm ci
run: npm ci

- name: npm test
run: npm test -- --runInBand --coverage --watchAll=false

- id: publish-aggregator
uses: JS-DevTools/npm-publish@v1
if: github.ref == 'refs/heads/master'
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./package.json

# - name: SonarCloud Scan
# uses: sonarsource/sonarcloud-github-action@master
# if: github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.head.repo.fork
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# with:
# args: >
# -Dsonar.organization=axaguildev
# -Dsonar.projectKey=AxaGuilDEv_lighthouse-ecoindex-aggregator
# -Dsonar.exclusions=**/*.spec.js,**/*.stories.js,Scripts/**,**/*.scss,**/__snapshots__/**,**/*[Tt]ests.cs,**/node_modules/**,**/ClientApp/build/**,**/ClientApp/.storybook/**,**/ClientApp/storybook-static/**,**/obj/**,**/__mocks__/**,**/ClientApp/src/serviceWorker.ts
# -Dsonar.javascript.lcov.reportPaths=**/coverage/lcov.info

- name: Commit updates package.json
uses: stefanzweifel/git-auto-commit-action@v4
if: github.ref == 'refs/heads/master'
with:
commit_message: "[skip ci] Update version package.json"
commit_user_name: GitHub
commit_user_email: github-action@bot.com
commit_author: GitHub <github-action@bot.com>
push_options: "--force"

- name: Create a GitHub release
uses: ncipollo/release-action@v1
if: github.ref == 'refs/heads/master'
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
"version": "1.0.0",
"description": "Tool for aggregating lighthouse and eco-index results",
"main": "src/cli.js",
"private": false,
"files": [
"src",
"readme.md",
"globalReports.html",
"LICENSE.md",
"package.json",
"package-lock.json",
".eslintrc.js"
],
"scripts": {
"lint": "eslint",
"test": "jest --coverage",
Expand Down
76 changes: 40 additions & 36 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

![image](https://user-images.githubusercontent.com/6480596/213727763-d8cdf611-2b35-4c60-aa94-bd85d5de006c.png)

# Lighthouse EcoIndex Aggregator
Expand All @@ -7,22 +6,24 @@ This generator tool can be used if you need to generate a global reports for all

At the end of the readme, we will explain how to generate the lighthouse and ecoindex tools, used by this aggregator.

## Package

## Options
- lighthouse-eco-index-aggregator [![npm version](https://badge.fury.io/js/lighthouse-eco-index-aggregator.svg)](https://badge.fury.io/js/lighthouse-eco-index-aggregator)

| Nom | Type | Description |
|----------|-------------|------|
| srcEcoIndex | string | Option is used for defined ecoIndex reports path |
| srcLighthouse | string | Option is used for defined lighthouse reports path |
| h | boolean | Option is used for see informations cli |
| reports | string | Option is used for defined format reports after task unique value possible used is "html" |
| lang | string | Option is used for translated report values possible used is "fr-FR" or "en-GB" default is "en-GB"|
| v | boolean | Option is used for verbose task |
| config | string | Option is used for define configuration file |
| pass | number | Option is used for define limit pass |
| fail | number | Option is used for define limit fail |
| m | boolean | Option is used for minify file output it's true by default |
## Options

| Nom | Type | Description |
| ------------- | ------- | -------------------------------------------------------------------------------------------------- |
| srcEcoIndex | string | Option is used for defined ecoIndex reports path |
| srcLighthouse | string | Option is used for defined lighthouse reports path |
| h | boolean | Option is used for see informations cli |
| reports | string | Option is used for defined format reports after task unique value possible used is "html" |
| lang | string | Option is used for translated report values possible used is "fr-FR" or "en-GB" default is "en-GB" |
| v | boolean | Option is used for verbose task |
| config | string | Option is used for define configuration file |
| pass | number | Option is used for define limit pass |
| fail | number | Option is used for define limit fail |
| m | boolean | Option is used for minify file output it's true by default |

## Example usage

Expand All @@ -33,12 +34,14 @@ node ./cli.js --srcLighthouse="C:\Workspace\reports\lighthouse" --srcEcoIndex="
You can also used this module programmatically

```js
const aggregate = require('lighthouse-eco-index-aggregator/src/main');
const aggregate = require("lighthouse-eco-index-aggregator/src/main");

console.log(aggregate({
srcLighthouse: './reports/lighthouse',
srcEcoIndex: './reports/ecoindex'
}))
console.log(
aggregate({
srcLighthouse: "./reports/lighthouse",
srcEcoIndex: "./reports/ecoindex",
})
);
```

## How to generate Lighthouse and EcoIndex reports
Expand All @@ -55,25 +58,26 @@ const ecoIndexOutputPathDir = path.join(__dirname, "reports/ecoindex");
const globalOutputPathDir = path.join(__dirname, "reports");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
on("after:run", async () => {
await aggregate({
reports: "html",
verbose: true,
srcLighthouse: lighthouseOutputPathDir,
srcEcoIndex: ecoIndexOutputPathDir,
outputPath: path.resolve(globalOutputPathDir, "report.html")
});
});
}
}
})
e2e: {
setupNodeEvents(on, config) {
on("after:run", async () => {
await aggregate({
reports: "html",
verbose: true,
srcLighthouse: lighthouseOutputPathDir,
srcEcoIndex: ecoIndexOutputPathDir,
outputPath: path.resolve(globalOutputPathDir, "report.html"),
});
});
},
},
});
```

But in order to generate this global report, we need the lighthouse and ecoindex reports (available in the `lighthouse` and `ecoindex` subfolders. In order to do so, we will use two extra NPM packages :

* [Cypress Audit](https://github.com/mfrachet/cypress-audit) in order to run Lighthouse
* [Eco Index Audit](https://github.com/EmmanuelDemey/eco-index-audit) in order to run EcoIndex.
- [Cypress Audit](https://github.com/mfrachet/cypress-audit) in order to run Lighthouse
- [Eco Index Audit](https://github.com/EmmanuelDemey/eco-index-audit) in order to run EcoIndex.

You will find a sample Cypress tests suite in the `cypress-demo` folder. Please have a look to the `demo.cy.js` and `cypress.config.js`.

Expand All @@ -83,4 +87,4 @@ In order to run the Cypress tests suite, you will execute the following commands
cd cypress-demo
npm i
npx cypress run -b chrome
```
```

0 comments on commit ec270e1

Please sign in to comment.