Commit 8dd8260a authored by Bart Kamphorst's avatar Bart Kamphorst Committed by Ruben ten Hove
Browse files

feat: provide configuration .badge-raw

parent ce28a428
Loading
Loading
Loading
Loading
+37 −15
Original line number Diff line number Diff line
@@ -2,45 +2,71 @@
# This job will create or update a badge when extended using the following template.
# It requires a Project Access Token or Personal Access Token with api scope set
# as a CI/CD variable called GL_TOKEN.
# To create your own automatic badges, add the following to your .gitlab-ci.yml:
# To create your own automatic badges using anybadge, add the following to your
# .gitlab-ci.yml:

# badge:your_custom_job:
#   extends: .badge
#   variables:
#     LABEL: "version"
#     VALUE: "1.2.3"
#     COLOR: "red"
#     LABEL: "version"  # Manditory unless an anybadge template is provided through BADGE_EXTRA_ARGS.
#     COLOR: "red"  # Optional.
#     URL: "${CI_PROJECT_URL}"
#     BADGE_EXTRA_ARG: "" # Optional. Additional argument to pass to anybadge.
#     BADGE_NAME: ""  # Optional. Name of the badge in Settings. Defaults to $LABEL

# Choose a color from this list: https://github.com/jongracecox/anybadge#colors
# Even fancier usage is displayed here: https://github.com/jongracecox/anybadge#examples

# Alternatively, you may provide your own IMAGE_URL directly:

# badge:your_custom_job:
#   extends: .badge-raw
#   variables:
#     IMAGE_URL: "https://img.shields.io/pypi/v/${PYTHON_PACKAGE}"
#     URL: "https://pypi.org/project/${PYTHON_PACKAGE}"
#     BADGE_NAME: "PyPI"  # Name of the badge in Settings.

# Make sure your_custom_job is replaced and unique, and you've changed the variables
# according to your preferences.

# Choose a color from this list: https://github.com/jongracecox/anybadge#colors
include:
  - local: project-automation/generic.yaml
  - local: project-automation/telemetry.yaml

.badge:
  extends: .telemetry
  image: registry.gitlab.com/just-ci/images/anybadge:latest
  stage: .post
  variables:
    GIT_STRATEGY: none
  extends: .badge-raw
  script:
    - BADGE_NAME=${BADGE_NAME:-${LABEL}}
    - IMAGE_URL=${CI_PROJECT_URL}/-/jobs/artifacts/${CI_DEFAULT_BRANCH}/raw/ci_badges/${BADGE_NAME}.svg?job=${CI_JOB_NAME}
    - set --
    - if [ "${LABEL}" != "" ]; then set -- -l "$LABEL" "$@"; fi
    - if [ "${COLOR}" != "" ]; then set -- -c "$COLOR" "$@"; fi
    - mkdir -p ci_badges
    - anybadge -l "${LABEL}" -v "${VALUE}" -c "${COLOR}" -f
      "ci_badges/${BADGE_NAME}.svg"
    - |
      echo "[+] Created ci_badges/${BADGE_NAME}.svg"
      echo "Label: ${LABEL}"
      echo "Value: ${VALUE}"
      echo "Color: ${COLOR}"
      echo "Extra argument: ${BADGE_EXTRA_ARG}"
      echo "URL: ${URL}"
      echo "Image URL: ${IMAGE_URL}"
      echo "You can use the image URL to point to this badge from, for example, a readme."
    - anybadge -v "${VALUE}" "$@" -f "ci_badges/${BADGE_NAME}.svg"
      ${BADGE_EXTRA_ARG}
    - !reference [.badge-raw, script]
  artifacts:
    paths:
      - ci_badges/*.svg
    when: always

.badge-raw:
  extends: .telemetry
  image: registry.gitlab.com/just-ci/images/anybadge:latest
  stage: .post
  variables:
    GIT_STRATEGY: none
  script:
    - |
      if [ "${DISABLE_BADGE_CREATION}" != "" ]; then
        exit 0
@@ -68,10 +94,6 @@ include:
        echo "[!] Something went wrong. We received the status code ${STATUS_CODE}."
        exit 1
      fi
  artifacts:
    paths:
      - ci_badges/*.svg
    when: always
  allow_failure: true
  rules:
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"