diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..d313c5ff05b11cb727f4d615ff88f3a6e54cdcac --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,166 @@ +default: + interruptible: true + +stages: + - test + +workflow: + rules: + - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push" + when: never + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + +check-merged-ci-config-is-valid: + stage: test + tags: + - ivas-linux + + 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" + parallel: + matrix: + - REPO: + - ivas-codec + - ivas-basop + + script: + - set -euxo pipefail + + - | + + if [ "$REPO" == "ivas-codec" ]; then + repo_url=$REPO_URL_FLOAT + patch_yml="main-float.yml" + else + repo_url=$REPO_URL_BASOP + patch_yml="main-basop.yml" + fi + + # artifact names + - MERGED_RESPONSE="${REPO}-merged.json" + - BASELINE_RESPONSE="${REPO}-baseline.json" + - ARTIFACTS_MERGED_YAML="${REPO}-merged.yml" + - ARTIFACTS_BASELINE_YAML="${REPO}-baseline.yml" + - ARTIFACTS_DIFF_YAML="${REPO}-diff.yml" + - 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 + + - 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 + - | + 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_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 + - cat $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 @- + + - 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 + - | + 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_SHA}" \ + -H "Content-Type: application/json" \ + -H "PRIVATE-TOKEN: $CI_LINT_TOKEN" \ + --output $MERGED_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" $MERGED_RESPONSE > $ARTIFACTS_MERGED_YAML + - rm $MERGED_RESPONSE + - cat $ARTIFACTS_MERGED_YAML + - | + 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 + + # 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 ===" + jq -r ".errors" $BASELINE_RESPONSE + fi + - | + if [ "$merged_valid" != "true" ]; then + echo "=== MERGED CONFIG IS INVALID ===" + jq -r ".errors" $MERGED_RESPONSE + exit 1 + fi + + + artifacts: + when: always + access: all + expire_in: "5 days" + paths: + - "*-baseline.yml" + - "*-merged.yml" + - "*-diff.yml" + - "*-baseline.json" + - "*-merged.json" diff --git a/main-float.yml b/main-float.yml index 1cc0861e283abfcdd42c1ea9f449578d5186a84a..e60dd180f65a2533bd1a8b8df34a73874a3ed5b2 100644 --- a/main-float.yml +++ b/main-float.yml @@ -21,8 +21,10 @@ stages: - compare - postvalidate - deploy + - new variables: + NEW_VARIABLE_FOR_TESTIN: "vlavsdsfsdf" EVS_BE_TEST_DIR: "/usr/local/be_2_evs_test" EVS_BE_WIN_TEST_DIR: "C:/Users/gitlab-runner/testvec" PROCESSING_SCRIPTS_BIN_DIR: "/test-bin"