Commit 8bb6609a authored by Jan Kiene's avatar Jan Kiene
Browse files

add comments + diffing

parent 607bb002
Loading
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ check-merged-ci-config-is-valid:
  variables:
    MERGED_RESPONSE: "merged.json"
    BASELINE_RESPONSE: "baseline.json"
    ARTIFACTS_MERGED_YAML: "merged.yml"
    ARTIFACTS_BASELINE_YAML: "baseline.yml"
    ARTIFACTS_DIFF_YAML: "diff.yml"
  parallel:
    matrix:
      - REPO:
@@ -35,13 +38,12 @@ check-merged-ci-config-is-valid:
    - if [ "$REPO" == "ivas-codec" ]; then repo_url=$REPO_URL_FLOAT; project_id=$PROJECT_ID_FLOAT; fi
    - if [ "$REPO" == "ivas-basop" ]; then repo_url=$REPO_URL_BASOP; project_id=$PROJECT_ID_BASOP; fi

    # for testing
    - |
      echo 'stages: [test]' | jq -Rs '{content: .}' | curl -sS -i -X POST -H "Content-Type: application/json" -H "PRIVATE-TOKEN: $LINT_TOKEN" --data-binary @- "https://forge.3gpp.org/rep/api/v4/projects/$project_id/ci/lint"

    # get the CI file from the respective repo without lengthy clone
    - test_yml="$REPO-ci.yml"
    - curl -sS --url "$repo_url/./raw/main/.gitlab-ci.yml?inline=false" --output $test_yml
    - cat $test_yml

    # get the "baseline" yaml for comparison. this is always main
    - |
      jq -n --arg yaml "$(<$test_yml)" '.content=$yaml' \
      | curl -sS -X POST \
@@ -51,6 +53,7 @@ check-merged-ci-config-is-valid:
             --output $BASELINE_RESPONSE \
             --data-binary @-

    # change branch to the one we are currently on and get the "merged" yaml
    - sed -i".bak" "s/\&IVAS_CODEC_CI_REF main/\&IVAS_CODEC_CI_REF ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}/" $test_yml
    - |
      jq -n --arg yaml "$(<$test_yml)" '.content=$yaml' \
@@ -60,6 +63,13 @@ check-merged-ci-config-is-valid:
             -H "PRIVATE-TOKEN: $LINT_TOKEN" \
             --output $MERGED_RESPONSE \
             --data-binary @-

    # extract actual merged yaml from the json responses and get diff
    - cat $BASELINE_RESPONSE | jq -r ".merged_yaml" > $ARTIFACTS_BASELINE_YAML
    - cat $MERGED_RESPONSE | jq -r ".merged_yaml" > $ARTIFACTS_MERGED_YAML
    - dyff between $ARTIFACTS_BASELINE_YAML $ARTIFACTS_MERGED_YAML | tee $ARTIFACTS_DIFF_YAML

    # fail job if merged yaml is not valid
    - |
      grep "valid" $MERGED_RESPONSE | grep "true"
  artifacts:
@@ -67,5 +77,6 @@ check-merged-ci-config-is-valid:
    access: all
    expire_in: "5 days"
    paths:
      - $MERGED_RESPONSE
      - $BASELINE_RESPONSE
      - $ARTIFACTS_BASELINE_YAML
      - $ARTIFACTS_MERGED_YAML
      - $ARTIFACTS_DIFF_YAML