MrSeaWave / blogs

✍🏻 个人博客,记录、分享一写随笔和技术知识
https://hailangya.com
3 stars 0 forks source link

修复 CI 构建博客造成的更新时间错误 - Sea's Blog #8

Open MrSeaWave opened 3 years ago

MrSeaWave commented 3 years ago

https://mrseawave.github.io/blogs/2021/01/07/ci-hexo-update-time/#more

当使用 Travis CI or Github Actions 自动化部署时,发现部署成功后,所有文章的更新时间都变成了此次提交修改的时间,但有些文章在上一次提交后是没有发生过任何修改的。 这是因为 git 在推送更新时,并不记录保存文件的访问时间、修改时间等元信息,(原因在这里)所以每次使用 git 把项目 clone 下来时,文件的时间都是克隆时的时间。又因为如果没有在 front-matte

edgexyz commented 2 years ago

我使用了 gh actions 的 git ls-filesfind 指令,但是均报错 fatal: ambiguous argument '': unknown revision or path not in the working tree. ...

MrSeaWave commented 2 years ago

@edgexyz 文章中workflow部分反转义可能有误,现已更新,去掉run语句之后两头的""

jobs:
  <jobs_id>:
    steps:
      - name: Restore file modification time
        run: |
-          "git ls-files -z | while read -d '' path; do touch -d \"$(git log -1 --format=\"@%ct\" \"$path\")\" \"$path\"; done"
+          git ls-files -z | while read -d '' path; do touch -d "$(git log -1 --format="@%ct" "$path")" "$path"; done
+          # 或者使用下面的方式
+          find source -name '*.md' | while read file; do touch -d "$(git log -1 --format="@%ct" "$file")" "$file"; done
flc1125 commented 1 year ago

🤓🤓🤓 Nice,来自社会主义接班人的点赞。