Commit 4370edde authored by Jan Kiene's avatar Jan Kiene
Browse files

try with patching and running the lint locally

parent 4873af41
Loading
Loading
Loading
Loading
Loading
+16 −25
Original line number Diff line number Diff line
@@ -12,12 +12,6 @@ workflow:
      when: never
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

variables:
  REPO_URL_FLOAT: "https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec"
  REPO_URL_BASOP: "https://forge.3gpp.org/rep/sa4/audio/ivas-basop"
  PROJECT_ID_FLOAT: "49"
  PROJECT_ID_BASOP: "77"

check-merged-ci-config-is-valid:
  stage: test
  tags:
@@ -28,6 +22,8 @@ check-merged-ci-config-is-valid:
    ARTIFACTS_MERGED_YAML: "merged.yml"
    ARTIFACTS_BASELINE_YAML: "baseline.yml"
    ARTIFACTS_DIFF_YAML: "diff.yml"
    REPO_URL_FLOAT: "https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec"
    REPO_URL_BASOP: "https://forge.3gpp.org/rep/sa4/audio/ivas-basop"
  parallel:
    matrix:
      - REPO:
@@ -35,41 +31,36 @@ check-merged-ci-config-is-valid:
        - ivas-basop
  script:
    # - set -euxo pipefail
    - 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
    - |
      curl -H "JOB-TOKEN: $CI_JOB_TOKEN" "https://forge.3gpp.org/rep/api/v4/projects/$project_id/repository/files/.gitlab-ci.yml?ref=main"

    - |
      curl -X POST -H "Content-Type: application/json" -H "JOB-TOKEN: $CI_JOB_TOKEN" --data '{"content": "stages: [test]\n"}' "https://forge.3gpp.org/rep/api/v4/projects/$project_id/ci/lint?include_merged_yaml=true&ref=main" --output test_output.json
    - cat test_output.json
    - if [ "$REPO" == "ivas-codec" ]; then repo_url=$REPO_URL_FLOAT; patch_yaml="main-float.yml"; fi
    - if [ "$REPO" == "ivas-basop" ]; then repo_url=$REPO_URL_BASOP; patch_yaml="main-basop-yml";fi

    # 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
    # get the "baseline" yaml for comparison. this is always the thing we got from main branch of $REPO
    - |
      jq -n --arg yaml "$(<$test_yml)" '.content=$yaml' \
      | curl -sS -X POST \
             --url "https://forge.3gpp.org/rep/api/v4/projects/$project_id/ci/lint?include_merged_yaml=true" \
             --url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/ci/lint?include_merged_yaml=true" \
             -H "Content-Type: application/json" \
             # -H "PRIVATE-TOKEN: $LINT_TOKEN_FLOAT" \
             -H "JOB-TOKEN: $CI_JOB_TOKEN" \
             --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
    # patch the yaml file to include the stuff we have locally in this branch
    - |
      sed -i".bak" -E '/^include:/,/^[^[:space:]]/c\                                                                                                                                                                                                                                                                              (base)
      include:\
        - local: ${patch_yaml}' $test_yml
    - cat $test_yml

    # lint patched yaml
    - |
      jq -n --arg yaml "$(<$test_yml)" '.content=$yaml' \
      | curl -sS -X POST \
             --url "https://forge.3gpp.org/rep/api/v4/projects/$project_id/ci/lint?include_merged_yaml=true" \
             --url "${CI_API_V4_URL}/v4/projects/${CI_PROJECT_ID}/ci/lint?include_merged_yaml=true" \
             -H "Content-Type: application/json" \
             # -H "PRIVATE-TOKEN: $LINT_TOKEN_FLOAT" \
             -H "JOB-TOKEN: $CI_JOB_TOKEN" \
             --output $MERGED_RESPONSE \
             --data-binary @-