【问题标题】:Why latest commit date is not working in Github workflow?为什么最新的提交日期在 Github 工作流程中不起作用?
【发布时间】:2022-01-10 21:22:57
【问题描述】:

此代码用于获取文件夹中 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

【问题讨论】:

    标签: python github github-actions gitpython


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      • 2021-08-25
      • 2023-02-23
      • 2023-03-19
      相关资源
      最近更新 更多