Commit f6c1c5b3 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Naming properly the generated openapi file + creating merge request for the generated openapi

parent 84c454ab
Loading
Loading
Loading
Loading
+18 −11
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ variables:
  LOGFILE_OPENAPI: "openapi-validation.log"
  LOGFILE_OPENAPI: "openapi-validation.log"
  GIT_CLEAN_FLAGS: -ffdxq
  GIT_CLEAN_FLAGS: -ffdxq
  #GIT_SSL_NO_VERIFY: "true"
  #GIT_SSL_NO_VERIFY: "true"
  GIT_STRATEGY: clone


stages:
stages:
  - validation
  - validation
@@ -77,24 +78,30 @@ Generation of OpenAPI:
    - |
    - |
     curl --header "PRIVATE-TOKEN: $PIPELINE_PROJECT_TOKEN" "${CI_API_V4_URL}/projects/694/repository/files/common-openapi%2FgenerateOpenapi%2Esh/raw?ref=autogeneration" >> generateOpenapi.sh
     curl --header "PRIVATE-TOKEN: $PIPELINE_PROJECT_TOKEN" "${CI_API_V4_URL}/projects/694/repository/files/common-openapi%2FgenerateOpenapi%2Esh/raw?ref=autogeneration" >> generateOpenapi.sh
    - chmod +x generateOpenapi.sh
    - chmod +x generateOpenapi.sh
    - |
     curl --header "PRIVATE-TOKEN: $PIPELINE_PROJECT_TOKEN" "${CI_API_V4_URL}/projects/694/repository/files/common-openapi%2Fproject-config%2Eyaml/raw?ref=autogeneration" >> project-config.yaml
    - git clone "https://oauth2:$PIPELINE_ACCESS_TOKEN@$CI_SERVER_HOST/rep/$CI_PROJECT_PATH.git" ${CI_PROJECT_NAME}
    - git clone "https://oauth2:$PIPELINE_ACCESS_TOKEN@$CI_SERVER_HOST/rep/$CI_PROJECT_PATH.git" ${CI_PROJECT_NAME}
  script: 
  script: 
    - echo 'Generate OpenAPI'
    - echo 'Generate OpenAPI'
    - ./generateOpenapi.sh ${CI_PROJECT_NAME}
    - ./generateOpenapi.sh ${CI_PROJECT_NAME} project-config.yaml
  after_script:
  after_script:
    - echo $CI_COMMIT_BRANCH
    - echo $CI_PROJECT_PATH
    - echo $CI_SERVER_HOST
    - echo $(pwd)
    - cd ${CI_PROJECT_NAME}
    - cd ${CI_PROJECT_NAME}
    - |
    - |
     git push --push-option="ci.skip" "https://gitlab-ci-token:$PIPELINE_ACCESS_TOKEN@$CI_SERVER_HOST/rep/$CI_PROJECT_PATH.git"
     git push --push-option="ci.skip" -u origin "openapi-update-$version"
    # Create merge request using GitLab API
    - |
    - |
     git push --push-option="ci.skip" --tags "https://gitlab-ci-token:$PIPELINE_ACCESS_TOKEN@$CI_SERVER_HOST/rep/$CI_PROJECT_PATH.git" 
     curl --request POST \
    #- |
       --header "PRIVATE-TOKEN: $PIPELINE_ACCESS_TOKEN" \
    # git remote add origin "https://gitlab-ci-token:glpat-y3Uu8UsLTzXsHFyPcoH6@$CI_SERVER_HOST/rep/$CI_PROJECT_PATH.git"
       --header "Content-Type: application/json" \
    #- |
       --data "{
    #git push --push-option="ci.skip" origin HEAD:$($CI_COMMIT_BRANCH)
         \"id\": \"$CI_PROJECT_ID\",
         \"source_branch\": \"openapi-update-$version\",
         \"target_branch\": \"$CI_DEFAULT_BRANCH\",
         \"title\": \"Update OpenAPI files to version $version\",
         \"description\": \"Automatically generated OpenAPI files from specification version $version\",
         \"remove_source_branch\": true
       }" \
       "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/merge_requests"
  rules:
  rules:
    - changes:
    - changes:
        - doc/*.docx
        - doc/*.docx
+67 −39
Original line number Original line Diff line number Diff line
#!/bin/bash
#!/bin/bash


DOC2OAS_DOCKER_IMAGE=doc2oas-ie-sample:master
if [ "$#" -ne 2 ]; then

    echo "Usage: $0 <project-path> <project-config.yaml>"
echo "\n------ Checking for docker image --------"
    exit 1
#docker pull "$DOCKER_IMAGE"
fi

echo "------ Parsing repo URL --------"


#HOST_URL=$(echo $1 | cut -d'/' -f 1-3)
DOC2OAS_DOCKER_IMAGE=doc2oas-ie-sample:master
#PROJECT_NAME=$(echo $1 | cut -d'/' -f 5- | cut -d'.' -f 1)
#echo "HOST URL:" $HOST_URL
#echo "PROJECT NAME:" $PROJECT_NAME
#echo "TAG NAME:" $2


echo "------ Getting spec and config files--------"
# Get version from spec file name in root doc directory
# If there is no .docx file or more than one, then simply exit
cd doc
cd doc


spec=$(ls | grep 'docx')
spec=$(ls | grep 'docx')
if [ -z $spec ] ; then 
if [ -z $spec ] ; then 
    echo "-- No spec file"
    echo "-- No spec file"
    exit 0
    exit 0
#Check if there are more than one
fi
fi


config="config.yaml"
version=$(ls | grep -e v[0-9]* -o)
if [ -z "$version" ]; then
    echo "No version found in spec filename"
    exit 1
fi

# Create new branch for the changes in the cloned repo
branch_name="openapi-update-$version"
echo "\n------ Creating new branch $branch_name --------"
cd ../$1  # Go to cloned repo
git checkout -b "$branch_name"
cd ../doc  # Back to root doc directory for processing

echo "\n------ Checking for docker image --------"
#docker pull "$DOCKER_IMAGE"

echo "------ Getting spec and config files--------"
# Get project prefix (e.g., gs030) from the project path
project_prefix=$(echo $1 | grep -o 'gs[0-9]\{3\}')

# Get all config files for this project
configs=$(grep -A20 "^[[:space:]]*$project_prefix:" "$2" | grep "config_file" | sed 's/.*config_file:[[:space:]]*"\(.*\)".*/\1/')

if [ -z "$configs" ]; then
    echo "No config files found for project $project_prefix"
    exit 1
fi

# Process each config file
echo "$configs" | while read -r config; do
    echo "Processing config file: $config"
    
    
echo "\n------ Preparaing spec --------"
    echo "\n------ Preparing spec for $config --------"
echo -e "import sys" | tee -a "command.py"
    echo -e "import sys" | tee "command.py"
    echo -e "\nsys.path.append(\"/app\")" | tee -a "command.py"
    echo -e "\nsys.path.append(\"/app\")" | tee -a "command.py"
    echo -e "\nimport main" | tee -a "command.py"
    echo -e "\nimport main" | tee -a "command.py"
    echo -e "\nif __name__ == '__main__':" | tee -a "command.py"
    echo -e "\nif __name__ == '__main__':" | tee -a "command.py"
    echo -e "\n    sys.exit(main.maindoc2oas(\"/app/tmp/$spec\", \"/app/tmp/$config\"))" | tee -a "command.py"
    echo -e "\n    sys.exit(main.maindoc2oas(\"/app/tmp/$spec\", \"/app/tmp/$config\"))" | tee -a "command.py"
#docker run --rm -v $(pwd):/app/tmp $DOC2OAS_DOCKER_IMAGE "-c 'import main; main.maindoc2oas("/app/doc/$spec", "/app/doc/$config")'"
    
    docker run --rm -v $(pwd):/app/tmp $DOC2OAS_DOCKER_IMAGE tmp/command.py
    docker run --rm -v $(pwd):/app/tmp $DOC2OAS_DOCKER_IMAGE tmp/command.py
    
    
    echo "------ Move generated openapi to the correct folder --------"
    echo "------ Move generated openapi to the correct folder --------"
    
    
    openapi=$(ls | grep gs_*.yaml)
    openapi=$(ls | grep gs_*.yaml)
if [ -z $openapi ] ; then 
    if [ -z "$openapi" ] ; then 
    echo "-- No openapi file"
        echo "-- No openapi file generated for $config"
    exit 0
        continue
else 
    fi
    #mv $openapi ../autogenerated/$openapi
    
	mv $openapi ../$1/autogenerated/$openapi
    # Find corresponding openapi name for this config
    new_name=$(grep -A20 "^[[:space:]]*$project_prefix:" "$2" | grep -B1 "config_file:.*$config" | grep "openapi_name" | sed 's/.*openapi_name:[[:space:]]*"\(.*\)".*/\1/')
    
    if [ ! -z "$new_name" ]; then
        echo "Renaming $openapi to $new_name"
        mv "$openapi" "$new_name"
        openapi="$new_name"
    fi
    fi
    
    
cd .. 
    # Move openapi to the cloned repo
cd $1
    mv "$openapi" ../$1/$openapi
    
    # Add to git in cloned repo
    git add ../$1/$openapi
done


echo "\n------ Prepare to push -------"
echo "\n------ Prepare to push -------"
git add autogenerated/$openapi
cd ../$1  # Go to cloned repo for git operations
version=$(ls doc | grep -e v[0-9]* -o)
git rm doc/$spec
git rm doc/$spec
git commit -m "Autogenerated openapi version $version"
git commit -m "Autogenerated openapi version $version"


echo "\n------ Tag version -----"
# Git push and merge request creation are handled by the CI file
echo $version
git tag $version

exit 0
exit 0
 No newline at end of file
+66 −0
Original line number Original line Diff line number Diff line
# Project configurations
projects:
  gs011:
    configs:
      - config_file: "config-MecAppSupportApi.yaml"
        openapi_name: "MecAppSupportApi.yaml"
      - config_file: "config-MecServiceMgmtApi.yaml"
        openapi_name: "MecServiceMgmtApi.yaml"
  gs012:
    configs:
      - config_file: "config-RniAPI.yaml"
        openapi_name: "RniAPI.yaml"
  gs013:
    configs:
      - config_file: "config-LocationaPI.yaml"
        openapi_name: "LocationaPI.yaml"
  gs014:
    configs:
      - config_file: "config-UEidentityAPI.yaml"
        openapi_name: "UEidentityAPI.yaml"
  gs015:
    configs:
      - config_file: "config-BwManagementApi.yaml"
        openapi_name: "BwManagementApi.yaml"
      - config_file: "config-TrafficSteeringApi.yaml"
        openapi_name: "TrafficSteeringApi.yaml"
  gs016:
    configs:
      - config_file: "config-UEAppInterfaceApi.yaml"
        openapi_name: "UEAppInterfaceApi.yaml"
  gs021:
    configs:
      - config_file: "config-MEC021_AppMobilityService.yaml"
        openapi_name: "MEC021_AppMobilityService.yaml"
  gs028:
    configs:
      - config_file: "config-WlanInformationApi.yaml"
        openapi_name: "WlanInformationApi.yaml"
  gs029:
    configs:
      - config_file: "config-MEC029_FAI.yaml"
        openapi_name: "MEC029_FAI.yaml"
  gs030:
    configs:
      - config_file: "config-MEC030_V2XInformationServices.yaml"
        openapi_name: "MEC030_V2XInformationServices.yaml"
  gs033:
    configs:
      - config_file: "config-MEC033_IoT.yaml"
        openapi_name: "MEC033_IoT.yaml"
  gs040:
    configs:
      - config_file: "config-MEC040_fedEnablement.yaml"
        openapi_name: "MEC040_fedEnablement.yaml"
  gs045:
    configs:
      - config_file: "config-MEC045_QoSMeasurementApi.yaml"
        openapi_name: "MEC045_QoSMeasurementApi.yaml"
  gs046:
    configs:
      - config_file: "config-MEC046_SensorSharingApi.yaml"
        openapi_name: "MEC046_SensorSharingApi.yaml"
  gs048:
    configs:
      - config_file: "config-MEC048_EnablementCustomSelfServiceApi.yaml"
        openapi_name: "MEC048_EnablementCustomSelfServiceApi.yaml"
 No newline at end of file