Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'git log' dates incorrect in a GitHub action

I'm using this script to generate a file with commit dates

cat .github/workflows/header.md > "COVID 19/fechas.md"
git ls-tree -r --name-only HEAD COVID\ 19/*.csv | while read filename; do
    date=$(git log -1 --format="%aD" -- "$filename")
    echo "| $date  | $filename |" >>  "COVID 19/fechas.md"
done
git config --global user.email "[email protected]"
git config --global user.name "FechaActionBot"
git add "COVID 19/fechas.md"
git commit -m "Fichero de fechas generado"

In this GitHub Action, which checks out the code and runs above as a script.

No matter what I use as format (commiter or author date), I get the same result, which shows the same date (the current one) for all files.

like image 748
jjmerelo Avatar asked Jan 23 '26 15:01

jjmerelo


1 Answers

By default, the checkout action does a shallow clone. You need to configure it for a deep clone, as indicated, if you want to access the real commit date (and not the date of a ghost commit created by the shallow clone), this way:

name: genera fechas
on:
  push:
    paths:
    - '**.csv'

jobs:
  genera_fechas:
    runs-on: ubuntu-latest
    name: Genera CSV
    steps:
      - name: checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: '0'
      - name: Fechas
        run: .github/workflows/dates.sh
      - name: Check in
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

like image 74
jjmerelo Avatar answered Jan 26 '26 08:01

jjmerelo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!