Troubleshooting Process
Where is the modification time information of the blog obtained when hexo compiles the blog?
After consulting the hexo document, the modification time information is based on the file modification time.
Why the file modification time obtained by Github Action is different from the local one?
The modification time of files will not be synchronized to the deploy machine when Action checkouts the branch from remote repository. So the modification time is determined by the file system. All files are just created for deploy machine, and their atime(access time), mtime(modify time) and ctime(change time) are all at this time.
How to solve the problem mentioned above?
As we know, the modification record of files will be carried in the git repository, so the commit record of the git will also carry the modification time of files.
We can find the last modified commit time of the file in git by the following git command.
1 | mtime=$(git log -1 --format="@%ct" "$file") |
We can change the mtime of file by the following command.
1 | touch -d "$mtime" "$file" |
So, we can restore modification time of files by the following command.
1 | git ls-files | while read file; do touch -d $(git log -1 --format="@%ct" "$file") "$file"; done |
Testing on Action still cannot fix this problem, although there is no problem with local testing.
I spent a lot of time on this problem, which also exposed my lack of clear ideas to solve problem.
By chance, I realized whether the checkout operation did not fetch all the commits. By reading the checkout instructions, I noticed a parameter fetch-depth
, the introduction about it is as follows.
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# Default: 1
Modify this parameter to 0, I successfully solves my problem.
End to spread flowers
Keep your thinking clear and no afraid to learn new knowledge!
Stay hungry. Stay foolish.
Appendix
The complete action yaml file is as follows.
1 | name: Node.js CI |