更新文章 #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Hexo Blog | |
| on: | |
| push: | |
| branches: | |
| - main # 监控的分支:这里填你存放源码的分支名,可能是 main 或 master | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. 修改:把代码拉取到虚拟机 | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # <---【关键点1】改成 0,表示拉取全部历史记录 | |
| # 2. 新增:恢复文件的修改时间 | |
| - name: Restore Timestamps | |
| uses: chetan/git-restore-mtime-action@v2 # <---【关键点2】使用这个插件根据 Git 记录恢复时间 | |
| # 3. 安装 Hexo 和依赖 | |
| - name: Install Dependencies | |
| run: | | |
| npm install -g hexo-cli | |
| npm install | |
| # 4. 生成静态文件 (相当于你在本地敲 hexo g) | |
| - name: Build Hexo | |
| run: hexo generate | |
| # 5. 把生成的文件推送到 gh-pages 分支 | |
| - name: Deploy | |
| uses: peaceiris/actions-gh-pages@v3 # 这是一个在大名鼎鼎的第三方 Action | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} # GitHub 自动生成的令牌,无需手动设置 | |
| publish_dir: ./public # Hexo 生成文件的目录 | |
| publish_branch: gh-pages # 推送到哪个分支,通常是 gh-pages | |
| commit_message: ${{ github.event.head_commit.message }} |