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

Merge branch 'tech/first-version' into 'master'

First commit of bruno template

See merge request to-be-continuous/bruno!2
parents 72bb1385 2959efc9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ files:
    documentation: ./README.md
    changelog: ./CHANGELOG.md
data:
    description: "Run your automated API tests with Bruno"
    description: "Test your APIs with Bruno"
    labels:
    - to be continuous
    - Test
+15 −15
Original line number Diff line number Diff line
@@ -8,9 +8,9 @@ In order to include this template in your project, add the following to your `gi

```yaml
include:
  - project: 'to-be-continuous/bruno'
    ref: '1.0.0'
    file: '/templates/gitlab-ci-bruno.yml'
  - project: "to-be-continuous/bruno"
    ref: "1.0.0"
    file: "/templates/gitlab-ci-bruno.yml"
```

## `bruno` job
@@ -20,21 +20,21 @@ This job starts [Bruno](https://www.usebruno.com/) (functional) tests.
It uses the following variable:

| Name              | Description                                                                                                            | Default value                                 |
| --------------------- | ---------------------------------------- | ----------------- |
| `BRU_IMAGE`       | The Docker image used to run Bruno. | `registry.hub.docker.com/bruno:latest` |
| `BRU_PROJECT_DIR` | The Bruno project directory (containing test scripts) | `.` |
| `BRU_EXTRA_ARGS`  | Bruno extra [run options](link-to-cli-options-ref) | _none_ |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| `BRU_IMAGE`       | The Docker image used to run the [Bruno CLI](https://docs.usebruno.com/cli/overview.html).                             | `registry.hub.docker.com/library/node:latest` |
| `BRU_COLLECTIONS` | The matcher to select Bruno collection directory(ies) to run.                                                          | `bruno`                                       |
| `BRU_EXTRA_ARGS`  | Bruno extra [run options](https://docs.usebruno.com/cli/overview.html#options)                                         | _none_                                        |
| `REVIEW_ENABLED`  | Set to `true` to enable Bruno tests on review environments (dynamic environments instantiated on development branches) | _none_ (disabled)                             |

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

| Report                      | Format                                                                      | Usage                                                                                                 |
| -------------- | ---------------------------------------------------------------------------- | ----------------- |
| `$BRU_PROJECT_DIR/reports/bruno.xunit.xml` | [xUnit](https://github.com/jest-community/jest-junit#readme) test report(s) | [GitLab integration](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsjunit) |
| --------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `reports/bruno-*.xunit.xml` | [junit](https://docs.usebruno.com/cli/overview.html#options) test report(s) | [GitLab integration](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsjunit) |

### base url auto evaluation

By default, the Bruno template tries to auto-evaluate its base url
By default, the Bruno template tries to auto-evaluate a [{{base_url}} variable](https://docs.usebruno.com/scripting/vars.html)
(i.e. the variable pointing at server under test) by looking either for a `$environment_url` variable or for an
`environment_url.txt` file.

+7 −7
Original line number Diff line number Diff line

{
  "name": "Bruno",
  "description": "Run your automated tests with [Bruno](https://www.usebruno.com/)",
  "description": "Test your APIs with [Bruno](https://www.usebruno.com/)",
  "template_path": "templates/gitlab-ci-bruno.yml",
  "kind": "acceptance",
  "variables": [
    {
      "name": "BRU_IMAGE",
      "description": "The Docker image used to run Bruno",
      "default": "registry.hub.docker.com/bruno:latest"
      "description": "The Docker image used to run the [Bruno CLI](https://docs.usebruno.com/cli/overview.html)",
      "default": "registry.hub.docker.com/library/node:latest"
    },
    {
      "name": "BRU_PROJECT_DIR",
      "description": "The Bruno project directory (containing test scripts)",
      "default": "."
      "name": "BRU_COLLECTIONS",
      "description": "The matcher to select Bruno collection directory(ies) to run",
      "default": "bruno"
    },
    {
      "name": "BRU_EXTRA_ARGS",
      "description": "Bruno extra [run options](link-to-cli-options-ref)",
      "description": "Bruno extra [run options](https://docs.usebruno.com/cli/overview.html#options)",
      "advanced": true
    },
    {
+5.06 KiB (24.7 KiB)
Loading image diff...
+33 −15
Original line number Diff line number Diff line
@@ -60,12 +60,9 @@ workflow:
variables:
  # variabilized tracking image
  TBC_TRACKING_IMAGE: "registry.gitlab.com/to-be-continuous/tools/tracking:master"

  # Default Docker image (use a public image - can be overridden)
  BRU_IMAGE: "registry.hub.docker.com/bruno:latest"
  # Directory where BRU tests are implemented
  BRU_ROOT_DIR: "."

  BRU_IMAGE: "registry.hub.docker.com/library/node:latest"
  BRU_COLLECTIONS: bruno
  # default production ref name (pattern)
  PROD_REF: '/^(master|main)$/'
  # default integration ref name (pattern)
@@ -145,6 +142,9 @@ stages:
    if [[ -z "$ca_imported" ]]
    then
      log_warn "Could not import custom CA certificates !"
    else
      # prepare CLI options
      export cacerts_opt="--cacerts ${bundle}"
    fi
  }

@@ -342,32 +342,50 @@ bruno:
    - name: "$TBC_TRACKING_IMAGE"
      command: ["--service", "bruno", "1.0.0"]
  stage: acceptance
  # TODO (if necessary): define cache policy here
  variables:
    # NPM cache
    npm_config_cache: "$CI_PROJECT_DIR/.npm"
  cache:
    # cache shall be per branch per template
    key: "${CI_COMMIT_REF_SLUG}-bruno"
    paths:
      - .cache/
      - .npm/
  before_script:
    - !reference [.bru-scripts]
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    - eval_env_url
    - cd "$BRU_ROOT_DIR"
    # TODO (if necessary): do setup stuff here
    - npm install -g @usebruno/cli
  script:
    # TODO: run bru tests
    # TODO (if possible): $TRACE set enables debug logs on the tool
    - mkdir -p -m 777 reports
    - bru run ${TRACE+--verbose} --env BASE_URL=$BRU_BASE_URL --junit --output=reports/bruno.xunit.xml $BRU_EXTRA_ARGS
    - |
      for collection in $BRU_COLLECTIONS
      do
        rc=0
        if [[ -d "$collection" ]] && [[ -f "$collection/bruno.json" ]]
        then
          cd $collection
          log_info "Running collection \\e[33;1m./${collection}\\e[0m..."
          namenopunct=$(basename $collection | tr '[:punct:]' '_')
          junit_report="$CI_PROJECT_DIR/reports/bruno-$namenopunct.xunit.xml"
          if ! bru run -r --output "$junit_report" --format junit --env-var "base_url=$BRU_BASE_URL" $cacerts_opt $BRU_EXTRA_ARGS
          then
            log_error "Collection \\e[33;1m./${collection}\\e[0m failed"
            rc=1
          fi
          cd $CI_PROJECT_DIR
        else
          log_warn "Matched path is not a Bruno collection: \\e[33;1m./${collection}\\e[0m"
        fi
      done
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always
    paths:
      - $BRU_ROOT_DIR/reports/bruno.*
      - reports/bruno-*
    reports:
      # TODO (if possible): Acceptance tests use JUnit format and GitLab integration (see: https://docs.gitlab.com/ee/ci/yaml/#artifactsreports)
      junit:
        - $BRU_ROOT_DIR/reports/bruno.xunit.xml
        - reports/bruno-*.xunit.xml
    expire_in: 1 day
  rules:
    - !reference [.acceptance-policy, rules]