Commit 1ddec0d8 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: migrate to CI/CD component

⚠️ requires GitLab 16.6 or later
parent 4ec682d0
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'
+42 −19
Original line number Diff line number Diff line
@@ -6,23 +6,46 @@ This project implements a GitLab CI/CD template to build, test and analyse your

## 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/php/gitlab-ci-php@4.5.0
    # 2: set/override component inputs
    inputs:
      image: "registry.hub.docker.com/library/php:8-apache" # ⚠ 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/php'
    ref: '4.5.0'
    file: '/templates/gitlab-ci-php.yml'

variables:
  # 2: set/override template variables
  PHP_IMAGE: "registry.hub.docker.com/library/php:8-apache" # ⚠ this is only an example
```

## Global configuration

The PHP template uses some global configuration used throughout all jobs.

| Name                  | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| --------------------- | -------------------------------------- | ----------------- |
| `PHP_IMAGE`           | The Docker image used to run PHP <br/>:warning: **set the version required by your project** | `registry.hub.docker.com/library/php:latest` |
| `PHP_PROJECT_DIR`     | The PHP project root directory         | `.`               |
| `image` / `PHP_IMAGE` | The Docker image used to run PHP <br/>:warning: **set the version required by your project** | `registry.hub.docker.com/library/php:latest` |
| `project-dir` / `PHP_PROJECT_DIR` | The PHP project root directory         | `.`               |

## Managing PHP extensions

@@ -62,10 +85,10 @@ is found in the project (`phpunit.xml` or `phpunit.xml.dist`).

It uses the following variable:

| Name                  | Description                              | Default value     |
| Input / Variable | Description                              | Default value     |
| --------------------- | ---------------------------------------- | ----------------- |
| `PHP_UNIT_ARGS`       | Additional PHPUnit [options](https://docs.phpunit.de/en/10.2/textui.html#command-line-options) | _none_ |
| `PHP_UNIT_DISABLED`   | Set to `true` to disable PHPUnit test (if some `phpunit.xml` or `phpunit.xml.dist` file unintentionally triggers the build) | _none_ (auto based on presence of `phpunit.xml` or `phpunit.xml.dist` file) |
| `unit-args` / `PHP_UNIT_ARGS` | Additional PHPUnit [options](https://docs.phpunit.de/en/10.2/textui.html#command-line-options) | _none_ |
| `unit-disabled` / `PHP_UNIT_DISABLED` | Set to `true` to disable PHPUnit test (if some `phpunit.xml` or `phpunit.xml.dist` file unintentionally triggers the build) | _none_ (auto based on presence of `phpunit.xml` or `phpunit.xml.dist` file) |

:warning: in order to be able to compute [code coverage](https://docs.phpunit.de/en/10.2/code-coverage.html),
your project shall have a (dev) dependency to [`php-code-coverage`](https://github.com/sebastianbergmann/php-code-coverage).
@@ -86,10 +109,10 @@ It is bound to the `test` stage, and is **enabled by default**.

It uses the following variable:

| Name                       | Description                              | Default value     |
| Input / Variable | Description                              | Default value     |
| -------------------------- | ---------------------------------------- | ----------------- |
| `PHP_CODESNIFFER_DISABLED` | Set to `true` to disable this job                  | _none_ (enabled)  |
| `PHP_CODESNIFFER_ARGS`     | PHP_CodeSniffer [options](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options) | _none_ |
| `codesniffer-disabled` / `PHP_CODESNIFFER_DISABLED` | Set to `true` to disable this job                  | _none_ (enabled)  |
| `codesniffer-args` / `PHP_CODESNIFFER_ARGS` | PHP_CodeSniffer [options](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options) | _none_ |

You have two options to configure PHP_CodeSniffer for your project:

@@ -133,11 +156,11 @@ This job generates a [SBOM](https://cyclonedx.org/) file listing installed packa

It is bound to the `test` stage, and uses the following variables:

| Name                  | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| --------------------- | -------------------------------------- | ----------------- |
| `PHP_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `PHP_SBOM_VERSION` | The version of @cyclonedx/cyclonedx-php used to emit SBOM | _none_ (uses latest) |
| `PHP_SBOM_OPTS` | [@cyclonedx/cyclonedx-php options](https://github.com/CycloneDX/cyclonedx-php-composer#usage) used for SBOM analysis | _none_ |
| `sbom-disabled` / `PHP_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `sbom-version` / `PHP_SBOM_VERSION` | The version of @cyclonedx/cyclonedx-php used to emit SBOM | _none_ (uses latest) |
| `sbom-opts` / `PHP_SBOM_OPTS` | [@cyclonedx/cyclonedx-php options](https://github.com/CycloneDX/cyclonedx-php-composer#usage) used for SBOM analysis | _none_ |

### `php-outdated` job

@@ -147,9 +170,9 @@ It is bound to the `test` stage, and can be run manually at will.

It uses the following variable:

| Name                | Description                              | Default value     |
| Input / Variable | Description                              | Default value     |
| ------------------- | ---------------------------------------- | ----------------- |
| `PHP_OUTDATED_OPTS` | [`composer outdated` options](https://getcomposer.org/doc/03-cli.md#outdated) | `--direct` |
| `outdated-opts` / `PHP_OUTDATED_OPTS` | [`composer outdated` options](https://getcomposer.org/doc/03-cli.md#outdated) | `--direct` |

### `php-composer-audit` job

@@ -157,7 +180,7 @@ This job performs a vulnerability scan in your dependencies with [`composer audi

It is bound to the `test` stage, and uses the following variables:

| Name                | Description                              | Default value     |
| Input / Variable | Description                              | Default value     |
| ------------------- | ---------------------------------------- | ----------------- |
| `PHP_COMPOSER_AUDIT_DISABLED` | Set to `true` to disable this job | _none_ (enabled) |
| `PHP_COMPOSER_AUDIT_OPTS` | [`composer audit` options](https://getcomposer.org/doc/03-cli.md#audit) | `--locked` |
| `composer-audit-disabled` / `PHP_COMPOSER_AUDIT_DISABLED` | Set to `true` to disable this job | _none_ (enabled) |
| `composer-audit-opts` / `PHP_COMPOSER_AUDIT_OPTS` | [`composer audit` options](https://getcomposer.org/doc/03-cli.md#audit) | `--locked` |
+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": "Build, test and analyse your [PHP](https://www.php.net/) projects",
  "template_path": "templates/gitlab-ci-php.yml",
  "kind": "build",
  "prefix": "php",
  "is_component": true,
  "variables": [
    {
      "name": "PHP_IMAGE",
−7.77 KiB (17.7 KiB)
Loading image diff...
Loading