Commit 5e0803db authored by Nikos Psaromanolakis's avatar Nikos Psaromanolakis
Browse files

fix: Edit .gitlab-ci.yml

parent af79213d
Loading
Loading
Loading
Loading
Loading
+50 −17
Original line number Diff line number Diff line
@@ -771,7 +771,11 @@ nightly_compare_failed_images_job:
        FAILED_TAG="$2"
        REPOSITORIES_URL="$3"

        echo "Commit lookup for: $IMAGE_PATH" >&2
        echo "Repository API URL: $REPOSITORIES_URL" >&2

        if [ -z "$REPOSITORIES_URL" ]; then
          echo "Commit lookup failed: repository API URL is empty." >&2
          printf '%s\n' "Unknown"
          return
        fi
@@ -784,38 +788,54 @@ nightly_compare_failed_images_job:
            --header "PRIVATE-TOKEN: $GROUP_ACCESS_TOKEN" \
            --url "$REPOSITORIES_URL"
        ) || {
          echo "Commit lookup failed: could not list registry repositories." >&2
          printf '%s\n' "Unknown"
          return
        }

        REPOSITORY_ID=$(
        echo "Repositories returned by API:" >&2
        printf '%s\n' "$REPOSITORIES_JSON" |
          jq -r '.[] | "  id=\(.id) project_id=\(.project_id) location=\(.location)"' \
          >&2

        REPOSITORY_DATA=$(
          printf '%s' "$REPOSITORIES_JSON" |
            jq -r \
              --arg IMAGE_PATH "$IMAGE_PATH" \
              '.[] |
               select(.location == $IMAGE_PATH) |
               .id' |
              '
                .[]
                | select(
                    .location == $IMAGE_PATH
                    or
                    ($IMAGE_PATH | endswith(.path))
                  )
                | "\(.id) \(.project_id)"
              ' |
            head -n 1
        )

        REPOSITORY_ID=$(
          printf '%s\n' "$REPOSITORY_DATA" |
            awk '{print $1}'
        )

        PROJECT_ID=$(
          printf '%s' "$REPOSITORIES_JSON" |
            jq -r \
              --arg IMAGE_PATH "$IMAGE_PATH" \
              '.[] |
               select(.location == $IMAGE_PATH) |
               .project_id' |
            head -n 1
          printf '%s\n' "$REPOSITORY_DATA" |
            awk '{print $2}'
        )

        if [ -z "$REPOSITORY_ID" ] ||
          [ "$REPOSITORY_ID" = "null" ] ||
          [ -z "$PROJECT_ID" ] ||
          [ "$PROJECT_ID" = "null" ]; then
          echo "Commit lookup failed: matching registry repository was not found." >&2
          printf '%s\n' "Unknown"
          return
        fi

        echo "Repository ID: $REPOSITORY_ID" >&2
        echo "Project ID: $PROJECT_ID" >&2

        FAILED_TAG_JSON=$(
          curl \
            --fail \
@@ -824,6 +844,7 @@ nightly_compare_failed_images_job:
            --header "PRIVATE-TOKEN: $GROUP_ACCESS_TOKEN" \
            --url "${CI_API_V4_URL}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags/${FAILED_TAG}"
        ) || {
          echo "Commit lookup failed: could not retrieve tag $FAILED_TAG." >&2
          printf '%s\n' "Unknown"
          return
        }
@@ -834,10 +855,13 @@ nightly_compare_failed_images_job:
        )

        if [ -z "$FAILED_DIGEST" ]; then
          echo "Commit lookup failed: failed tag has no digest." >&2
          printf '%s\n' "Unknown"
          return
        fi

        echo "Failed image digest: $FAILED_DIGEST" >&2

        PAGE=1

        while true; do
@@ -849,6 +873,7 @@ nightly_compare_failed_images_job:
              --header "PRIVATE-TOKEN: $GROUP_ACCESS_TOKEN" \
              --url "${CI_API_V4_URL}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100&page=${PAGE}"
          ) || {
            echo "Commit lookup failed: could not list registry tags." >&2
            printf '%s\n' "Unknown"
            return
          }
@@ -870,22 +895,29 @@ nightly_compare_failed_images_job:
          )

          for TAG in $COMMIT_TAGS; do
            echo "Checking commit tag: $TAG" >&2

            TAG_JSON=$(
              curl \
                --fail \
                --silent \
                --show-error \
                --header "PRIVATE-TOKEN: $GROUP_ACCESS_TOKEN" \
                --url "${CI_API_V4_URL}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags/${TAG}" \
                2>/dev/null
            ) || continue
                --url "${CI_API_V4_URL}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags/${TAG}"
            ) || {
              echo "Could not retrieve tag details for $TAG." >&2
              continue
            }

            TAG_DIGEST=$(
              printf '%s' "$TAG_JSON" |
                jq -r '.digest // empty'
            )

            echo "Tag $TAG digest: $TAG_DIGEST" >&2

            if [ "$TAG_DIGEST" = "$FAILED_DIGEST" ]; then
              echo "Matching commit found: $TAG" >&2
              printf '%s\n' "$TAG"
              return
            fi
@@ -894,6 +926,7 @@ nightly_compare_failed_images_job:
          PAGE=$((PAGE + 1))
        done

        echo "No matching commit tag found for digest $FAILED_DIGEST." >&2
        printf '%s\n' "Unknown"
      }