Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: v4 #14

Merged
merged 30 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
661311d
feat: update the definition
Apr 26, 2023
73790b9
docs: update README
Jul 30, 2023
03ee088
feat: update action description
Jul 30, 2023
891b55d
feat: update Dockerfile: add Heart complete installation
Jul 30, 2023
8a60cfe
feat: remove Heart installation from entrypoint, as thez full install…
Jul 30, 2023
8e76292
feat: add the verbose option
Aug 6, 2023
dd612f4
feat: use the test Heart Docker image
Aug 6, 2023
a679781
feat: add the verbose mode
Aug 6, 2023
c39115a
chore: remove useless files and ignored files as we are using the new…
Aug 6, 2023
beb9943
refactor: remove the use of Heart image to reduce complexity
Aug 7, 2023
5351944
fix: update the config path if the config is an existing file
Aug 7, 2023
f5f8563
refactor: restore the use of Heart image, as an error was in it
Aug 8, 2023
a2162c4
fix: syntax
Aug 8, 2023
5c7b23a
docs: fix examples syntax
Aug 8, 2023
c8bf078
ci: add a lint check on PRs
Aug 9, 2023
90cc0b2
feat: reduce the set of installable dependencies
Aug 9, 2023
6d5e0b4
docs: remove falsy comment
Aug 9, 2023
32fe8c2
ci: setup custom Markdown lint
Aug 9, 2023
cc81497
ci: fix filename
Aug 9, 2023
1256a1e
ci: add exception for a tag
Aug 9, 2023
87feb7a
docs: fix lint
Aug 9, 2023
bf1c87b
refactor: use the proper Heart image tag
Aug 10, 2023
ed0c62e
fix: base image repository
Aug 16, 2023
bd48be6
docs: fix action version
Aug 16, 2023
95093cc
docs: fix mysql_database_url example value
Aug 16, 2023
d3ea819
feat: use stable version 4
Oct 8, 2023
d0fb7ae
fix: prefix environment variables with HEART_
Oct 8, 2023
cf015b1
feat: fix variable name
Oct 8, 2023
59b851e
fix: remove versions pin in apt-get, as dependencies version can be r…
Oct 8, 2023
73df185
docs:fix Slack acccess token variable name
Oct 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 🧹 Lint

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
lint:
name: Lint codebase
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Lint Dockerfile
uses: hadolint/[email protected]

- name: Lint GitHub workflows
run: |
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
./actionlint -color
shell: bash

- name: Lint Markdown
uses: DavidAnson/markdownlint-cli2-action@v11
with:
config: .markdownlint.yaml
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
node_modules/
.env
package*.json
3 changes: 3 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignored:
# Disable pin versions in apt get install, as versions can disappear from the registry
- "DL3008"
10 changes: 10 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Default state for all rules
default: true
# Line length
MD013:
code_blocks: false
# Inline HTML
MD033:
allowed_elements: ["a", "img", "p"]
# First line in a file should be a top-level heading
MD041: false
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

37 changes: 10 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
# use a Node.js image with Chrome installed, because @fabernovel/heart-lighthouse requires an external Chrome installation.
# use the latest Node.js LTS instead of Node.js 14 (which is the version supported by Heart) because of
# an unresolvable bug with node-gyp during installation with Node.js 14 / NPM 6.
FROM timbru31/node-chrome:18
FROM fabernovel/heart:v4.0.0

# weird missing library with @fabernovel/heart-greenit (maybe because of an outdated Chromium version):
# Error: Failed to launch the browser process!
# /node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
RUN apt-get update && \
apt-get -yq install libx11-xcb1

# set environment variable to make the @fabernovel/heart-lighthouse module work
ENV CHROME_PATH=/usr/bin/google-chrome-stable
# set bash as the default shell
SHELL ["/bin/bash", "-c"]

# lighter setup that could only work when @fabernovel/heart-lighthouse will rely on an "internal" browser (probably v4).
# by using pupeeter/chromium like @fabernovel/heart-greenit already does, there will be no need to install an external version of Chrome.
#
# FROM node:18
#
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
# RUN apt-get update && \
# apt-get -yq install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils
# As the config can be a file on the user's repository, we need git to retrieve it
RUN apt-get update && \
apt-get -yq --no-install-recommends install \
ca-certificates \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Uncomment the next 2 lines for local development
# WORKDIR /usr/app
# COPY ./ /usr/app
COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

# set bash as the default shell
SHELL ["/bin/bash", "-c"]

95 changes: 57 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,78 @@

# Heart: evaluate webpages

Evaluate webpages directly from your CI with [Google Lighthouse](https://pagespeed.web.dev/), <a href="https://www.ecoindex.fr/" hreflang="fr">GreenIT</a>, [Mozilla Observatory](https://observatory.mozilla.org/) or [SSLLabs Server](https://www.ssllabs.com/ssltest/).
Evaluate webpages directly from your CI with [Google Lighthouse](https://pagespeed.web.dev/),
<a href="https://www.ecoindex.fr/" hreflang="fr">GreenIT</a>,
[Mozilla Observatory](https://observatory.mozilla.org/)
or [SSLLabs Server](https://www.ssllabs.com/ssltest/).

Retrieve the evaluations in a [Slack](https://slack.com/) channel or in a [Google Bigquery](https://cloud.google.com/bigquery]) database.
Retrieve the evaluations in a [MySQL](https://www.mysql.com/) database
or in a [Slack](https://slack.com/) channel.

This GitHub Action make use of the CLI tool [Heart](https://heart.fabernovel.com).

## Usage

```yaml
- uses: faberNovel/heart-action@v1
- uses: faberNovel/heart-action@v4
with:
# [Required]
# Service name that analyze the URL.
# Available values: greenit,lighthouse,observatory,ssllabs-server
analysis_service: observatory
# Available values: greenit, lighthouse, observatory, ssllabs-server.
analysis_service: lighthouse

# [Required]
# Set the JSON configuration used by the analysis service, either with a file path OR an inline string.
# Configuration used by the analysis service. File path to a JSON file or JSON-inlined string.
# The configuration format depends of each service, and is detailed in the READMEs of Heart: https://github.com/faberNovel/heart/tree/master/modules
# Example for the Mozilla Observatory service: https://github.com/faberNovel/heart/tree/master/modules/heart-observatory
file: conf/observatory.json
inline: '{"host":"heart.fabernovel.com"}'
# Example for the Google Lighthouse service: https://github.com/faberNovel/heart/tree/master/modules/lighthouse.
config: conf/lighthouse.json OR '{"url":"heart.fabernovel.com"}'

# [Optional]
# Check if the score of the result reaches the given threshold (between 0 and 100).
threshold: 80

# [Optional]
# Services names that process the result of the analyze, separated by commas.
# Available values: bigquery,slack
listener_services: slack
# Comma-separated list of listener services that will not be triggered once the analysis is done.
# This parameter is mutually exclusive with the listener_services_only one.
# Available values: mysql, slack.
listener_services_except: slack

# [Optional]
# Only required if you use "bigquery" as a listener_services
google_application_credentials: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
# Comma-separated list of listener services that will be triggered once the analysis is done.
# This parameter is mutually exclusive with the listener_services_except one.
# Available values: mysql, slack.
listener_services_only: mysql,slack

# [Optional]
# If you use your own instance of Mozilla Observatory, use this setting to set the server API URL.
# Only required if you you use "mysql" as a listener_services_except or listener_services_only.
# Location and credentials of your MySQL database, in a URL format.
mysql_database_url: login:[email protected]:3306

# [Optional]
# Only required if you you use "observatory" as analysis_service.
# Location of the Observatory API.
# See https://github.com/mozilla/http-observatory#creating-a-local-installation-tested-on-ubuntu-15
observatory_api_url: https://http-observatory.security.mozilla.org/api/v1/

# [Optional]
# If you use your own instance of Mozilla Observatory, use this setting to set the website URL.
# Only required if you you use "observatory" as analysis_service.
# Location of the Observatory website to view the the results.
# See https://github.com/mozilla/http-observatory#creating-a-local-installation-tested-on-ubuntu-15
observatory_analyze_url: https://observatory.mozilla.org/analyze/

# [Optional]
# Only required if you you use "slack" as a listener_services
slack_api_token: ${{ secrets.SLACK_API_TOKEN }}
# Only required if you you use "slack" as a listener_services_except or listener_services_only.
# Slack access token.
slack_access_token: ${{ secrets.SLACK_ACCESS_TOKEN }}

# [Optional]
# Only required if you you use "slack" as a listener_services_except or listener_services_only.
# Slack channel where the analysis results will be send.
slack_channel_id: 'heart'

# [Optional]
# Customize the Slack channel where the notifications are send (default: #heart)
slack_channel_id: '#heart-analysis'
# Display additional information when running Heart
verbose: false
```

## Examples
Expand All @@ -74,12 +93,12 @@ jobs:
name: 🔬 Analyse heart.fabernovel.com with Mozilla Observatory

steps:
- uses: faberNovel/heart-action@v1
- uses: faberNovel/heart-action@v4
with:
analysis_service: observatory
inline: '{"host":"heart.fabernovel.com"}'
config: '{"host":"heart.fabernovel.com"}'
listener_services: slack
slack_api_token: ${{ secrets.SLACK_API_TOKEN }}
slack_access_token: ${{ secrets.SLACK_ACCESS_TOKEN }}

```

Expand Down Expand Up @@ -109,12 +128,12 @@ jobs:
]

steps:
- uses: faberNovel/heart-action@v1
- uses: faberNovel/heart-action@v4
with:
analysis_service: lighthouse
file: ${{ matrix.lighthouse_configuration }}
config: ${{ matrix.lighthouse_configuration }}
listener_services: slack
slack_api_token: ${{ secrets.SLACK_API_TOKEN }}
slack_access_token: ${{ secrets.SLACK_ACCESS_TOKEN }}
# prevent jobs from being blocked by a previous failed job.
continue-on-error: true

Expand All @@ -134,24 +153,24 @@ jobs:
name: 🔬 Analyze with GreenIT

steps:
- uses: faberNovel/heart-action@v1
- uses: faberNovel/heart-action@v4
with:
analysis_service: greenit
file: analysis/conf/greenit.json
config: analysis/conf/greenit.json
listener_services: slack
slack_api_token: ${{ secrets.SLACK_API_TOKEN }}
slack_access_token: ${{ secrets.SLACK_ACCESS_TOKEN }}

lighthouse:
runs-on: ubuntu-latest
name: 🔬 Analyze with Google Lighthouse

steps:
- uses: faberNovel/heart-action@v1
- uses: faberNovel/heart-action@v4
with:
analysis_service: lighthouse
file: analysis/conf/lighthouse.json
config: analysis/conf/lighthouse.json
listener_services: slack
slack_api_token: ${{ secrets.SLACK_API_TOKEN }}
slack_access_token: ${{ secrets.SLACK_ACCESS_TOKEN }}

```

Expand Down Expand Up @@ -181,12 +200,12 @@ jobs:
]

steps:
- uses: faberNovel/heart-action@v1
- uses: faberNovel/heart-action@v4
with:
analysis_service: greenit
file: ${{ matrix.greenit_configuration }}
config: ${{ matrix.greenit_configuration }}
listener_services: slack
slack_api_token: ${{ secrets.SLACK_API_TOKEN }}
slack_access_token: ${{ secrets.SLACK_ACCESS_TOKEN }}
# prevent jobs from being blocked by a previous failed job.
continue-on-error: true

Expand All @@ -207,12 +226,12 @@ jobs:
]

steps:
- uses: faberNovel/heart-action@v1
- uses: faberNovel/heart-action@v4
with:
analysis_service: lighthouse
file: ${{ matrix.lighthouse_configuration }}
config: ${{ matrix.lighthouse_configuration }}
listener_services: slack
slack_api_token: ${{ secrets.SLACK_API_TOKEN }}
slack_access_token: ${{ secrets.SLACK_ACCESS_TOKEN }}
# prevent jobs from being blocked by a previous failed job.
continue-on-error: true

Expand Down
62 changes: 33 additions & 29 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,68 @@ inputs:
analysis_service:
description: |
Service name that analyze the URL.
Available values: dareboost, greenit, lighthouse, observatory, ssllabs-server
Available values: greenit, lighthouse, observatory, ssllabs-server.
required: true
default: ''
file:
description: Set the file path to the JSON configuration used by the analysis service.
required: false
default: ''
inline:
description: Set the inline string of the JSON configuration used by the analysis service.
required: false
config:
description: Configuration used by the analysis service. File path to a JSON file or JSON-inlined string.
required: true
default: ''
threshold:
description: Check if the score of the result reaches the given threshold (between 0 and 100).
required: false
default: ''
listener_services:
listener_services_except:
description: |
Services names that process the result of the analyze, separated by commas.
Available values: bigquery, slack
Comma-separated list (without spaces) of listener services that will not be triggered once the analysis is done.
This parameter is mutually exclusive with the listener_services_only one.
Available values: mysql, slack.
required: false
default: ''
dareboost_api_token:
description: Dareboost API token
listener_services_only:
description: |
Comma-separated list (without spaces) of listener services that will be triggered once the analysis is done.
This parameter is mutually exclusive with the listener_services_except one.
Available values: mysql, slack
required: false
default: ''
google_application_credentials:
description: Google Service account
mysql_database_url:
description: Location and credentials of your MySQL database, in a URL format.
required: false
default: ''
observatory_api_url:
description: Location of the Observatory API
description: Location of the Observatory API.
required: false
default: ''
observatory_analyze_url:
description: Location of the Observatory website that provides the results
description: Location of the Observatory website to view the the results.
required: false
default: ''
slack_api_token:
description: Slack API token
slack_access_token:
description: Slack access token.
required: false
default: ''
slack_channel_id:
description: Slack channel where the analysis results will be send
description: Slack channel where the analysis results will be send.
required: false
default: ''
verbose:
description: Displays debug information
required: false
default: ''
runs:
using: docker
image: Dockerfile
args:
- ${{ inputs.analysis_service }}
- ${{ inputs.file }}
- ${{ inputs.inline }}
- ${{ inputs.config }}
- ${{ inputs.threshold }}
- ${{ inputs.listener_services }}
- ${{ inputs.listener_services_except }}
- ${{ inputs.listener_services_only }}
- ${{ inputs.verbose }}
env:
DAREBOOST_API_TOKEN: ${{ inputs.dareboost_api_token }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ inputs.google_application_credentials }}
OBSERVATORY_API_URL: ${{ inputs.observatory_api_url }}
OBSERVATORY_ANALYZE_URL: ${{ inputs.observatory_analyze_url }}
SLACK_API_TOKEN: ${{ inputs.slack_api_token }}
SLACK_CHANNEL_ID: ${{ inputs.slack_channel_id }}
HEART_MYSQL_DATABASE_URL: ${{ inputs.mysql_database_url }}
HEART_OBSERVATORY_API_URL: ${{ inputs.observatory_api_url }}
HEART_OBSERVATORY_ANALYZE_URL: ${{ inputs.observatory_analyze_url }}
HEART_SLACK_ACCESS_TOKEN: ${{ inputs.slack_access_token }}
HEART_SLACK_CHANNEL_ID: ${{ inputs.slack_channel_id }}
Loading