Commit 49779c31 authored by Jan Kiene's avatar Jan Kiene
Browse files

add job for clang-format application

parent bdc0c97b
Loading
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ workflow:


stages:
  - prevalidate
  - build
  - test

@@ -285,6 +286,61 @@ stages:
      junit:
        - report-junit.xml

# ---------------------------------------------------------------
# verification jobs
# ---------------------------------------------------------------

clang-format-check:
  extends:
    - .test-job-linux
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # only have MR pipelines for MRs to main
    - if: $CI_PIPELINE_SOURCE == 'push'
      when: never
    - if: $CI_PIPELINE_SOURCE == 'schedule'
      when: never
  variables:
    ARTIFACT_BASE_NAME: "mr-$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--formatting-fix"
  stage: prevalidate
  needs: []
  timeout: "5 minutes"
  script:
    # Set up variables. This can't be done in the "variables" section because variables are not expanded properly there
    - PATCH_FILE_NAME="$ARTIFACT_BASE_NAME".patch
    - >
      INSTRUCTIONS_GITLAB="To fix formatting issues:\n
      - download the diff patch available as artifact of this job\n
      - unzip the artifact and place the patch file in the root directory of your local IVAS repo\n
      - run: git apply $PATCH_FILE_NAME\n
      - commit new changes"
    - >
      INSTRUCTIONS_README="To fix formatting issues:\n
      - place the patch file in the root directory of your local IVAS repo\n
      - run: git apply $PATCH_FILE_NAME\n
      - commit new changes"

    - format_problems=0
    - scripts/check-format.sh -af -p 8 || format_problems=$?
    - if [ $format_problems == 0 ] ; then exit 0; fi

    - mkdir tmp-formatting-fix
    - git diff > "tmp-formatting-fix/$PATCH_FILE_NAME"

    # Print instructions to job output
    - echo -e "$INSTRUCTIONS_GITLAB"

    # Include readme in the artifact, in case someone misses the job printout (e.g. getting the artifact via MR interface)
    - echo -e "$INSTRUCTIONS_README" > "tmp-formatting-fix/readme.txt"

    - exit $format_problems
  artifacts:
    expire_in: 1 day
    paths:
      - tmp-formatting-fix/
    when: on_failure
    name: "$ARTIFACT_BASE_NAME"
    expose_as: "formatting patch"

# ---------------------------------------------------------------
# Build jobs
# ---------------------------------------------------------------