Commit 2aae699d authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: initial commit

parent a6122d28
Loading
Loading
Loading
Loading

Hurl.r2.yml

0 → 100644
+13 −0
Original line number Diff line number Diff line
files:
    template: ./templates/gitlab-ci-hurl.yml
    documentation: ./README.md
    changelog: ./CHANGELOG.md
data:
    description: "Run your automated (HTTP) tests with Hurl"
    public: true
    labels:
    - to be continuous
    - API
    - Test
    license: LGPL v3
    deprecated: false
+9 −6
Original line number Diff line number Diff line
# GitLab CI template for Hurl

This project implements a GitLab CI/CD template to run your automated tests with [Hurl](https://hurl.dev/).

## Usage
@@ -20,21 +21,21 @@ It uses the following variable:

| Name                  | description                              | default value     |
| --------------------- | ---------------------------------------- | ----------------- |
| `HURL_IMAGE`       | The Docker image used to run Hurl. | `registry.hub.docker.com/hurl:latest` |
| `HURL_PROJECT_DIR` | The Hurl project directory (containing test scripts) | `.` |
| `HURL_EXTRA_ARGS`  | Hurl extra [run options](link-to-cli-options-ref) | _none_ |
| `HURL_IMAGE`          | The Docker image used to run Hurl. | `ghcr.io/orange-opensource/hurl:latest` |
| `HURL_TEST_FILES`     | The Hurl test files to run | `hurl/*.hurl` |
| `HURL_EXTRA_ARGS`     | Hurl extra [run options](https://hurl.dev/docs/manual.html#options) | _none_ |
| `REVIEW_ENABLED`      | Set to `true` to enable Hurl 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             |
| -------------- | ---------------------------------------------------------------------------- | ----------------- |
| `$HURL_PROJECT_DIR/reports/Hurl.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/hurl.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) |

### base url auto evaluation

By default, the Hurl template tries to auto-evaluate its base url
(i.e. the variable pointing at server under test) by looking either for a `$environment_url` variable or for an 
By default, the Hurl template tries to auto-evaluate the base server url
(i.e. the variable pointing at server under test) by looking either for an `$environment_url` variable or for an 
`environment_url.txt` file.

Therefore if an upstream job in the pipeline deployed your code to a server and propagated the deployed server url,
@@ -43,3 +44,5 @@ or through a basic `environment_url.txt` file, then the Hurl test will automatic

:warning: all our deployment templates implement this design. Therefore even purely dynamic environments (such as review
environments) will automatically be propagated to your Hurl tests.

When successfully determined, the base url is then [injected as `base_url` variable](https://hurl.dev/docs/templates.html#injecting-variables), and can be freely used in your Hurl scripts with the `{{base_url}}` expression.
+5 −5
Original line number Diff line number Diff line
@@ -8,16 +8,16 @@
    {
      "name": "HURL_IMAGE",
      "description": "The Docker image used to run Hurl",
      "default": "registry.hub.docker.com/hurl:latest"
      "default": "ghcr.io/orange-opensource/hurl:latest"
    },
    {
      "name": "HURL_PROJECT_DIR",
      "description": "The Hurl project directory (containing test scripts)",
      "default": "."
      "name": "HURL_TEST_FILES",
      "description": "The Hurl test files to run",
      "default": "hurl/*.hurl"
    },
    {
      "name": "HURL_EXTRA_ARGS",
      "description": "Hurl extra [run options](link-to-cli-options-ref)",
      "description": "Hurl extra [run options](https://hurl.dev/docs/manual.html#options)",
      "advanced": true
    },
    {
−7.12 KiB (3.85 KiB)
Loading image diff...
+16 −24
Original line number Diff line number Diff line
@@ -62,9 +62,8 @@ variables:
  TBC_TRACKING_IMAGE: "$CI_REGISTRY/to-be-continuous/tools/tracking:master"

  # Default Docker image (use a public image - can be overridden)
  HURL_IMAGE: "registry.hub.docker.com/hurl:latest"
  # Directory where HURL tests are implemented
  HURL_ROOT_DIR: "."
  HURL_IMAGE: "ghcr.io/orange-opensource/hurl:latest"
  HURL_TEST_FILES: "hurl/*.hurl"

  # default production ref name (pattern)
  PROD_REF: '/^(master|main)$/'
@@ -127,6 +126,8 @@ stages:
      then
        # Import certificates in bundle
        echo "${certs}" | tr -d '\r' >> "${bundle}"
        # pass cacert file to Hurl with $HURL_cacert
        export HURL_cacert="${bundle}"

        log_info "Custom CA certificates imported in \\e[33;1m${bundle}\\e[0m"
        ca_imported=1
@@ -308,14 +309,14 @@ stages:
    # shellcheck disable=SC2154
    if [[ -n "$environment_url" ]]
    then
      HURL_BASE_URL="$environment_url"
      export HURL_BASE_URL
      log_info "Upstream \$environment_url variable set: use base url \\e[33;1m$HURL_BASE_URL\\e[0m"
      HURL_base_url="$environment_url"
      export HURL_base_url
      log_info "Upstream \$environment_url variable set: use base url \\e[33;1m$HURL_base_url\\e[0m"
    elif [[ -f environment_url.txt ]]
    then
      HURL_BASE_URL=$(cat environment_url.txt)
      export HURL_BASE_URL
      log_info "Upstream environment_url.txt file found: use base url \\e[33;1m$HURL_BASE_URL\\e[0m"
      HURL_base_url=$(cat environment_url.txt)
      export HURL_base_url
      log_info "Upstream environment_url.txt file found: use base url \\e[33;1m$HURL_base_url\\e[0m"
    else
      log_info "No upstream environment url found: leave default"
    fi
@@ -329,37 +330,28 @@ stages:
# on master branch: automatically started after staging deployment
# on non-master branch: manually started after review env deployment (requires $REVIEW_ENABLED to be set)
hurl:
  image: $HURL_IMAGE
  image:
    name: "$HURL_IMAGE"
    entrypoint: [""]
  services:
    - name: "$TBC_TRACKING_IMAGE"
      command: ["--service", "hurl", "1.0.0"]
  stage: acceptance
  # TODO (if necessary): define cache policy here
  cache:
    # cache shall be per branch per template
    key: "${CI_COMMIT_REF_SLUG}-hurl"
    paths:
      - .cache/
  before_script:
    - *hurl-scripts
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    - eval_env_url
    - cd "$HURL_ROOT_DIR"
    # TODO (if necessary): do setup stuff here
  script:
    # TODO: run hurl tests
    # TODO (if possible): $TRACE set enables debug logs on the tool
    - mkdir -p -m 777 reports
    - hurl run ${TRACE+--verbose} --env BASE_URL=$HURL_BASE_URL --junit --output=reports/hurl.xunit.xml $HURL_EXTRA_ARGS
    - hurl ${TRACE+--verbose} --test --report-junit reports/hurl.xunit.xml $HURL_EXTRA_ARGS $HURL_TEST_FILES
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always
    paths:
      - $HURL_ROOT_DIR/reports/hurl.*
      - reports/hurl.*
    reports:
      # TODO (if possible): Acceptance tests use JUnit format and GitLab integration (see: https://docs.gitlab.com/ee/ci/yaml/#artifactsreports)
      junit:
        - $HURL_ROOT_DIR/reports/hurl.xunit.xml
        - reports/hurl.xunit.xml
    expire_in: 1 day
  rules:
    - !reference [.acceptance-policy, rules]