Commit 91d5ed10 authored by Jan Kiene's avatar Jan Kiene
Browse files

cleanup + comments

parent 41c2601a
Loading
Loading
Loading
Loading
Loading
+15 −32
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ workflow:
      when: never
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

# Get the merged CI config for ivas-codec and ivas-basop repos based on the current branch and check for it to be valid.
check-merged-ci-config-is-valid:
  stage: test
  tags:
@@ -25,10 +26,9 @@ check-merged-ci-config-is-valid:
        - ivas-basop

  script:
    - set -euxo pipefail
    - set -euo pipefail

    - |

      if [ "$REPO" == "ivas-codec" ]; then
        repo_url=$REPO_URL_FLOAT
        patch_yml="main-float.yml"
@@ -46,32 +46,27 @@ check-merged-ci-config-is-valid:
    - TEST_YML="${REPO}-ci.yml"
    - BASE_YML="${REPO}-base-ci.yml"

    # Get CI file from the respective repo
    - curl -sS --url "${repo_url}/-/raw/main/.gitlab-ci.yml?inline=false" --output $TEST_YML
    # - echo "=== Original CI file ==="
    # - cat $TEST_YML
    #
    # - |
    #   echo "Target branch SHA: $CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
    # - |
    #   echo "Current commit SHA: $CI_COMMIT_SHA"
 
    - git fetch origin
    - git checkout $CI_COMMIT_REF_NAME

    # Approach for validating the CI configs:
    # Due to intricacies of gitlab API token perissions/setup, the setup is a bit convoluted. We can't
    # just call the the lint API endpoint of the repective repos, but instead need to
    #   - get the CI file from the respective repo (which includes from this repo's main)
    #   - patch the include section so that it includes the correct local file in this repo (main-float.yml or main-basop-yml)
    #   - call CI lint in THIS repo with passing the patched file -> this should have the same result as the other repo included remotely
    #   - to get the merged yaml back, we need to pass dry_run: true, BUT this causes CI lint to actually run a pipeline which fails
    #     because there are no push pipeline defined...
    #   - so now we need to use the merged yaml file that we got back to again run the static lint and then finally we get a result for the whole thing being valid
 
    # Get CI file from the respective repo
    - curl -sS --url "${repo_url}/-/raw/main/.gitlab-ci.yml?inline=false" --output $TEST_YML

    - cp $TEST_YML $BASE_YML
    - sed -i '/^include:/,$d' $BASE_YML
    - |
      echo -e "include:\n  - local: ${patch_yml}" >> $BASE_YML
    # - echo "=== Baseline CI file (target branch) ==="
    # - cat $BASE_YML

    # Debug: Check if files actually differ between refs
    # - echo "=== Checking ${patch_yml} at both refs ==="
    # - |
    #   curl -sS "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/files/${patch_yml}?ref=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}" -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" | jq -r .content | base64 -d | sha256sum
    # - |
    #   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

    # Get merged baseline with target branch ref
    - |
@@ -99,12 +94,6 @@ check-merged-ci-config-is-valid:
    - sed -i '/^include:/,$d' $TEST_YML
    - |
      echo -e "include:\n  - local: ${patch_yml}" >> $TEST_YML
    # - echo "=== Current CI file (feature branch) ==="
    # - cat $TEST_YML

    # Show what the local file looks like
    # - echo "=== First 50 lines of ${patch_yml} ==="
    # - head -n 50 $patch_yml

    # Get current with feature branch ref
    - |
@@ -135,12 +124,6 @@ check-merged-ci-config-is-valid:
    # Check validity
    - baseline_valid=$(jq -r ".valid" $BASELINE_RESPONSE)
    - merged_valid=$(jq -r ".valid" $MERGED_RESPONSE)
    - |
      echo "Baseline valid: $baseline_valid"
    - |
      echo "Merged valid: $merged_valid"
 
    # Show errors if invalid
    - |
      if [ "$baseline_valid" != "true" ]; then
        echo "=== WARNING: BASELINE CONFIG IS INVALID ==="