1. A Confusing Problem
| |
The above is part of a project’s workflow, used mainly to check code style, run unit tests, and compile the code. It is triggered when a Pull Request is submitted.
But GitHub Actions kept failing, with the following message:
| |
The key point is that running it locally produced no error at all. At first I suspected GitHub Actions simply wasn’t stable enough and might be flaky. So I pushed repeatedly, but the error persisted.
2. Debugging Online
I brought out the big gun: I logged in to Ngrok, got an Authtoken, and configured it in Secrets. Then I added the following snippet before the failing task:
| |
In the Actions execution log, I found the SSH login link. I ran the command to log in to the Runner remotely and debug:
| |
I entered the password root and could debug online. But it still reported the same error, so I had to find another way.
3. A Clue in the Logs
Based on the error, I guessed it was something like a code cache or sync issue. So I went through the full Actions log and finally spotted a clue.
| |
A SHA value in the log caught my attention, because I had run into a problem before in Jenkins where a Git record could not be found. A SHA represents a version record.
Then, locally I ran git checkout -f 0f878e746fe9ce55a6c4b793c66f501c14c456f5 and, surprisingly, it said that record could not be found. I expanded the collapsed Checking out the ref log:
| |
Merge 2ecc7398161e7a0211c59b52061c9e3800d28551 into 38eaa5cde0580ac4d29537065b687e090db557c6 β so actions/checkout by default merges the Pull Request branch’s code onto the latest code, producing a new record.
The cause was found: the developer forked the mainline code and then developed a new feature. But during that process, the mainline branch had already merged other people’s code. When the already-merged code conflicts with the code in the Pull Request, this phenomenon occurs.
The way to solve it is: before submitting each Pull Request, pull the upstream code again, then rebase to resolve the conflict, and only then submit. There are two kinds of conflict here β one is a file conflict, and the other is a functional conflict.
4. Interpreting the action/checkout Parameters
Next, let us take a look at the other parameters and features of action/checkout.
fetch-depthdefaults to 1, pulling only the current branch. When set to 0, it pulls the records of all branches and tags.
| |
- Check out multiple repositories’ code into a specified directory
| |
- Check out onto the record that submitted the Pull Request; by default it is the record after the merge
| |
