github.com/XiaoMi/Gaea@v1.2.5/gen_version.sh (about)

     1  #!/bin/bash
     2  
     3  ROOT="$(pwd)"
     4  
     5  if BUILD_GIT_REVISION=$(git rev-parse HEAD 2> /dev/null); then if ! git diff-index --quiet HEAD; then BUILD_GIT_REVISION=${BUILD_GIT_REVISION}"-dirty"
     6      fi
     7  else
     8      BUILD_GIT_REVISION=unknown
     9  fi
    10  
    11  # Check for local changes
    12  if git diff-index --quiet HEAD --; then
    13    tree_status="Clean"
    14  else
    15    tree_status="Modified"
    16  fi
    17  
    18  # Check for git branch and git dirty
    19  BRANCH=$(git rev-parse --abbrev-ref HEAD)
    20  GIT_DIRTY=$(git diff --no-ext-diff 2> /dev/null | wc -l)
    21  
    22  # XXX This needs to be updated to accomodate tags added after building, rather than prior to builds
    23  RELEASE_TAG=$(git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --exact-match --tags 2> /dev/null || echo "")
    24  
    25  # security wanted VERSION='unknown'
    26  VERSION="${BUILD_GIT_REVISION}"
    27  if [[ -n "${RELEASE_TAG}" ]]; then
    28    VERSION="${RELEASE_TAG}"
    29  elif [[ -n ${MY_VERSION} ]]; then
    30    VERSION="${MY_VERSION}"
    31  fi
    32  
    33  # used by core/version
    34  echo buildVersion       "${VERSION}"
    35  echo buildGitRevision   "${BUILD_GIT_REVISION}"
    36  echo buildUser          "$(whoami)"
    37  echo buildHost          "$(hostname -f)"
    38  echo buildStatus        "${tree_status}"
    39  echo buildTime          "$(date +%Y-%m-%d--%T)"
    40  echo buildBranch        "${BRANCH}"
    41  echo buildGitDirty      "${GIT_DIRTY}"