4

I've noticed that GitHub action does not fail as expected. The same shell script is used in bitbucket pipeline and it fails there as expected. The script is https://github.com/pavelfomin/gphoto-manager/blob/master/scripts/check-release.sh. It returns 1 if the version in the pom.xml exists as a tag already.

I've tested the script locally and it does return 1 when tag already exists.

GitHub action: https://github.com/pavelfomin/gphoto-manager/actions/runs/570220185 https://github.com/pavelfomin/gphoto-manager/blob/master/.github/workflows/maven.yml

BitBucket pipeline: https://bitbucket.org/pvlf/gphoto-manager/addon/pipelines/home#!/results/2 https://github.com/pavelfomin/gphoto-manager/blob/master/bitbucket-pipelines.yml

What am I missing?

pavel
  • 2,964
  • 2
  • 14
  • 14
  • Have you tried ```[ $? == 1 ] && exit 1``` ? Instead of || – Antonin GAVREL Feb 16 '21 at 03:54
  • The script returns 0 if tag does not exist (`git tag -l | grep $version` returns 1) so `[ $? == 1 ]` returns 0 in that case. If tag does exist (`git tag -l | grep $version` returns 0) then 1 is returned by the script hence `|| exit 1`. The script does work as expected when I run it locally and in bitbucket. It appears that github action ignores the status. Or somehow the result is different when the script is executed by github action. – pavel Feb 16 '21 at 15:18
  • The root cause was the lack of fetched tags in the repo so the `git tag` did not list any tags. I've posted the details in the answer. – pavel Feb 17 '21 at 17:26

1 Answers1

1

The issue is caused by actions/checkout@v2 fetching the git repository with --depth=1 and without fetching the tags by default. The solution is to specify fetch-depth: "0"

    - uses: actions/checkout@v2
      with:
        # 0 indicates all history for all branches and tags
        fetch-depth: "0"
pavel
  • 2,964
  • 2
  • 14
  • 14