Commit bbdf8708 authored by Jan Kiene's avatar Jan Kiene
Browse files

update ci file to initial MR pipeline

parent 5df49408
Loading
Loading
Loading
Loading
Loading
+72 −92
Original line number Diff line number Diff line
variables:
  TESTV_DIR: "/testv"
  TOOLS_DIR: "/tools"
  TESTV_DIR: "/usr/local/testv"


# prevent running two pipelines on pushes to merge request branches
workflow:
@@ -17,41 +17,6 @@ stages:
  - test
  - compare

# template for job that builds docker images and pushes them to the container registry (once enabled)
# name of child job determines name of image and name of dockerfile in ci/
# NOTE: this will only work once the container registry is activated in the project
.build-docker-image:
  stage: maintenance
  tags:
    - shell
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - IMAGE_LATEST=CI_REGISTRY_IMAGE/$CI_BUILD_NAME:latest
    - IMAGE_TAG=CI_REGISTRY_IMAGE/$CI_BUILD_NAME:$CI_COMMIT_SHORT_SHA
    - echo "Build $IMAGE_TAG"
    - docker build -t $IMAGE_TAG -t $IMAGE_LATEST -f ci/$CI_BUILD_NAME.dockerfile
    - docker push $IMAGE_LATEST
  rules:
    - if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
      when: manual
      allow_failure: true
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "push"
      changes:
        - ci/*dockerfile

ubuntu_22.04:
  extends: .build-docker-image

# temporary test job to see whether everything works with the docker runner
test-job-docker-runner:
  stage: test
  tags:
    - docker
  image: ubuntu
  script:
    - echo "This job tests something"



# template for all test jobs
.test-job:
@@ -60,112 +25,126 @@ test-job-docker-runner:
      when: never
    - when: on_success

# template for using an ubuntu 22.04 image in docker
.test-job-ubuntu:
# template test job on linux
.test-job-linux:
  extends: .test-job
  image: $CI_REGISTRY_IMAGE/ubuntu_22.04:latest
  tags:
    - exec::docker
    - ivas-linux
  before_script:
    - if [ ! -d "$TESTV_DIR" ]; then mkdir -p $TESTV_DIR; fi
    - cp -r scripts/testv/* $TESTV_DIR/


# build all components of the project, i.e. codec itself, the unittests, the prerenderer and the standalone version of the TD object renderer
.build-all-linux:
  extends: .test-job-ubuntu
build-all-linux-make:
  extends: .test-job-linux
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  stage: build
  script:
    - bash ci/build_all_linux.sh

.build-codec-instrumented-linux:
  extends: .test-job-ubuntu
build-codec-linux-cmake:
  extends: .test-job-linux
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  stage: build
  script:
    - bash ci/build_codec_instrumented.sh
    - mkdir build
    - cd build
    - cmake ..
    - make -j

build-codec-instrumented-linux:
  extends: .test-job-linux
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  stage: build
  script:
    - bash ci/build_codec_instrumented_linux.sh

# make sure that the codec builds with msan, asan and usan
.build-codec-sanitizers-linux:
  extends: .test-job-ubuntu
build-codec-sanitizers-linux:
  extends: .test-job-linux
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  stage: build
  script:
    # need to patch PATH so that `clang` is available
    - PATH=$PATH:/usr/lib/llvm-13/bin
    - bash ci/build_codec_sanitizers_linux.sh


# test that runs all modes with 1s input signals
.codec-smoke-test:
  extends: .test-job-ubuntu
codec-smoke-test:
  extends: .test-job-linux
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  stage: test
  tags:
    - exec::docker
    - res::ivas-testv
  script:
    - bash ci/smoke_test.sh
  artifacts:
    paths:
      - summary.txt
      - out/logs


# compare bit exactness between target and source branch
.self-test-on-merge-request:
  extends: .test-job-ubuntu
self-test-on-merge-request:
  extends: .test-job-linux
  stage: compare
  tags:
    - exec::docker
    - res::ivas-testv
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  script:
    ### build test binaries, clean for paranoia reasons
    - make clean all
    - mv IVAS_cod IVAS_cod_test
    - mv IVAS_dec IVAS_dec_test
    ### build test binaries, initial clean for paranoia reasons
    - make clean
    - mkdir build
    - cd build
    - cmake ..
    - make -j
    - mv IVAS_cod ../IVAS_cod_test
    - mv IVAS_dec ../IVAS_dec_test
    - cd ..
    - rm -rf build/*

    ### backup testvectors from source branch before switching to arget branch -> makes sure that up-to-date testv folder is used in case the branch makes changes to it
    - cp -r scripts/testv scripts/testv.bak

    ### checkout version to compare against
    # first delete local target branch to avoid conflicts when branch is cached and there are merge conflicts during fetching
    - git branch -D $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    # depending on chaching, the branch may not be there, so prevent failure of this command -> should maybe be done smarter later
    - git branch -D $CI_MERGE_REQUEST_TARGET_BRANCH_NAME || true
    # needed when depth is lower than the number of commits in the branch
    - git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME:$CI_MERGE_REQUEST_TARGET_BRANCH_NAME

    ## 1. variant: use target branch directly -> includes possible race condition
    #- git checkout $CI_MERGE_REQUEST_TARGET_BRANCH_NAME

    ## 2. variant: compare to last common commit ("start" of branch after all possible merge-backs)
    #- last_source_commit=$(git log -n 1 --pretty=format:"%H")
    #- last_target_commit=$(git log -n 1 --pretty=format:"%H" $CI_MERGE_REQUEST_TARGET_BRANCH_NAME)
    #- split_commit=$(git merge-base $last_source_commit $last_target_commit)
    #- git checkout $split_commit

    ## 3. variant: compare to last master commit before pipeline was created
    ### compare to last target branch commit before pipeline was created
    - target_commit=$(git log $CI_MERGE_REQUEST_TARGET_BRANCH_NAME -1 --oneline --before=${CI_PIPELINE_CREATED_AT} --format=%H)
    - git checkout $target_commit

    ### build reference binaries
    - make clean all
    - mv IVAS_cod IVAS_cod_ref
    - mv IVAS_dec IVAS_dec_ref
    - cd build
    - cmake ..
    - make -j
    - mv IVAS_cod ../IVAS_cod_ref
    - mv IVAS_dec ../IVAS_dec_ref
    - cd ..

    # TODO: instead check out the source commit again
    ### restore testv folder from branch
    - rm -rf scripts/testv
    - cp -r scripts/testv.bak scripts/testv

    ### copy testv dir to necessary place
    - cp -r $TESTV_DIR ./scripts/testv
    ### run selftest
    - test_output=test_output.txt
    - python3 ./scripts/self_test.py --encref IVAS_cod_ref --decref IVAS_dec_ref --enctest IVAS_cod_test --dectest IVAS_dec_test | tee $test_output
    - ls -altr scripts/testv
    - python3 ./scripts/self_test.py --encref IVAS_cod_ref --decref IVAS_dec_ref --enctest IVAS_cod_test --dectest IVAS_dec_test | tee test_output.txt

    ### analyse test output
    # check for crashes during the test, if any happened, fail the test
    - if cat $test_output | grep -c "Run errors were encountered for the following conditions:"; then echo "Codec had run errors"; exit 1; fi
    - if cat test_output.txt | grep -c "Run errors were encountered for the following conditions:"; then echo "Codec had run errors"; exit 1; fi
    # check for non bitexact output and fail test if the merge request does not have a non-BE tag
    - if ! cat $test_output | grep -c "All [0-9]* tests are bitexact" && ! echo $CI_MERGE_REQUEST_TITLE | grep -c --ignore-case "\[non[ -]*be\]"; then echo "Non-bitexact cases without non-BE tag encountered"; exit 1; fi

    - if ! cat test_output.txt | grep -c "All [0-9]* tests are bitexact" && ! echo $CI_MERGE_REQUEST_TITLE | grep -c --ignore-case "\[non[ -]*be\]"; then echo "Non-bitexact cases without non-BE tag encountered"; exit 1; fi
  artifacts:
    paths:
      - ./scripts/ref/logs
      - ./scripts/test/logs
      - ./scripts/self_test_summary.txt
      - test_output.txt
      - scripts/test/logs
      - scripts/ref/logs


# Pull state of a branch on 3GPP repo, push to a mirror repo.
@@ -181,8 +160,9 @@ pull-from-3gpp-forge:
    - git checkout $CI_COMMIT_BRANCH
    
    # Pull commits from upstream
    - git pull --ff-only --tags https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec.git $MIRROR_SOURCE_BRANCH
    - git lfs pull https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec.git
    - git remote add upstream https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec.git
    - git pull --ff-only --tags upstream $MIRROR_SOURCE_BRANCH
    - git lfs pull upstream

    # Push to mirror, include tags. Option `-o ci.skip` tells GitLab to skip CI for the pushed commits (assumed already tested upstream)
    - git push --tags -o ci.skip "https://${GITLAB_USER_LOGIN}:${MIRROR_ACCESS_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:${CI_COMMIT_BRANCH}"