Command '['git', 'rev-parse', 'HEAD^1']' returned non-zero exit status 128

Viewed 800

I am a beginner in embedded programming and trying to set up a workflow where the code sizes are automatically put in database and compared with the previous revision. Beginner on Github as well obviously. I am trying to have a python script called by a Github Action.

So here is the action:

- name: Stamp revision
        working-directory: cobrax
        continue-on-error: True
        run: |
          pip install psycopg2-binary
          pip install click
          pip install prettytable
          python3 codesizes.py stamp build/zephyr/zephyr.elf

And here is the problematic line in the python code, where I am trying to fetch the parent revision:

    revision = subprocess.check_output(
        ["git", "rev-parse", "{}".format(revision)], encoding="UTF-8"
    ).strip()
    parent_revision = subprocess.check_output(
        ["git", "rev-parse", "{}^1".format(revision)], encoding="UTF-8"
    ).strip()

Now, for revision that works perfectly. But, just because of the '^1' for parent revision, I keep getting the following error message from the github action:

subprocess.CalledProcessError: Command '...' returned non-zero exit status 128

So, I tried a few things, notably:

["git", "rev-parse", "{}^".format(revision)], encoding="UTF-8"
    ).strip()
["git", "rev-list", "--parents", "-n", "1", revision, "|", "cut", "-d'", "'", "-f2-"], encoding="UTF-8"

But, the error comes from elsewhere. As I am a beginner, I wish someone would explain it to me because that obviously comes the virtual environment thing for github actions because on my ubuntu VM in the repo I don't have that problem.

Thank you for your help.

1 Answers

After some research, it turns out that the actions/checkout@v2 that I use defaults to a shallow --depth=1 clone. This allows me to use HEAD but NOT HEAD^

With my workflow configured as such:

      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 2

Everything works !

Related