Commit 819d7547 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: migrate to CI/CD component

⚠️ requires GitLab 16.6 or later
parent 6161b004
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'    
+38 −15
Original line number Diff line number Diff line
@@ -11,13 +11,36 @@ Languages supported by this build tool are :

## 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/sbt/gitlab-ci-sbt@1.4.0
    # 2: set/override component inputs
    inputs:
      image: "registry.hub.docker.com/sbtscala/scala-sbt:17.0.2_1.6.2_3.1.3" # ⚠ 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/sbt'
    ref: '1.4.0'
    file: '/templates/gitlab-ci-sbt.yml'

variables:
  # 2: set/override template variables
  SBT_IMAGE: "registry.hub.docker.com/sbtscala/scala-sbt:17.0.2_1.6.2_3.1.3" # ⚠ this is only an example
```

## Project prerequisites
@@ -70,11 +93,11 @@ repository configuration without any specific configuration.**

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

| Name           | Description                                                                                               | Default value                                                                                                                                     |
| Input / Variable | Description                                                                                               | Default value                                                                                                                                     |
|----------------|-----------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `SBT_IMAGE`    | The Docker image used to run sbt <br/>:warning: **set the version required by your project**              | `registry.hub.docker.com/sbtscala/scala-sbt:17.0.2_1.6.2_3.1.3`                                                                                                           |
| `SBT_OPTS`     | Global [sbt options](https://www.scala-sbt.org/1.x/docs/Command-Line-Reference.html#sbt+JVM+options+and+system+properties) | `-Dsbt.global.base=sbt-cache/sbtboot -Dsbt.boot.directory=sbt-cache/boot -Dsbt.coursier.home=sbt-cache/coursier -Dsbt.ci=true -Dsbt.color=always` |
| `SBT_CLI_OPTS` | Additional sbt options used on the command line                                                           | `--batch`                                                                                                                                         |
| `image` / `SBT_IMAGE` | The Docker image used to run sbt <br/>:warning: **set the version required by your project**              | `registry.hub.docker.com/sbtscala/scala-sbt:17.0.2_1.6.2_3.1.3`                                                                                                           |
| `opts` / `SBT_OPTS` | Global [sbt options](https://www.scala-sbt.org/1.x/docs/Command-Line-Reference.html#sbt+JVM+options+and+system+properties) | `-Dsbt.global.base=sbt-cache/sbtboot -Dsbt.boot.directory=sbt-cache/boot -Dsbt.coursier.home=sbt-cache/coursier -Dsbt.ci=true -Dsbt.color=always` |
| `cli-opts` / `SBT_CLI_OPTS` | Additional sbt options used on the command line                                                           | `--batch`                                                                                                                                         |

As you can see, your sbt cache policy is preconfigured to use local cache in `sbt-cache` directory (not to download
dependencies over and over again).
@@ -92,10 +115,10 @@ for test jobs dependency reasons (some test jobs such as SONAR analysis have a d

It uses the following environment variable:

| Name             | Description                                 | Default value                     |
| Input / Variable | Description                                 | Default value                     |
|------------------|---------------------------------------------|-----------------------------------|
| `SBT_BUILD_ARGS` | sbt arguments for the [build job packaging](https://www.scala-sbt.org/1.x/docs/Running.html#Common+commands)   | `clean package`                   |
| `SBT_TEST_ARGS`  | sbt arguments for the [build job test phase](https://www.scala-sbt.org/1.x/docs/Running.html#Common+commands) | `coverage test coverageAggregate` |
| `build-args` / `SBT_BUILD_ARGS` | sbt arguments for the [build job packaging](https://www.scala-sbt.org/1.x/docs/Running.html#Common+commands)   | `clean package`                   |
| `test-args` / `SBT_TEST_ARGS` | sbt arguments for the [build job test phase](https://www.scala-sbt.org/1.x/docs/Running.html#Common+commands) | `coverage test coverageAggregate` |

Note:
- Always keep the `clean` goal to generate bytes code without any instrumentation coming from the test phasis.
@@ -120,11 +143,11 @@ 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     |
| --------------------- | -------------------------------------- | ----------------- |
| `SBT_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `SBT_SBOM_IMAGE` | The syft image used for SBOM analysis | `registry.hub.docker.com/anchore/syft:debug` |
| `SBT_SBOM_OPTS` | Options for syft used for SBOM analysis | `dir:sbt-cache/coursier --catalogers java-cataloger` |
| `sbom-disabled` / `SBT_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `sbom-image` / `SBT_SBOM_IMAGE` | The syft image used for SBOM analysis | `registry.hub.docker.com/anchore/syft:debug` |
| `sbom-opts` / `SBT_SBOM_OPTS` | Options for syft used for SBOM analysis | `dir:sbt-cache/coursier --catalogers java-cataloger` |

In addition to logs in the console, this job produces the following reports, kept for one week:

@@ -165,10 +188,10 @@ Example:

Define the following environment variables :

| Name                                    | Description                                       |
| Input / Variable | Description                                       |
|-----------------------------------------|---------------------------------------------------|
| `MAVEN_REPOSITORY_PUBLISH_SNAPSHOT_URL` | Destination repository to publish snpashot artifacts |
| `MAVEN_REPOSITORY_PUBLISH_RELEASE_URL`  | Destination repository to publish release artifacts |
| `maven-repository-publish-snapshot-url` / `MAVEN_REPOSITORY_PUBLISH_SNAPSHOT_URL` | Destination repository to publish snpashot artifacts |
| `maven-repository-publish-release-url` / `MAVEN_REPOSITORY_PUBLISH_RELEASE_URL` | Destination repository to publish release artifacts |
| `MAVEN_REPOSITORY_PUBLISH_USERNAME`     | Repository Username |
| `MAVEN_REPOSITORY_PUBLISH_PASSWORD`     | Repository Password |

+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
+5 −2
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
  "description": "Build, test and analyse your [sbt](https://www.scala-sbt.org/)-based projects",
  "template_path": "templates/gitlab-ci-sbt.yml",
  "kind": "build",
  "prefix": "sbt",
  "is_component": true,
  "variables": [
    {
      "name": "SBT_IMAGE",
@@ -61,9 +63,10 @@
      "variables": [
        {
          "name": "SBT_PUBLISH_MODE",
          "type": "enum",
          "values": ["snapshot", "ontag", "release"],
          "description": "Publish mode (one of `snapshot`, `ontag`, `release`)",
          "type": "enum",
          "values": ["", "snapshot", "ontag", "release"],
          "default": "",
          "mandatory": true
        },
        {
−2.49 KiB (7.05 KiB)
Loading image diff...
Loading