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

Merge branch 'feat/component' into 'master'

feat: migrate to GitLab CI/CD component

See merge request to-be-continuous/bash!34
parents e9caacb5 c85e02f0
Loading
Loading
Loading
Loading
+35 −12
Original line number Diff line number Diff line
@@ -4,13 +4,36 @@ This project implements a GitLab CI/CD template to test and analyse your shell c

## 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/bash/gitlab-ci-bash@3.3.0
    # 2: set/override component inputs
    inputs:
      bats-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/bash'
    ref: '3.3.0'
    file: '/templates/gitlab-ci-bash.yml'

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

## Jobs
@@ -19,12 +42,12 @@ include:

This job performs a static analysis of your shell scripts using [ShellCheck](https://github.com/koalaman/shellcheck).

| Name                    | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| ----------------------- | -------------------------------------- | ----------------- |
| `BASH_SHELLCHECK_DISABLED` | Set to `true` to disable ShellCheck                                                | _none_ (enabled) |
| `BASH_SHELLCHECK_IMAGE` | The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck) | `registry.hub.docker.com/koalaman/shellcheck-alpine:stable` |
| `BASH_SHELLCHECK_FILES` | Shell file(s) pattern to analyse                                                  | `**/*.sh`            |
| `BASH_SHELLCHECK_OPTS`  | ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) | _none_ |
| `shellcheck-disabled` / `BASH_SHELLCHECK_DISABLED` | Set to `true` to disable ShellCheck                                                | _none_ (enabled) |
| `shellcheck-image` / `BASH_SHELLCHECK_IMAGE` | The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck) | `registry.hub.docker.com/koalaman/shellcheck-alpine:stable` |
| `shellcheck-files` / `BASH_SHELLCHECK_FILES` | Shell file(s) pattern to analyse                                                  | `**/*.sh`            |
| `shellcheck-opts` / `BASH_SHELLCHECK_OPTS` | ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) | _none_ |

### `bash-bats` job

@@ -32,13 +55,13 @@ This job performs unit tests based on [Bats](https://bats-core.readthedocs.io/)

The job uses the following variables:

| Name                    | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| ----------------------- | -------------------------------------- | ----------------- |
| `BASH_BATS_ENABLED`     | Set to `true` to enable bats tests                                                    | _none_ (disabled) |
| `BASH_BATS_IMAGE`       | The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats) | `registry.hub.docker.com/bats/bats:latest` |
| `BASH_BATS_TESTS`       | The path to a Bats test file, or the path to a directory containing Bats test files | `tests`           |
| `BASH_BATS_OPTS`        | Bats [options](https://bats-core.readthedocs.io/en/stable/usage.html)                | _none_ |
| `BASH_BATS_LIBRARIES`   | Coma separated list of Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons) (formatted as `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`) | _none_ |
| `bats-enabled` / `BASH_BATS_ENABLED` | Set to `true` to enable bats tests                                                    | _none_ (disabled) |
| `bats-image` / `BASH_BATS_IMAGE` | The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats) | `registry.hub.docker.com/bats/bats:latest` |
| `bats-tests` / `BASH_BATS_TESTS` | The path to a Bats test file, or the path to a directory containing Bats test files | `tests`           |
| `bats-opts` / `BASH_BATS_OPTS` | Bats [options](https://bats-core.readthedocs.io/en/stable/usage.html)                | _none_ |
| `bats-libraries` / `BASH_BATS_LIBRARIES` | Coma separated list of Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons) (formatted as `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`) | _none_ |

In addition to a textual report in the console, this job produces the following reports, kept for one day:

+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": "Test and analyse your shell code",
  "template_path": "templates/gitlab-ci-bash.yml",
  "kind": "build",
  "prefix": "bash",
  "is_component": true,
  "features": [
    {
      "id": "shellcheck",
−4.41 KiB (14.9 KiB)
Loading image diff...
+48 −5
Original line number Diff line number Diff line
@@ -13,6 +13,43 @@
# program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA  02110-1301, USA.
# =========================================================================================
spec:
  inputs:
    shellcheck-disabled:
      description: Disable ShellCheck
      type: boolean
      default: false
    shellcheck-image:
      description: The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck)
      default: registry.hub.docker.com/koalaman/shellcheck-alpine:stable
    shellcheck-files:
      description: Shell file(s) pattern to analyse
      default: '**/*.sh'
    shellcheck-opts:
      description: ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md)
      default: ''
    bats-enabled:
      description: Enable Bats
      type: boolean
      default: false
    bats-image:
      description: The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats)
      default: registry.hub.docker.com/bats/bats:latest
    bats-tests:
      description: The path to a Bats test file, or the path to a directory containing Bats test files
      default: tests
    bats-opts:
      description: Bats [options](https://bats-core.readthedocs.io/en/stable/usage.html)
      default: ''
    bats-libraries:
      description: |-
        Coma separated list of Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons)

        Formatted as: `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`

        Example: `bats-support@https://github.com/bats-core/bats-support/archive/v0.3.0.zip bats-assert@https://github.com/bats-core/bats-assert/archive/v2.0.0.zip`
      default: ''
---
# default workflow rules: Merge Request pipelines
workflow:
  rules:
@@ -56,19 +93,25 @@ workflow:

variables:
  # variabilized tracking image
  TBC_TRACKING_IMAGE: "registry.gitlab.com/to-be-continuous/tools/tracking:master"
  TBC_TRACKING_IMAGE: registry.gitlab.com/to-be-continuous/tools/tracking:master

  BASH_BATS_IMAGE: "registry.hub.docker.com/bats/bats:latest"
  BASH_BATS_TESTS: "tests"
  BASH_BATS_IMAGE: $[[ inputs.bats-image ]]
  BASH_BATS_TESTS: $[[ inputs.bats-tests ]]

  BASH_SHELLCHECK_IMAGE: "registry.hub.docker.com/koalaman/shellcheck-alpine:stable"
  BASH_SHELLCHECK_FILES: "**/*.sh"
  BASH_SHELLCHECK_IMAGE: $[[ inputs.shellcheck-image ]]
  BASH_SHELLCHECK_FILES: $[[ inputs.shellcheck-files ]]

  # default production ref name (pattern)
  PROD_REF: '/^(master|main)$/'
  # default integration ref name (pattern)
  INTEG_REF: '/^develop$/'

  BASH_SHELLCHECK_DISABLED: $[[ inputs.shellcheck-disabled ]]
  BASH_SHELLCHECK_OPTS: $[[ inputs.shellcheck-opts ]]
  BASH_BATS_ENABLED: $[[ inputs.bats-enabled ]]
  BASH_BATS_OPTS: $[[ inputs.bats-opts ]]
  BASH_BATS_LIBRARIES: $[[ inputs.bats-libraries ]]

stages:
  - build
  - test