Commit 58552ee8 authored by Thomas Boni's avatar Thomas Boni
Browse files

ci: use new template release job

parent e267899b
Loading
Loading
Loading
Loading
+2 −47
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ stages:
include:
  - remote: 'https://api.r2devops.io/job/r/r2devops-bot/links_checker/0.2.0.yml?ignore=true.yml'
  - remote: 'https://api.r2devops.io/job/r/r2devops-bot/codespell/0.1.0.yml?ignore=true.yml'
  - remote: 'https://api.r2devops.io/job/r/r2devops-bot/template_release/0.1.0.yaml?ignore=true.yml'

variables:
  IMAGE_TAG_PYTHON_ALPINE: "alpine3.16"
@@ -256,53 +257,7 @@ codespell:

# See https://docs.gitlab.com/ee/api/releases/
# We can only control the link to the hub, the release is still storing the source code
release:
  stage: deploy
  image:
    name: alpine/httpie:${IMAGE_TAG_HTTPIE_ALPINE}
    entrypoint: [""]
  variables:
    PIPENV_PIPFILE: tools/notify/Pipfile
  before_script:
    - apk update && apk add --no-cache bash
    - pip install --ignore-installed distlib pipenv
    - pipenv install

  script: >
    PROJECT_ENCODED=$(/bin/bash -c "$(http --ignore-stdin --body https://gist.githubusercontent.com/cdown/1163649/raw/8a35c36fdd24b373788a7057ed483a5bcd8cd43e/gistfile1.sh) && _encode '$CI_PROJECT_PATH'");

    for JOB in jobs/*; do
      JOB=$(basename ${JOB})
      # Retrieve all versions of the job inside the CHANGELOG file, ## [(0.2.0)] - 2021-04-20 => get only this part ()
      VERSIONS=$(sed -rn 's/^##\s*\[\s*([^\ ]*)\s*\]\s*-\s*[0-9]{4}-[0-9]{2}-[0-9]{2}\s*/\1/p' jobs/${JOB}/CHANGELOG.md)
      for VERSION in ${VERSIONS}; do
        #Retrieve the changes between two versions
        CHANGELOG=$(sed -n "/^##\s*\[\s*${VERSION}\s*\]/,/^##/p" jobs/${JOB}/CHANGELOG.md | sed -e '/^$/d' | head -n -1 | tail -n +2)
        #For initial version, we don't have a previous version, so set to default message
        [ -z "${CHANGELOG}" ] && CHANGELOG=$(sed -n "/^##\s*\[\s*$VERSION\s*\]/,/^[^##]/p" jobs/${JOB}/CHANGELOG.md | sed -e '/^$/d' | tail -n +2)
        STAGE=$(sed -rn 's/^\s*stage\s*:\s*([a-z]*)/\1/p' jobs/${JOB}/${JOB}.yml )
        result=$(http --ignore-stdin POST https://gitlab.com/api/v4/projects/$PROJECT_ENCODED/releases \
          "JOB-TOKEN: ${CI_JOB_TOKEN}" \
          tag_name=${JOB}-${VERSION} \
          ref=${CI_COMMIT_SHA} \
          "description=${CHANGELOG}" \
          'assets:={"links": [{"name": "Hub link", "url": "https://jobs.r2devops.io/'"${VERSION}/${JOB}"'.yml"}]}')

          if [ $(echo $result | grep "Release already exists\|${JOB}-${VERSION}" | wc -l) -eq 0 ]; then
            echo "[ERROR] Problem when attempting to create release ${JOB}-${VERSION}"
            echo "[ERROR] ${result}"
            exit 1;
          else
            if [ $(echo ${result} | grep "Release already exists" | wc -l) -eq 0 ]; then
              echo "New version detected for $JOB-$VERSION, sending notification to discord"
              pipenv run python tools/notify/discord_release_notify.py -n ${JOB} -v ${VERSION} -c "${CHANGELOG}" -s ${STAGE}
            fi

            echo "Processed ${JOB}-${VERSION} : ${result}";
          fi

      done
    done
template_release:
  rules:
   - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH_SLUG == "r2devops-hub"'