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

Merge branch 'feat/normalize-reports' into 'master'

Normalize reports

See merge request to-be-continuous/bash!19
parents feeb5035 27e103c2
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -28,23 +28,28 @@ This job performs a static analysis of your shell scripts using [ShellCheck](htt

### `bash-bats` job

This job performs unit tests based on [Bats](https://github.com/bats-core/bats-core) (Bash Automated Testing System).
This job performs unit tests based on [Bats](https://bats-core.readthedocs.io/) (Bash Automated Testing System).

The job uses the following variables:

| Name                    | 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://github.com/bats-core/bats-core) | `bats/bats:1.2.1` |
| `BASH_BATS_IMAGE`       | The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats) | `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://github.com/bats-core/bats-core#usage)                | `--formatter junit --output reports` |
| `BASH_BATS_LIBRARIES`   | Coma separated list of Bats [libraries and add-ons](https://github.com/bats-core/bats-core#libraries-and-add-ons) (formatted as `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`) | _none_ |
| `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_ |

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

| Report         | Format                                                                       | Usage             |
| -------------- | ---------------------------------------------------------------------------- | ----------------- |
| `reports/*.bats.xml` | [xUnit](https://en.wikipedia.org/wiki/XUnit) test report(s) | [GitLab integration](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsjunit) |

#### How to manage libraries and add-ons

The Docker image used only contains [bats-core](https://github.com/bats-core/bats-core).
If you wish to used Bats [libraries and add-ons](https://github.com/bats-core/bats-core#libraries-and-add-ons), you have
If you wish to used Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons), you have
two options: 

1. either use the Git submodule technique whenever possible,
+5 −6
Original line number Diff line number Diff line
@@ -30,13 +30,13 @@
    {
      "id": "bats",
      "name": "Bats",
      "description": "Test your shell scripts with [Bats](https://github.com/bats-core/bats-core) (Bash Automated Testing System)",
      "description": "Test your shell scripts with [Bats](https://bats-core.readthedocs.io/) (Bash Automated Testing System)",
      "enable_with": "BASH_BATS_ENABLED",
      "variables": [
        {
          "name": "BASH_BATS_IMAGE",
          "description": "The Docker image used to run [Bats](https://github.com/bats-core/bats-core)",
          "default": "bats/bats:1.2.1",
          "description": "The Docker image used to run [Bats](https://hub.docker.com/r/bats/bats)",
          "default": "bats/bats:latest",
          "advanced": true
        },
        {
@@ -46,12 +46,11 @@
        },
        {
          "name": "BASH_BATS_OPTS",
          "description": "Bats [options](https://github.com/bats-core/bats-core#usage)",
          "default": "--formatter junit --output reports"
          "description": "Bats [options](https://bats-core.readthedocs.io/en/stable/usage.html)"
        },
        {
          "name": "BASH_BATS_LIBRARIES",
          "description": "Coma separated list of Bats [libraries and add-ons](https://github.com/bats-core/bats-core#libraries-and-add-ons)\n\nFormatted as: `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`\n\nExample: `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`"
          "description": "Coma separated list of Bats [libraries and add-ons](https://bats-core.readthedocs.io/en/stable/writing-tests.html#libraries-and-add-ons)\n\nFormatted as: `lib_name_1@archive_url_1 lib_name_2@archive_url_2 ...`\n\nExample: `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`"
        }
      ]
    }
+3 −4
Original line number Diff line number Diff line
@@ -44,8 +44,7 @@ variables:
  # variabilized tracking image
  TBC_TRACKING_IMAGE: "$CI_REGISTRY/to-be-continuous/tools/tracking:master"

  BASH_BATS_IMAGE: "bats/bats:1.2.1"
  BASH_BATS_OPTS: "--formatter junit --output reports"
  BASH_BATS_IMAGE: "bats/bats:latest"
  BASH_BATS_TESTS: "tests"

  BASH_SHELLCHECK_IMAGE: "koalaman/shellcheck-alpine:stable"
@@ -250,7 +249,7 @@ bash-bats:
  script:
    - install_bats_libs
    - mkdir reports
    - bats $BASH_BATS_OPTS $BASH_BATS_TESTS
    - bats --formatter junit --output reports $BASH_BATS_OPTS $BASH_BATS_TESTS
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
@@ -259,7 +258,7 @@ bash-bats:
      junit:
        - "reports/*.bats.xml"
    paths:
      - reports
      - "reports/*.bats.xml"
  rules:
    - if: '$BASH_BATS_ENABLED != "true"'
      when: never