akaihola / darker

Apply black reformatting to Python files only in regions changed since a given commit. For a practical usage example, see the blog post at https://dev.to/akaihola/improving-python-code-incrementally-3f7a
https://pypi.org/project/darker/
Other
638 stars 55 forks source link

`commit-range` action intermittent failure #601

Open akaihola opened 3 months ago

akaihola commented 3 months ago

Every now and then the commit-range action crashes with Git's fatal: bad object <hash>. The github.event.commits structure contains two commits, but the local clone actually only has one.

This happened e.g. in build #41 for #591:

github.event.commits in env.commit_list ```json env: commit_list: [ { "author": { "email": "13725+akaihola@users.noreply.github.com", "name": "Antti Kaihola", "username": "akaihola" }, "committer": { "email": "13725+akaihola@users.noreply.github.com", "name": "Antti Kaihola", "username": "akaihola" }, "distinct": true, "id": "06dfd005c3050f9a13a3b20f32cd3c0d70765da5", "message": "GitHub action enhancements\n\n- change to working directory\n- install `pip-requirements-parser` in a separate step\n- include Darker exit code in outputs\n- include Darker standard output in outputs\n- run `commit-range` action locally", "timestamp": "2024-07-30T01:08:04+03:00", "tree_id": "2419b5a681fc2200ec4f0423635b4b4dee008a7a", "url": "https://github.com/akaihola/darker/commit/06dfd005c3050f9a13a3b20f32cd3c0d70765da5" }, { "author": { "email": "13725+akaihola@users.noreply.github.com", "name": "Antti Kaihola", "username": "akaihola" }, "committer": { "email": "13725+akaihola@users.noreply.github.com", "name": "Antti Kaihola", "username": "akaihola" }, "distinct": true, "id": "0d5b83a3c875db922d82bfa5022b4fa62f0bda09", "message": "Workflow to test `working-directory` action input", "timestamp": "2024-07-30T01:08:04+03:00", "tree_id": "f2da2a4337a344e41291b3e5805f90f7e92d3aba", "url": "https://github.com/akaihola/darker/commit/0d5b83a3c875db922d82bfa5022b4fa62f0bda09" }, { "author": { "email": "13725+akaihola@users.noreply.github.com", "name": "Antti Kaihola", "username": "akaihola" }, "committer": { "email": "13725+akaihola@users.noreply.github.com", "name": "Antti Kaihola", "username": "akaihola" }, "distinct": true, "id": "7003e2a03e139366ba75993acf75912bef2d7697", "message": "Adjust `--stdin-filename` tests to new exit codes", "timestamp": "2024-07-30T01:08:04+03:00", "tree_id": "66c7f454336031b305eea1c57a444bc0ccdfd213", "url": "https://github.com/akaihola/darker/commit/7003e2a03e139366ba75993acf75912bef2d7697" } ] ```

Log for step Fail if no exit code 2 even though test.py was not found in the test-working-directory job:

fatal: bad object 06dfd005c3050f9a13a3b20f32cd3c0d70765da5
##[error]Process completed with exit code 128.
##[group]Run echo "::error::Darker should have failed with exit code 2"
echo "::error::Darker should have failed with exit code 2"
echo "::error::It exited with "
exit 1
shell: /usr/bin/bash -e {0}
##[endgroup]
##[error]Darker should have failed with exit code 2
##[error]It exited with 
##[error]Process completed with exit code 1.

For this particular run I didn't have debug logging active for commit-range, but very probably git log would have only displayed the last commit at the time (7003e2a0). The commit hash in bad object 06dfd005 referred to the third-last commit at the time.