Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github actions的lastGeneratePath.log问题 #128

Open
Raydon10 opened this issue Oct 29, 2022 · 6 comments
Open

github actions的lastGeneratePath.log问题 #128

Raydon10 opened this issue Oct 29, 2022 · 6 comments

Comments

@Raydon10
Copy link

Raydon10 commented Oct 29, 2022

问题在下一条

@Raydon10
Copy link
Author

我在使用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

@Raydon10 Raydon10 changed the title github actions的lastGeneratePath。log github actions的lastGeneratePath.log Oct 29, 2022
@Raydon10 Raydon10 changed the title github actions的lastGeneratePath.log github actions的lastGeneratePath.log问题 Oct 29, 2022
@LetTTGACO
Copy link
Collaborator

看不出来问题在哪,但是部署到githubpages有插件的,可以试一下以下流程
仓库分为博客源码仓库和GithubPages仓库

  1. 配置配置Git用户名邮箱
  2. yuque-hexo sync
  3. 上传代码到博客源码仓库
  4. hexo generate 生成静态文件
  5. 利用peaceiris/actions-gh-pages@v3 上传文章到GitHub Pages
      - 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 }} // 默认

@LetTTGACO
Copy link
Collaborator

至于第三步 推送代码到博客源码仓库。我也使用的插件

      - name: 推送文章到仓库
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

@LetTTGACO
Copy link
Collaborator

参考我的部署配置

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 "[email protected]"

      - 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 }}

@Raydon10
Copy link
Author

我的意思是,每次从博客源码仓库用github actions部署到github pages仓库,actions里每次都必须拉取语雀所有文章,然后再重新生成到github pages吗?因为lastGeneratePath.log无法起作用...

@LetTTGACO
Copy link
Collaborator

我的意思是,每次从博客源码仓库用github actions部署到github pages仓库,actions里每次都必须拉取语雀所有文章,然后再重新生成到github pages吗?因为lastGeneratePath.log无法起作用...

不会啊,我的就是这么配置的,能正常提交的,lastGeneratePath.log写入我倒是没遇到过,可以看下日志。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants