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

add getting the baseline yml

parent 2ce856d0
Loading
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -39,13 +39,24 @@ check-merged-ci-config-is-valid:
    - 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 the thing we got from main branch of $REPO
    # get the "baseline" yaml for comparison. this is always the thing we have on the MR target branch (usually main)
    - git checkout $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    - base_yml="base-$CI_MERGE_REQUEST_TARGET_BRANCH_NAME-ci.yml
    # patch the yaml file to include the stuff we have locally in this branch
    - cp $test_yml $base_yml
    - |
      sed -i".bak" '/^include:/,$d' $base_yml
    - cat $base_yml
    - |
      jq -n --arg yaml "$(<$test_yml)" '.content=$yaml' \
      echo -e "include:\n  - local: ${patch_yml}\n" >> $base_yml
    - cat $base_yml
    # lint patched yaml
    - |
      jq -n --arg yaml "$(<$base_yml)" --arg ref "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" '{ content: $yaml, ref: $ref }' \
      | curl -sS -X POST \
             --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?include_merged_yaml=true" \
             -H "Content-Type: application/json" \
             -H "JOB-TOKEN: $CI_JOB_TOKEN" \
             -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" \
             --output $BASELINE_RESPONSE \
             --data-binary @-