Commit 47fd880c authored by Naum Spaseski's avatar Naum Spaseski Committed by Miguel Angel Reina Ortega
Browse files

Support for markdown specifications

OpenAPI publication in a branch for each repo instead of Gitlab pages
parent be2e3c64
Loading
Loading
Loading
Loading
+13 −21
Original line number Diff line number Diff line
@@ -29,28 +29,20 @@ Validate OpenAPIs:
    - if: $CLEAN_WEB_PAGES == "false"
      when: always
    
pages:
Publication OpenaAPIs:
  stage: publish
  dependencies:
    - Validate OpenAPIs
  needs: ["Validate OpenAPIs"]
  before_script:
    - git clone "https://gitlab-ci-token:${CI_JOB_TOKEN}@$CI_SERVER_HOST/rep/$CI_PROJECT_PATH.git" ${CI_PROJECT_NAME}
    - cd $CI_PROJECT_NAME  # Go to cloned repo
    - git checkout openapis || git checkout -b openapis
  script: 
    # Get the previous GitLab Pages content
    - set +e
    - curl --fail "$CI_PAGES_URL/content.zip" -o "content.zip"
    - if [ -e "content.zip" ]; then unzip "content.zip"; rm "content.zip"; fi
    - set -e
    # Add/update content
    - if [[ -n "$CI_COMMIT_TAG" ]]; then mkdir -p "public/$CI_COMMIT_TAG"; cp -r -f build/* public/$CI_COMMIT_TAG; fi
    - if [ "$CLEAN_WEB_PAGES" != "false" ]; then echo "Removing folder $CLEAN_WEB_PAGES..."; rm -r public/$CLEAN_WEB_PAGES; fi
    # Remove all pdf files
    - rm -f public/*/*.pdf
    # Zip the content and publish the zip again
    - zip -r "content.zip" "public"
    - mv "content.zip" "public/"
    - du -h public/
  artifacts:
    paths:
      - public
    - echo 'Publish OpenAPI $CI_COMMIT_TAG'
    - mkdir -p "$CI_COMMIT_TAG"
    - cp -r -f ../build/* $CI_COMMIT_TAG
    - git add $CI_COMMIT_TAG/*
    - git commit -m "Added new version $CI_COMMIT_TAG"
    - git push --push-option="ci.skip" -u origin openapis
  rules:
    # Job executed when creating a tag
    - if: $CI_COMMIT_TAG
+162 −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: forge.etsi.org:5050/cti/md-specs-dev/tools/generatecr:master
  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'
    - /generateCR/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%2Fgenerate_changemarks%2Esh/raw?ref=nfv" >> generate_changemarks.sh
    - chmod +x generate_changemarks.sh
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fnfv_delimiter_start%2Edocx/raw?ref=nfv" >> nfv_delimiter_start.docx
    #- |
    # curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fmec_delimiter_end%2Edocx/raw?ref=specifications" >> mec_delimiter_end.docx
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fnfv_coversheet_template%2Edocx/raw?ref=nfv" >> nfv_coversheet_template.docx
    #- |
    # curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/specifications%2FSpec-template%2Edocx/raw?ref=specifications" >> mec_spec_template.docx
  script:
    - echo 'CR contribution'
    - mkdir docs
    - ./generate_changemarks.sh ${CI_PROJECT_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${CI_MERGE_REQUEST_IID} nfv_delimiter_start.docx nfv_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" >> mec_spec_template.docx
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2FETSI_GR_cover_skeleton%2Edocx/raw?ref=main" >> ETSI_GR_cover_skeleton.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} mec_spec_template.docx $SPEC_NAME ETSI_GR_cover_skeleton.docx "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=nfv" > publish_spec.sh
    - chmod +x publish_spec.sh
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fgenerate_releasenotes%2Esh/raw?ref=nfv" > generate_releasenotes.sh
    - chmod +x generate_releasenotes.sh
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2Fnfv_release_notes_template%2Edocx/raw?ref=nfv" > release_notes_template.docx
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2FSpec-template%2Edocx/raw?ref=nfv" > nfv_spec_template.docx
    - |
     export SPEC_NAME=$(ls | grep -E "(GS|GR).*\.md" | cut -d'.' -f1)
    - |
      echo 'Checking if GS or GR specification'
      if [[ $SPEC_NAME =~ ^GS.* ]]
      then
        curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2FETSI_GS_cover_skeleton%2Edocx/raw?ref=nfv" > nfv_cover_skeleton.docx
      elif [[ $SPEC_NAME =~ ^GR.* ]]
      then
        curl "${CI_API_V4_URL}/projects/$PIPELINE_SCRIPTS_PROJECT_ID/repository/files/specifications%2FETSI_GR_cover_skeleton%2Edocx/raw?ref=main" > nfv_cover_skeleton.docx
      else
        echo 'Specification is not a GS or GR specification'
        exit 1
      fi
  script:
    - echo 'Publishing spec'
    - ./publish_spec.sh ${CI_COMMIT_TAG} nfv_spec_template.docx ${CI_PROJECT_NAME} nfv_cover_skeleton.docx
    - ./generate_releasenotes.sh ${CI_PROJECT_URL} ${CI_PROJECT_ID} ${CI_COMMIT_TAG} release_notes_template.docx "$GITLAB_USER_NAME" $SPECIFICATIONS_PIPELINE_TOKEN
  artifacts:
    name: "${CI_PROJECT_NAME}_${CI_COMMIT_TAG}"
    paths:
      - "baseline/*_${CI_COMMIT_TAG}.docx"
      #- "baseline/*_${CI_COMMIT_TAG}.pdf"
      #- "baseline/*_${CI_COMMIT_TAG}.epub"
+118 KiB

File added.

No diff preview for this file type.

+118 KiB

File added.

No diff preview for this file type.

+580 KiB

File added.

No diff preview for this file type.

Loading