git rev-list with a gitrevision range argument on circleci build 不工作

git rev-list with a gitrevision range argument on circleci build not working

对于this repro repo 在 CircleCI 管道构建作业中 git rev-list --count develop..$CIRCLE_SHA1 returns0.

同上 git rev-list --count develop..HEAD.

git rev-list develop..HEAD什么都不做

build output

上面的所有git命令在本地运行时产生不同的结果。 git rev-list --count HEAD returns 本地和 CircleCI 运行s 的相同非零值。 每当提供 gitrevision range 参数时,CircleCI 上似乎 git rev-list 失败 难道我做错了什么?如何让 git rev-list 使用 git 修订范围?

config.yml

version: 2.1

executors:
    base:
        docker:
            - image: cimg/base:2020.01

jobs:
    build:
        executor: base
        steps:
        - checkout
        - run:
            name: Test git in bash script
            command: chmod +x .circleci/circle_test.sh && .circleci/circle_test.sh
        - run:
            name: Test git in circleci command
            environment:
                PACKAGE_PATH: "./packages"       
            command: |
                echo -e $(git rev-list -1 develop..$CIRCLE_SHA1 -- ${PACKAGE_PATH#./} | cat)
                echo -e $(git rev-list -1 develop..$CIRCLE_SHA1 | cat)
                echo -e $(git rev-list develop..$CIRCLE_SHA1 | cat)
                git rev-list --count develop..$CIRCLE_SHA1
                git rev-list --count HEAD

workflows:
    version: 2
    ci:
        jobs:
        - build

.circleci/circle_test.sh

PACKAGE_PATH="./packages" 

LATEST_PACKAGE_COMMIT_SINCE_DEVELOP=$(git rev-list -1 develop..$CIRCLE_SHA1 -- ${PACKAGE_PATH#./})

LATEST_COMMIT_SINCE_DEVELOP=$(git rev-list -1 develop..$CIRCLE_SHA1)

COMMITS_SINCE_DEVELOP=$(git rev-list develop..$CIRCLE_SHA1)

COMMITS_COUNT_SINCE_DEVELOP=$(git rev-list --count develop..$CIRCLE_SHA1)

COMMITS_COUNT=$(git rev-list --count HEAD)

echo -e "\e[36m  first changed commit in package since develop $LATEST_PACKAGE_COMMIT_SINCE_DEVELOP \e[0m"

echo -e "\e[36m  first changed commit since develop $LATEST_COMMIT_SINCE_DEVELOP \e[0m"

echo -e "\e[36m  commits since develop $COMMITS_SINCE_DEVELOP \e[0m"

echo -e "\e[36m  commits count since develop $COMMITS_COUNT_SINCE_DEVELOP \e[0m"

echo -e "\e[36m  commits count $COMMITS_COUNT \e[0m"

echo -e "\e[36m  this commit $CIRCLE_SHA1 \e[0m"

在 CircleCI 上使用完整的提交 sha1 而不是分支名称 例如,开发分支的 sha1 使用 bash DEVELOP_SHA1=$(git rev-parse origin/develop)

那么LATEST_COMMIT_SINCE_DEVELOP=$(git rev-list -1 develop..$CIRCLE_SHA1)应该写成LATEST_COMMIT_SINCE_DEVELOP=$(git rev-list -1 $DEVELOP_SHA1..$CIRCLE_SHA1)