Commit 6b7e7487 authored by Cédric OLIVIER's avatar Cédric OLIVIER
Browse files

Merge branch 'feat/component' into 'master'

feat: migrate to CI/CD component

See merge request to-be-continuous/lighthouse!6
parents 356d3747 539d32a0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ include:
    file: '/templates/validation.yml'
  - project: 'to-be-continuous/bash'
    ref: '3.3'
    file: 'templates/gitlab-ci-bash.yml'
    file: '/templates/gitlab-ci-bash.yml'
  - project: 'to-be-continuous/semantic-release'
    ref: '3.7'
    file: '/templates/gitlab-ci-semrel.yml'    
+35 −20
Original line number Diff line number Diff line
@@ -4,13 +4,36 @@ This project implements a GitLab CI/CD template to continuously analyse your web

## Usage

In order to include this template in your project, add the following to your `gitlab-ci.yml`:
This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component-in-a-cicd-configuration) 
or using the legacy [`include:project`](https://docs.gitlab.com/ee/ci/yaml/index.html#includeproject) syntax.

### Use as a CI/CD component

Add the following to your `gitlab-ci.yml`:

```yaml
include:
  # 1: include the component
  - component: gitlab.com/to-be-continuous/lighthouse/gitlab-ci-lighthouse@1.1.0
    # 2: set/override component inputs
    inputs:
      review-enabled: true # ⚠ this is only an example
```

### Use as a CI/CD template (legacy)

Add the following to your `gitlab-ci.yml`:

```yaml
include:
  # 1: include the template
  - project: 'to-be-continuous/lighthouse'
    ref: '1.1.0'
    file: '/templates/gitlab-ci-lighthouse.yml'

variables:
  # 2: set/override template variables
  REVIEW_ENABLED: "true" # ⚠ this is only an example
```

## `lighthouse` job
@@ -19,12 +42,12 @@ This job runs the [Lighthouse CI](https://github.com/GoogleChrome/lighthouse-ci)

It uses the following variable:

| Name             | Description                              | Default value     |
| Input / Variable | Description                              | Default value     |
| ---------------- | ---------------------------------------- | ----------------- |
| `LHCI_IMAGE`     | The Docker image used to run Lighthouse CI (use [browser images](https://github.com/cypress-io/cypress-docker-images/tree/master/browsers) only). | `registry.hub.docker.com/cypress/browsers:latest`   |
| `LHCI_VERSION`   | Lighthouse CI version to run | `latest` |
| `LHCI_RUN_OPTS`  | Lighthouse CI [autorun options](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md#autorun) | `--upload.target=filesystem --collect.settings.chromeFlags=\"--no-sandbox\" --collect.url=\"%{environment_url}\"` |
| `REVIEW_ENABLED` | Set to `true` to enable Lighthouse tests on review environments (dynamic environments instantiated on development branches) | _none_ (disabled) |
| `image` / `LHCI_IMAGE` | The Docker image used to run Lighthouse CI (use [browser images](https://github.com/cypress-io/cypress-docker-images/tree/master/browsers) only). | `registry.hub.docker.com/cypress/browsers:latest`   |
| `version` / `LHCI_VERSION` | Lighthouse CI version to run | `latest` |
| `run-opts` / `LHCI_RUN_OPTS` | Lighthouse CI [autorun options](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md#autorun) | `--upload.target=filesystem --collect.settings.chromeFlags=\"--no-sandbox\" --collect.url=\"%{environment_url}\"` |
| `review-enabled` / `REVIEW_ENABLED` | Set to `true` to enable Lighthouse tests on review environments (dynamic environments instantiated on development branches) | _none_ (disabled) |

All the rest of your Lighthouse CI configuration shall be defined either as [`LHCI_` environment variables](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md#environment-variables) 
or in one of the supported [configuration files](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md#configuration-file),
@@ -65,13 +88,9 @@ The easiest solution is to declare all the analysed urls in the `$LHCI_RUN_OPTS`

```yaml
include:
  - project: 'to-be-continuous/lighthouse'
    ref: '1.1.0'
    file: '/templates/gitlab-ci-lighthouse.yml'

variables:
  # pass 3 collect urls, using late %{environment_url} expansion
  LHCI_RUN_OPTS: >- 
  - component: gitlab.com/to-be-continuous/lighthouse/gitlab-ci-lighthouse@1.1.0
    inputs:
      run-opts: >- 
    --upload.target=filesystem 
    --collect.settings.chromeFlags="--no-sandbox"
    --collect.url="%{environment_url}"
@@ -87,13 +106,9 @@ Another option could be to handle it in your JavaScript-based [configuration fil

```yaml
include:
  - project: 'to-be-continuous/lighthouse'
    ref: '1.1.0'
    file: '/templates/gitlab-ci-lighthouse.yml'

variables:
  # remove collect url from lhci autorun options
  LHCI_RUN_OPTS: "--upload.target=filesystem --collect.settings.chromeFlags=--no-sandbox
  - component: gitlab.com/to-be-continuous/lighthouse/gitlab-ci-lighthouse@1.1.0
    inputs:
      run-opts: --upload.target=filesystem --collect.settings.chromeFlags=--no-sandbox
```

`.lighthouserc.js`:
+2 −2
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@ if [[ "$curVer" ]]; then
  log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..."

  # replace in README
  sed -e "s/ref: '$curVer'/ref: '$nextVer'/" README.md > README.md.next
  sed -e "s/ref: *'$curVer'/ref: '$nextVer'/" -e "s/ref: *\"$curVer\”/ref: \”$nextVer\”/" -e "s/component: *\(.*\)@$curVer/component: \1@$nextVer/" README.md > README.md.next
  mv -f README.md.next README.md

  # replace in template and variants
  for tmpl in templates/*.yml
  do
    sed -e "s/\"$curVer\"/\"$nextVer\"/" "$tmpl" > "$tmpl.next"
    sed -e "s/command: *\[\"--service\", \"\(.*\)\", \"$curVer\"\]/command: [\"--service\", \"\1\", \"$nextVer\"]/" "$tmpl" > "$tmpl.next"
    mv -f "$tmpl.next" "$tmpl"
  done
else
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
  "description": "Continuously analyse your web apps and web pages performances and developer best practices with [Lighthouse CI](https://github.com/GoogleChrome/lighthouse-ci)",
  "template_path": "templates/gitlab-ci-lighthouse.yml",
  "kind": "acceptance",
  "prefix": "lhci",
  "is_component": true,
  "variables": [
    {
      "name": "LHCI_IMAGE",
+3.25 KiB (22.8 KiB)
Loading image diff...
Loading