美文网首页
Jenkins-iOS组件pod自动化脚本

Jenkins-iOS组件pod自动化脚本

作者: FieryDragon | 来源:发表于2023-03-15 13:47 被阅读0次
    #!/bin/bash -l
    
    export LANG=en_US.UTF-8
    
    echo "执行脚本"
    
    component_local_url_name_length=${#COMPONENT_LOCAL_URL}
    if [ "$component_local_url_name_length" = "0" ];then
        echo "私有库本地路径不能为空"
        exit 1
    fi
    
    lib_name_length=${#LIB_NAME}
    if [ "$lib_name_length" = "0" ];then
        echo "私有库名不能为空"
        exit 1
    fi
    
    cd "$COMPONENT_LOCAL_URL"
    
    #创建私有索引库
    echo "是否创建私有索引库:$IF_POD_REPOS"
    if [ "$IF_POD_REPOS" = "0" ]; then
        echo "不创建私有索引库....."
    else
        echo "创建私有索引库😊😊..."
        POD_REPOS_URL='http://***/component/component-ios-specs.git'
        repos_name_git=${POD_REPOS_URL##*/}
        repos_name=${repos_name_git%.*}
        
        tdspec_path=("~/.cocoapods/repos/$repos_name")
        if [ ! -d "$tdspec_path" ] ; then
            echo "开始创建私有索引库路径$tdspec_path"
            pod repo add "$repos_name" "$POD_REPOS_URL"
        fi
        echo "创建私有索引库完成😊😊..."
    fi
    
    
    #创建私有库
    #echo "创建私有库😊😊..."
    #echo "是否创建私有库:$IF_POD_LIB_CREATE"
    #if [ "$IF_POD_LIB_CREATE" = "0" ]; then
    #    echo "不创建私有库....."
    #else
    # 
    #    echo "iOS\nObjC\nYes\nNone\nNo\nYS\n"|pod lib create "$LIB_NAME"
    #fi
    #echo "创建私有库完成😊😊..."
    
    #关联远端仓库
    lib_url_length=${#LIB_URL}
    if [ "$lib_url_length" != "0" ];then
        echo "关联远端仓库😊😊..."
        git remote add origin "$LIB_URL"
        echo "关联远端仓库完毕😊😊..."
    fi
    
    
            #临时数据
    temp_path="$COMPONENT_LOCAL_URL/TempPath"
    if [ ! -d "$temp_path" ] ; then
        mkdir -pv $temp_path
    fi
    NewDATE=`date +%s`
    
    #git提交
    git_commit_length=${#GIT_COMMIT}
    if [ "$git_commit_length" != "0" ];then
    
            cd "$COMPONENT_LOCAL_URL/Example"
            echo "更新pod😊😊..."
            
            pod install | tee "$temp_path/$NewDATE.log"
            # 判断是否安装成功
            if cat $temp_path/$NewDATE.log | grep "Pod installation complete!" > /dev/null
            then
                echo "pod install成功 🌹🌹🌹🌹🌹🌹"
            else
                echo "pod install失败 ⚠️⚠️⚠️⚠️⚠️⚠️"
                rm -rf $temp_path
                exit 1
            fi
            echo "更新pod完毕😊😊..."
            
            
            cd "$COMPONENT_LOCAL_URL"
            echo "验证podspec是否有效😊😊..."
            #pod lib lint --allow-warnings  | tee "$temp_path/$NewDATE.log"
            pod lib lint --allow-warnings --verbose --use-libraries --no-clean --sources="$POD_REPOS_URL,https://github.com/CocoaPods/Specs"  | tee "$temp_path/$NewDATE.log"
            # 判断是否验证成功
            if cat $temp_path/$NewDATE.log | grep "$LIB_NAME passed validation." > /dev/null
            then
                echo "验证podspec成功 🌹🌹🌹🌹🌹🌹"
            else
                echo "验证podspec失败 ⚠️⚠️⚠️⚠️⚠️⚠️"
                rm -rf $temp_path
                exit 1
            fi
            echo "验证podspec完毕😊😊..."
            
            
            echo "提交😊😊..."       
            git stauts
            git add .
            git commit -m "$GIT_COMMIT"
            git push -f origin main
            echo "提交完毕😊😊..."        
    fi
    
    
    #tag版本
    git_tag_length=${#GIT_TAG}
    if [ "$git_tag_length" != "0" ];then
        echo "tag更新😊😊..."
        git tag -a "$GIT_TAG" -m "$GIT_TAG"
        git push origin --tags
        echo "同步更新😊😊..."
    fi
    
    
    #同步索引库
    if [ "$POD_REPO_PUSH" = "1" ];then
        echo "同步索引库😊😊..."
        pod repo push "$repos_name" "$LIB_NAME.podspec" --allow-warnings --verbose --use-libraries --sources="$POD_REPOS_URL,https://github.com/CocoaPods/Specs"| tee "$temp_path/$NewDATE.log"
                # 判断是否验证成功
        if cat $temp_path/$NewDATE.log | grep "Pushing the" > /dev/null
        then
            echo "同步索引库成功 🌹🌹🌹🌹🌹🌹"
        else
            echo "同步索引库失败 ⚠️⚠️⚠️⚠️⚠️⚠️"
            rm -rf $temp_path
            exit 1
        fi
      
        echo "同步索引库完毕😊😊..."
    fi
    
    rm -rf $temp_path
    exit 0
    
    

    相关文章

      网友评论

          本文标题:Jenkins-iOS组件pod自动化脚本

          本文链接:https://www.haomeiwen.com/subject/vgqtlktx.html