为什么最新提交日期在 Github 工作流程中不起作用?

Why latest commit date is not working in Github workflow?

此代码用于获取文件夹中 GitHub 文件的最新提交日期。这在我的本地机器上工作,但在 Github 操作中不起作用。在 Github 操作中,它为所有文件提供了相同的日期。有什么办法可以解决吗?

import git
from datetime import datetime
from git.objects.commit import Commit

def get_date(epoch_time):
    return datetime.fromtimestamp(epoch_time)

submissionDate_fileName = {}

dir_path = os.path.dirname(os.path.realpath(__file__))
repo = git.Repo(dir_path)
tree = repo.tree()

for blob in tree.trees[1]:
    commit = next(repo.iter_commits(paths=blob.path, max_count=1))
    date = str(get_date(commit.committed_date))[:10]
    submissionDate_fileName[blob.name] = date

默认情况下,GitHub Actions 使用仅包含最新提交的浅克隆进行克隆。如果您想进行任何类型的历史探索,或者需要标签或存储库中的其他提交,那么您需要像这样克隆完整的历史:

- uses: actions/checkout@v2
  with:
    fetch-depth: 0

这在 actions/checkout 的自述文件中有记录。