Commit 309cb9ce authored by Ruben ten Hove's avatar Ruben ten Hove Committed by Federico Falconieri
Browse files

feat: clear warning when badges cannot be created

parent 3d2c4dbe
Loading
Loading
Loading
Loading
+31 −26
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@

# Choose a color from this list: https://github.com/jongracecox/anybadge#colors

# Make sure your rules at least include the requirement of $GL_TOKEN

.badge:
  image: registry.gitlab.com/just-ci/images/anybadge:latest
  stage: .post
@@ -35,12 +33,6 @@
      echo -e "[+] Created ci_badges/${BADGE_NAME}.svg:\n- Label: ${LABEL}\n- Value: ${VALUE}\n- Color: ${COLOR}\n- URL: ${URL}"

    - |
      if [ -z "${GL_TOKEN}" ]; then
        echo "[!] GL_TOKEN not set. You can check the badge in the artifacts. It will not be automatically installed/updated in your project."
        echo "[?] You can set it manually. Create/update a badge named '${BADGE_NAME}' with the image URL ${IMAGE_URL} and as the link URL ${URL:-$CI_PROJECT_URL}."
        echo "[?] You can also set this badge anywhere else. Just reference the image ${IMAGE_URL}."
        exit 1
      else
      echo "[*] Creating/updating badge..."
      BADGE_ID=$(curl -SsLf -H "PRIVATE-TOKEN: ${GL_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/badges" | jq --arg BADGE_NAME "${BADGE_NAME}" '.[] | select(.name==$BADGE_NAME) | .id') || true
      if [ -z "${BADGE_ID}" ]; then
@@ -60,11 +52,24 @@
        echo "[!] Something went wrong. We received the status code ${STATUS_CODE}."
        exit 1
      fi
      fi
  artifacts:
    paths:
      - ci_badges/*.svg
    when: always
  allow_failure: true
  rules:
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $GL_TOKEN"

badge:GL_TOKEN-required:
  stage: .pre
  image: docker.io/alpine:3
  variables:
    GIT_STRATEGY: none
  script:
    - |
      echo "[!] GL_TOKEN not set. Please add a GL_TOKEN per the instructions: https://gitlab.com/just-ci/templates#how-to-use"
      echo "[!] Badges will not be created."
    - exit 1
  rules:
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $GL_TOKEN == null"
  allow_failure: true