Commit 895b64e1 authored by Jan Kiene's avatar Jan Kiene
Browse files

do extra lint step

parent 67bb81c3
Loading
Loading
Loading
Loading
Loading
+42 −24
Original line number Diff line number Diff line
@@ -73,16 +73,27 @@ check-merged-ci-config-is-valid:
    - |
      curl -sS "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/files/${patch_yml}?ref=${CI_COMMIT_SHA}" -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" | jq -r .content | base64 -d | sha256sum

    # Lint baseline with target branch ref
    # Get merged baseline with target branch ref
    - |
      jq -n --arg yaml "$(<$BASE_YML)" '{ content: $yaml }' \
      jq -n --arg yaml "$(<$BASE_YML)" '{ content: $yaml, dry_run: true }' \
      | curl -sS -X POST \
             --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?include_merged_yaml=true&dry_run=true&ref=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" \
         --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?include_merged_yaml=true&dry_run=true&ref=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}" \
         -H "Content-Type: application/json" \
         -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" \
         --output $BASELINE_RESPONSE \
         --data-binary @-

    # lint the whole merged thing statically (previous call tries to run pipeline which does not work because ivas-codec does not have push pipelines...)
    - jq -r ".merged_yaml" $BASELINE_RESPONSE > $ARTIFACTS_BASELINE_YAML
    - rm $BASELINE_RESPONSE
    - |
      jq -n --arg yaml "$(<$ARTIFACTS_BASELINE_YAML)" '{ content: $yaml }' \
      | curl -sS -X POST \
         --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?" \
         -H "Content-Type: application/json" \
         -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" \
         --output $BASELINE_RESPONSE \
         --data-binary @-
    - cat $BASELINE_RESPONSE | jq

    - sed -i '/^include:/,$d' $TEST_YML
    - |
@@ -94,19 +105,28 @@ check-merged-ci-config-is-valid:
    - echo "=== First 50 lines of ${patch_yml} ==="
    - head -n 50 $patch_yml

    # Lint current with feature branch ref
    # Get current with feature branch ref
    - |
      jq -n --arg yaml "$(<$TEST_YML)" '{ content: $yaml }' \
      jq -n --arg yaml "$(<$TEST_YML)" '{ content: $yaml, dry_run: true }' \
      | curl -sS -X POST \
             --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?include_merged_yaml=true&dry_run=true&ref=${CI_COMMIT_REF_NAME}" \
         --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?include_merged_yaml=true&dry_run=true&ref=${CI_COMMIT_SHA}" \
         -H "Content-Type: application/json" \
         -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" \
         --output $MERGED_RESPONSE \
         --data-binary @-
    - cat $MERGED_RESPONSE | jq

    - jq -r ".merged_yaml" $BASELINE_RESPONSE > $ARTIFACTS_BASELINE_YAML
    # lint the whole merged thing statically (previous call tries to run pipeline which does not work because ivas-codec does not have push pipelines...)
    - jq -r ".merged_yaml" $MERGED_RESPONSE > $ARTIFACTS_MERGED_YAML
    - rm $MERGED_RESPONSE
    - |
      jq -n --arg yaml "$(<$ARTIFACTS_MERGED_YAML)" '{ content: $yaml }' \
      | curl -sS -X POST \
         --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?" \
         -H "Content-Type: application/json" \
         -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" \
         --output $MERGED_RESPONSE \
         --data-binary @-

    - echo "=== Computing diff ==="
    - dyff between $ARTIFACTS_BASELINE_YAML $ARTIFACTS_MERGED_YAML | tee $ARTIFACTS_DIFF_YAML || true

@@ -120,19 +140,17 @@ check-merged-ci-config-is-valid:
 
    # Show errors if invalid
    - |

      if [ "$baseline_valid" != "true" ]; then
        echo "=== WARNING: BASELINE CONFIG IS INVALID ==="
        jq -r ".errors" $BASELINE_RESPONSE
      fi
    - |
      if [ "$merged_valid" != "true" ]; then
        echo "=== MERGED CONFIG IS INVALID ==="
        jq -r ".errors" $MERGED_RESPONSE
        exit 1
      fi
 
    - |

      if [ "$baseline_valid" != "true" ]; then
        echo "=== WARNING: BASELINE CONFIG IS INVALID ==="
        jq -r ".errors" $BASELINE_RESPONSE
      fi

  artifacts:
    when: always