schedule GitHub Action 自动构建vercel
1 min read118 words

schedule GitHub Action 自动构建vercel

Technology
Technology

实现通过 GitHub Actions 自动提交代码并触发 Vercel 定时构建来更新博客,可以按照以下流程操作:

  1. 利用 GitHub 提交触发 Vercel 构建:Vercel 与 GitHub 仓库关联后,默认会在检测到代码提交时自动触发构建部署,这一步无需额外配置,只需确保 Vercel 项目已正确关联到 GitHub 仓库。
  2. 通过 GitHub Actions 实现自动提交代码:配置定时任务,让 GitHub Actions 在指定时间自动提交代码变更(如更新博客内容、生成静态文件等),进而触发 Vercel 的自动构建流程,实现博客的定时自动更新。
name: Update Daily # 工作流的名称 on: schedule: - cron: '0 0 * * *' # 每天UTC时间0点运行(北京时间早上8点) workflow_dispatch: # 允许手动触发此工作流 jobs: update-readme: runs-on: ubuntu-latest # 使用最新的Ubuntu系统作为运行环境 steps: # 步骤1:检出仓库代码 - name: Checkout repository uses: actions/checkout@v4 # 步骤2:执行脚本更新deploy-timestamp(示例中为Shell命令,实际可替换为Python、Node.js等) - name: Update deploy-timestamp content run: | echo "最后自动部署时间: $(date)" > deploy-timestamp.txt # 步骤3:配置Git用户信息 - name: Setup Git config run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" # 步骤4:提交更改 - name: Commit changes run: | git add deploy-timestamp.txt git diff --quiet && git diff --staged --quiet || git commit -m "Auto-update via GitHub Actions on $(date)" git push permissions: contents: write