Commit 9ca503ba authored by Naum Spaseski's avatar Naum Spaseski
Browse files

Added gitlab_ci

parents
Loading
Loading
Loading
Loading
+142 −0
Original line number Diff line number Diff line
# CI/CD:
#
# GENERATION triggered by:
#  - merge request
#

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" # Creation of Merge Request (generation of CR)
    - if: $CI_PIPELINE_SOURCE == "trigger" # Upgrade of the index.html page
    - if: $CI_COMMIT_TAG # Creation of tag (publish spec)
    - if: $CI_PIPELINE_SOURCE == "web" # Removal of a specific entry
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never # Pipeline to be run manually as defined in the contribution procedure as it is not known when the CR is ready

variables:

stages:
  - checking
  - generation
  - publication
  - web

Checking conflicts:
  stage: checking
  rules:
    - if: $CI_MERGE_REQUEST_TITLE !~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_MILESTONE
      when: always
      variables:
        MERGE_REQUEST_MILESTONE: $CI_MERGE_REQUEST_MILESTONE
    - if: $CI_MERGE_REQUEST_TITLE !~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_MILESTONE == null
      when: always
      variables:
        MERGE_REQUEST_MILESTONE: "all"
  allow_failure: true
  image: python:3.9.18-slim-bullseye
  tags:
    - docker
  before_script:
    # Installation of required software
    - apt-get update -qq && apt-get -qq install -y git curl jq > /dev/null
    - |
     curl "https://git.onem2m.org/api/v4/projects/42/repository/files/checking_conflicts%2Esh/raw?ref=master" >> checking_conflicts.sh
    - chmod +x checking_conflicts.sh
    - git clone "https://oauth2:${SPECIFICATIONS_PIPELINE_TOKEN}@$CI_SERVER_HOST/rep/$CI_PROJECT_PATH.git" ${CI_PROJECT_NAME}
  script:
    - echo 'Checking conflicts'
    - ./checking_conflicts.sh ${CI_API_V4_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${MERGE_REQUEST_MILESTONE} ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} ${CI_MERGE_REQUEST_IID} ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} ${CI_PROJECT_NAME} "$GITLAB_USER_NAME" $GITLAB_USER_EMAIL $SPECIFICATIONS_PIPELINE_TOKEN
  artifacts:
    when: on_failure
    paths:
      - conflicting_merge_requests.txt
    expose_as: 'Checking conflicts log'

Word CR:
  stage: generation
  rules:
    - if: $CI_MERGE_REQUEST_TITLE !~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "merge_request_event"
      when: on_success
  dependencies: []
  when: on_success
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2FgenerateCR%2Fgenerate_changemarks%2Esh/raw?ref=main" >> generate_changemarks.sh
    - chmod +x generate_changemarks.sh
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fdata_delimiter_start%2Edocx/raw?ref=main" >> data_delimiter_start.docx
    #- |
    # curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fdata_delimiter_end%2Edocx/raw?ref=specifications" >> data_delimiter_end.docx
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fdata_coversheet_template%2Edocx/raw?ref=main" >> data_coversheet_template.docx
    #- |
    # curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/specifications%2FSpec-template%2Edocx/raw?ref=specifications" >> data_spec_template.docx
  script:
    - echo 'CR contribution'
    - mkdir docs
    - ./generate_changemarks.sh ${CI_PROJECT_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${CI_MERGE_REQUEST_IID} data_delimiter_start.docx data_coversheet_template.docx $SPECIFICATIONS_PIPELINE_TOKEN
  artifacts:
    paths:
      - docs/
    expose_as: 'Word CR'
    
Baseline contribution:
  stage: generation
  rules:
    - if: $CI_MERGE_REQUEST_TITLE =~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "merge_request_event"
      when: on_success
  dependencies: []
  when: on_success
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/publish_spec%2Esh/raw?ref=main" >> publish_spec.sh
    - chmod +x publish_spec.sh
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2FSpec-template%2Edocx/raw?ref=main" >> data_spec_template.docx
    - |
     export SPEC_NAME=$(ls | grep T*.md | cut -d'.' -f1)
     export BASELINE_VERSION=$(echo ${CI_MERGE_REQUEST_TITLE} | grep -o v.*_baseline | cut -d'_' -f1-3 )
  script:
    - echo 'Generating baseline'
    - ./publish_spec.sh ${CI_PROJECT_URL} ${BASELINE_VERSION} data_spec_template.docx $SPEC_NAME "onlyDocx"
  artifacts:
    name: "Baseline"
    paths:
      - baseline/
    expose_as: 'Baseline'
      
# Do not protect branch until creation and update of merge request can be differenciated for triggering pipeline, otherwise branch is protected_branches
# with a single update of a merge request (which is not desired). This should be run only for a creation of merge request
# Protect branch:
#   stage: generation
#   when: on_success
#   needs: ["Word CR"]
#   only:
#     - merge_requests
#   script:
#     - |
#      curl --request POST --header "PRIVATE-TOKEN: ${ACCESS_TOKEN}" "${CI_API_V4_URL}/projects/${CI_MERGE_REQUEST_PROJECT_ID}/protected_branches?name=${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}"
#

Publish spec:
  stage: publication
  only:
    - tags
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fpublish_spec%2Esh/raw?ref=main" >> publish_spec.sh
    - chmod +x publish_spec.sh
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2FSpec-template%2Edocx/raw?ref=main" >> data_spec_template.docx
    - |
     export SPEC_NAME=$(ls | grep -E "(GS|GR).*\.md" | cut -d'.' -f1)
  script:
    - echo 'Publishing spec'
    - ./publish_spec.sh ${CI_PROJECT_URL} ${CI_COMMIT_TAG} data_spec_template.docx $SPEC_NAME
  artifacts:
    name: "${CI_PROJECT_NAME}_${CI_COMMIT_TAG}"
    paths:
      - "baseline/*_${CI_COMMIT_TAG}.docx"
      - "baseline/*_${CI_COMMIT_TAG}.pdf"
      - "baseline/*_${CI_COMMIT_TAG}.epub"