部署问题修复说明
问题描述
GitHub Actions 构建时遇到以下错误:
Run `bundle install` elsewhere and add the updated Gemfile to version control.
If this is a development machine, remove the Gemfile.lock freeze by running
`bundle config set frozen false`.
Error: The process '/opt/hostedtoolcache/Ruby/3.3.9/x64/bin/bundle' failed with exit code 16
解决方案
1. 删除过时的 Gemfile.lock
- 删除了本地的
Gemfile.lock
文件 - 让 GitHub Actions 重新生成与 Ruby 3.0 兼容的版本
2. 更新 GitHub Actions 工作流
- 使用
ruby/setup-ruby@v1
替代已弃用的actions/setup-ruby
- 设置 Ruby 版本为 3.0(GitHub Pages 兼容版本)
- 启用 Bundler 缓存以提高构建速度
- 添加明确的依赖安装步骤
3. 修复后的工作流特点
- 兼容性:使用 GitHub Pages 支持的 Ruby 3.0
- 性能:启用 Bundler 缓存,加快构建速度
- 稳定性:使用活跃维护的 Actions
- 清晰性:明确的构建步骤和错误处理
预期结果
- GitHub Actions 构建应该能够成功完成
- 自动生成新的
Gemfile.lock
文件 - 网站能够正常部署到 GitHub Pages
注意事项
- 首次构建可能需要较长时间来生成新的
Gemfile.lock
- 后续构建将使用缓存,速度会更快
- 如果仍有问题,请检查 Actions 日志中的详细错误信息