分支和主干jar差异shell

分支和主干jar差异

脚本文件见附件,可以快速了解本次分支修改,便于发布前比对当前的开发分支和主干jar差异情况。 将jar-diff.sh放在根目录文件下面。

#!/bin/bash

# 获取当前git分支
CURRENT_BRANCH=`sh -c 'git branch --no-color 2>/dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`

if [ -n "$CURRENT_BRANCH" ]; then
    # 当前分支不为空
    APP_NAME=`cat .git/config | grep url | sed 's/.*\/\(.*\)\.git/\1/g'`
    echo "app name : "${APP_NAME}
    GIT_PATH=`cat .git/config | grep url | sed 's/.*\url = \(.*\)/\1/g'`
    echo "git path : "${GIT_PATH}
    echo "current branch : "${CURRENT_BRANCH}"\n"

    if [ "$CURRENT_BRANCH"x = "master"x ]; then
        echo "please change branch to diff jar. "
        exit -1
    fi

    # 比较当前分支和master分支的jar的差异
    MASTER_FILE_NAME="/tmp/"${APP_NAME}"_master"
    BRANCH_FILE_NAME="/tmp/"${APP_NAME}"_"`echo ${CURRENT_BRANCH} | sed -e 's/\//\_/g'`
    # 未清洗的临时文件
    MASTER_FILE_TMP=${MASTER_FILE_NAME}"_tmp"
    BRANCH_FILE_TMP=${BRANCH_FILE_NAME}"_tmp"

    # 编译生成工程依赖的jar列表
    git pull
    mvn clean install -Dmaven.test.skip > /dev/null
    mvn dependency:list>${BRANCH_FILE_TMP}

    # 校验分支编译是否成功
    if cat ${BRANCH_FILE_TMP} | grep "BUILD SUCCESS">/dev/null
    then
        echo ${CURRENT_BRANCH} " build success"
        # 清洗jar列表数据
        cat ${BRANCH_FILE_TMP} | grep "\[INFO\]    " | grep compile | sed 's/\[INFO\]    //g' | \
            sed 's/:compile//g' | sort | uniq > ${BRANCH_FILE_NAME}
    else
        echo ${CURRENT_BRANCH} "build failure\n"
        exit -1;
    fi

    # 切换到主干分支
    sleep 2s
    git checkout master
    git pull
    mvn clean install -Dmaven.test.skip > /dev/null
    mvn dependency:list>${MASTER_FILE_TMP}

    # 校验主干编译是否成功
    if cat ${MASTER_FILE_TMP} | grep "BUILD SUCCESS">/dev/null
    then
        echo "master build success\n"
        # 清洗jar列表数据
        cat ${MASTER_FILE_TMP} | grep "\[INFO\]    " | grep compile | sed 's/\[INFO\]    //g' | \
            sed 's/:compile//g' | sort | uniq > ${MASTER_FILE_NAME}

        # 输出分支的差异(不输出公共行)
        # 去掉--suppress-common-lines,可显示所有依赖的jar列表
        diff -y -W 150 --suppress-common-lines ${BRANCH_FILE_NAME} ${MASTER_FILE_NAME} | tee diff.txt
        echo "\n"

    else
        echo "master build failure\n"
        exit -1;
    fi

    # 切换回原来的分支
    sleep 2s
    git checkout ${CURRENT_BRANCH}
else
    echo "not a git repository. "
fi
文章目录
  1. 分支和主干jar差异