修复hexo集成部署的修改时间bug

  • ~1.66K 字
  • 次阅读
  • 条评论
  1. 1. BUG描述
  2. 2. BUG分析
  3. 3. BUG修复

其实很简单

BUG描述

每次集成部署后,所有文章的修改时间都会变成此次部署时间。

BUG分析

由于源码仓库内的时间是对的,所以问题的原因很可能是这个:
集成部署在拉取文件时导致文件修改日期。

BUG修复

Actions.yml文件加上这个(来源):

1
2
3
4
5
6
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

如果用了actions/checkout@v2,还要将参数fetch-depth设为0,
比如我的就变成了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: Hexo Deploy

on: [push, repository_dispatch]

jobs:
build:
runs-on: ubuntu-18.04

steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: '0'
ref: master

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "16"

- 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

- name: Setup Hexo & Deploy
env:
ACTION_DEPLOY_KEY: ${{ secrets.HEXO_DEPLOY_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.email "dghdhwang@gmail.com"
git config --global user.name "sasikya"
npm install hexo-cli -g
npm install
hexo clean
hexo deploy
分享这一刻
让朋友们也来瞅瞅!