11ty / 11ty-website

Documentation site for the Eleventy static site generator.
https://www.11ty.dev/
MIT License
470 stars 678 forks source link

add fetch-depth note to `git last modified` and `git created` #1656

Open alifeee opened 7 months ago

alifeee commented 7 months ago

Add note

  • This needs an entire git history (which is often not the case in CI environments) or it will return the date of checkout. Fetch the entire history in your CI, for example in GitHub by setting fetch-depth: 0 with GitHub's checkout action.

to git Last Modified and git Created on the Content Dates page

Most CIs checkout a shallow copy of the repository, in which case the git Created and git Last Modified dates will be wrong. This reminds people to disable shallow-cloning if using these two date types.

For example, in GitHub actions you must run

      - name: Checkout
        uses: actions/checkout@v4
+       with:
+         fetch-depth: "0"

for git Created and git Last Modified to work with Eleventy on the runners

Snapstromegon commented 7 months ago

Hi @alifeee thanks for the suggestion. Do you know if it's possible to detect a shallow clone from within the repo so we could display a warning in those cases when the git dates are used?

I like the first sentence of your note, but I'm a little torn on the second because of the way it's written. I will think about it if I find a better fitting version - otherwise I will merge this this weekend.

alifeee commented 7 months ago

it looks like a shallow repository can be detected by (source):

git rev-parse --is-shallow-repository

Would this be better as a warning or an error? If it was a warning then it would not be that visible on a CI system? I'm not the most knowledgeable about what happens to emitted warnings.

Perhaps it would appear under people's workflows?

Anyway if this were the case then we might not need a warning in the docs here. What do you think?