Open Raydon10 opened 1 year ago
我在使用github actions将github private仓库的代码自动部署到github pages上,但这过程中发现个问题,无法写入更新时间到private仓库的lastGeneratePath.log里,请问是否有好的办法,github actions代码如下:
name: Blog CI/CD
on: [push, repository_dispatch]
jobs:
blog-cicd:
name: Hexo blog build & deploy
runs-on: ubuntu-latest
env:
TZ: Asia/Shanghai
steps:
- name: Checkout codes
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Cache node modules
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: |
npm install hexo-cli -g
npm install yuque-hexo -g
npm install
npm run yuque
- name: Generate files
run: hexo generate
- name: Deploy blog
run: |
git clone "https://${{ secrets.GH_REF }}" deploy_git
mv ./deploy_git/.git ./public
cd ./public
git config user.name "xxx"
git config user.email "xxx"
git add .
git commit -m "GitHub Actions Auto Builder at $(date +'%Y-%m-%d %H:%M:%S')"
git push --force --quiet "https://${{ secrets.GH_TOKEN }}@${{ secrets.GH_REF }}" main:main
看不出来问题在哪,但是部署到githubpages有插件的,可以试一下以下流程 仓库分为博客源码仓库和GithubPages仓库
- name: 上传文章到GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.SSH_PRIVATE_KEY }}
external_repository: LetTTGACO/LetTTGACO.github.io // 你的GH地址
publish_branch: master
publish_dir: ./public
commit_message: ${{ github.event.head_commit.message }} // 默认
至于第三步 推送代码到博客源码仓库。我也使用的插件
- name: 推送文章到仓库
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
参考我的部署配置
name: Deplo
on:
# 允许手动push触发
push:
branches:
- master
# 允许外部仓库事件触发
repository_dispatch:
types:
- start
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检查分支
uses: actions/checkout@master
- name: 安装node环境
uses: actions/setup-node@master
with:
node-version: "12.x"
- name: 缓存依赖
uses: actions/cache@v1
id: cache
with:
path: node_modules
key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}
- name: 安装依赖
if: steps.cache.outputs.cache-hit != 'true'
run: |
export TZ='Asia/Shanghai'
npm install
- name: 拉取语雀的文章
env:
YUQUE_TOKEN: ${{ secrets.YUQUE_TOKEN }}
run: |
npm run yuque:sync // yuque-hexo sync
- name: 配置Git用户名邮箱
run: |
git config --global user.name "1874"
git config --global user.email "xxx@qq.com"
- name: 提交yuque拉取的文章到GitHub源码仓库
run: |
echo `date +"%Y-%m-%d %H:%M:%S"` begin > time.txt
git add .
git commit -m "Refresh yuque json" -a
- name: 推送文章到仓库
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: 生成静态文件
run: |
npm run hexo:clean // hexo clean
npm run hexo:build // hexo generate
- name: 上传文章到GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.SSH_PRIVATE_KEY }}
external_repository: LetTTGACO/LetTTGACO.github.io
publish_branch: master
publish_dir: ./public
commit_message: ${{ github.event.head_commit.message }}
我的意思是,每次从博客源码仓库用github actions部署到github pages仓库,actions里每次都必须拉取语雀所有文章,然后再重新生成到github pages吗?因为lastGeneratePath.log无法起作用...
我的意思是,每次从博客源码仓库用github actions部署到github pages仓库,actions里每次都必须拉取语雀所有文章,然后再重新生成到github pages吗?因为lastGeneratePath.log无法起作用...
不会啊,我的就是这么配置的,能正常提交的,lastGeneratePath.log写入我倒是没遇到过,可以看下日志。
问题在下一条