Commit d8bc8bd9 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: migrate to CI/CD component

⚠️ requires GitLab 16.6 or later
parent 29393628
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'
+48 −25
Original line number Diff line number Diff line
@@ -4,27 +4,50 @@ 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` (replace `__VERSION__` with the adequate version):
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/gradle/gitlab-ci-gradle@2.5.0
    # 2: set/override component inputs
    inputs:
      image: "registry.hub.docker.com/library/gradle:jdk11" # ⚠ 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/gradle'
    ref: '2.5.0'
    file: '/templates/gitlab-ci-gradle.yml'

variables:
  # 2: set/override template variables
  GRADLE_IMAGE: "registry.hub.docker.com/library/gradle:jdk11" # ⚠ this is only an example
```

## Global configuration

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

| Name                    | Description                                                                                                                                                                            | Default value             |
| Input / Variable | Description                                                                                                                                                                            | Default value             |
| ----------------------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
| `GRADLE_IMAGE`          | The Docker image used to run Gradle <br/>:warning: **set the version required by your project**                                                                                        | `registry.hub.docker.com/library/gradle:latest`           |
| `GRADLE_CLI_OPTS`       | Additional Gradle options used on the command line                                                                                                                                     | `None`                    |
| `GRADLE_CLI_BIN`        | The location of the gradle binary. If you prefer using a [gradle wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) you should override this (for e.g. `gradlew`) | `gradle`                  |
| `GRADLE_USER_HOME`      | The gradle user home                                                                                                                                                                   | `$CI_PROJECT_DIR/.gradle` |
| `GRADLE_DAEMON`         | Whether to use or not gradle daemon                                                                                                                                                    | `false`                   |
| `GRADLE_PROJECT_DIR`    | Gradle project root directory                                                                                                                                                          | `.`                       |
| `image` / `GRADLE_IMAGE` | The Docker image used to run Gradle <br/>:warning: **set the version required by your project**                                                                                        | `registry.hub.docker.com/library/gradle:latest`           |
| `cli-opts` / `GRADLE_CLI_OPTS` | Additional Gradle options used on the command line                                                                                                                                     | `None`                    |
| `cli-bin` / `GRADLE_CLI_BIN` | The location of the gradle binary. If you prefer using a [gradle wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) you should override this (for e.g. `gradlew`) | `gradle`                  |
| `user-home` / `GRADLE_USER_HOME` | The gradle user home                                                                                                                                                                   | `$CI_PROJECT_DIR/.gradle` |
| `daemon` / `GRADLE_DAEMON` | Whether to use or not gradle daemon                                                                                                                                                    | `false`                   |
| `project-dir` / `GRADLE_PROJECT_DIR` | Gradle project root directory                                                                                                                                                          | `.`                       |

As you can see the `GRADLE_USER_HOME` is set to a directory inside `$CI_PROJECT_DIR`. This will allow you to do some gradle caching
(declared in all gradle jobs) but also to provide a custom `gradle.properties` file in your directory.
@@ -64,9 +87,9 @@ for test jobs dependency reasons.

It uses the following variable:

| Name                   | Description                               | Default value     |
| Input / Variable | Description                               | Default value     |
| ---------------------- | ----------------------------------------- | ----------------- |
| `GRADLE_BUILD_ARGS`    | Gradle arguments for the build & test job | `build`           |
| `build-args` / `GRADLE_BUILD_ARGS` | Gradle arguments for the build & test job | `build`           |

#### About Code Coverage

@@ -100,9 +123,9 @@ By adding the plugin, the template will automatically add `jacocoTestReport` and

The jacoco coverage display in gitlab uses the following variable

| Name                       | Description                                         | Default value          |
| Input / Variable | Description                                         | Default value          |
| -------------------------- | --------------------------------------------------- | ---------------------- |
| `JACOCO_CSV_REPORT`    | Name of report                                          | `jacocoTestReport.csv` |
| `jacoco-csv-report` / `JACOCO_CSV_REPORT` | Name of report                                          | `jacocoTestReport.csv` |

### `gradle-sonar` job — SonarQube analysis

@@ -110,12 +133,12 @@ This job is **disabled by default** and performs a SonarQube analysis of your co

The job is bound to the `test` stage and uses the following variables:

| Name                     | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| ------------------------ | -------------------------------------- | ----------------- |
| `SONAR_HOST_URL`         | SonarQube server url                   | _none_ (disabled) |
| `sonar-host-url` / `SONAR_HOST_URL` | SonarQube server url                   | _none_ (disabled) |
| :lock: `SONAR_TOKEN`     | SonarQube authentication [token](https://docs.sonarqube.org/latest/user-guide/user-token/) | _none_ |
| `SONAR_BASE_ARGS`        | SonarQube [analysis arguments](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) | `sonar -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues` |
| `SONAR_QUALITY_GATE_ENABLED` | Set to `true` to enable SonarQube [Quality Gate](https://docs.sonarqube.org/latest/user-guide/quality-gates/) verification.<br/>_Uses `sonar.qualitygate.wait` parameter ([see doc](https://docs.sonarqube.org/latest/analysis/ci-integration-overview/#header-1))._ | _none_ (disabled) |
| `sonar-base-args` / `SONAR_BASE_ARGS` | SonarQube [analysis arguments](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) | `sonar -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues` |
| `sonar-quality-gate-enabled` / `SONAR_QUALITY_GATE_ENABLED` | Set to `true` to enable SonarQube [Quality Gate](https://docs.sonarqube.org/latest/user-guide/quality-gates/) verification.<br/>_Uses `sonar.qualitygate.wait` parameter ([see doc](https://docs.sonarqube.org/latest/analysis/ci-integration-overview/#header-1))._ | _none_ (disabled) |

### Dependency-check

@@ -123,10 +146,10 @@ The Gradle template features a job `gradle-dependency-check` that performs a man

It is bound to the `test` stage and use the following variable :

| Name                          | Description                                   | Default value          |
| Input / Variable | Description                                   | Default value          |
| ----------------------------- | --------------------------------------------- | ---------------------- |
| `GRADLE_DEPENDENCY_CHECK_DISABLED` | Set to `true` to disable this job        | _none_ (enabled) |
| `GRADLE_DEPENDENCY_CHECK_TASK` | Name of the gradle task launching the analysis | `dependencyCheckAnalyze` |
| `dependency-check-task` / `GRADLE_DEPENDENCY_CHECK_TASK` | Name of the gradle task launching the analysis | `dependencyCheckAnalyze` |

A Dependency-Check is a quite long operation and therefore the job is configured to be ran __manually__ by default (overridable).

@@ -243,10 +266,10 @@ This job generates a [SBOM](https://cyclonedx.org/) file listing all dependencie

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

| Name                  | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| --------------------- | -------------------------------------- | ----------------- |
| `GRADLE_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `GRADLE_SBOM_VERSION` | Version of the `cyclonedx-gradle-plugin` used for SBOM analysis<br/>_When unset, the latest version will be used_ | _none_ |
| `sbom-disabled` / `GRADLE_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `sbom-version` / `GRADLE_SBOM_VERSION` | Version of the `cyclonedx-gradle-plugin` used for SBOM analysis<br/>_When unset, the latest version will be used_ | _none_ |

This job injects cyclonedx plugin in your project. This can be disabled by defining the plugin in your `build.gradle` and setting  `$GRADLE_SBOM_VERSION` variable to `disabled`.

@@ -265,11 +288,11 @@ Currently the pipeline exposes two __manual__ jobs of publication:

Both jobs use the following variables

| Name                       | Description                                                             | Default value     |
| Input / Variable | Description                                                             | Default value     |
| -------------------------- | ----------------------------------------------------------------------- | ----------------- |
| `GRADLE_PUBLISH_VERSION`   | The value is propagated as gradle properties named `version`. It should be used in your publish task | `${CI_COMMIT_REF_SLUG}-SNAPSHOT` |
| `GRADLE_PUBLISH_ARGS`      | The publish task that is invoked                                        | `publish`         |
| `GRADLE_NO_PUBLISH`        | Set this variable if you wish to disable publish phase                  | `None`            |  
| `publish-version` / `GRADLE_PUBLISH_VERSION` | The value is propagated as gradle properties named `version`. It should be used in your publish task | `${CI_COMMIT_REF_SLUG}-SNAPSHOT` |
| `publish-args` / `GRADLE_PUBLISH_ARGS` | The publish task that is invoked                                        | `publish`         |
| `no-publish` / `GRADLE_NO_PUBLISH` | Set this variable if you wish to disable publish phase                  | `None`            |  

If you keep default value for `GRADLE_PUBLISH_VERSION`, it will have the following values

+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 [Gradle](https://gradle.org/)-based projects",
  "template_path": "templates/gitlab-ci-gradle.yml",
  "kind": "build",
  "prefix": "gradle",
  "is_component": true,
  "variables": [
    {
      "name": "GRADLE_IMAGE",
−19.7 KiB (18 KiB)
Loading image diff...
Loading