This code is used to get the latest commit date of a GitHub file in a folder. This is working in my local machine but not working in Github action. In the Github action, it's giving the same date for all the files. Is there any way to fix it?
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
By default, GitHub Actions clones with a shallow clone which only includes the latest commit. If you want to do any sort of history exploration, or need tags or other commits in the repository, then you need to clone with full history like so:
- uses: actions/checkout@v2
with:
fetch-depth: 0
This is documented in the README for actions/checkout
.