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



此代码用于获取文件夹中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的自述文件中有记录。

最新更新