zola + github page,用 workflows 部署

    之前的Zola都是本地build之后,再push到github上,这种方式很明显的弊端就是只能在本地编辑,而不能通过github编辑,再pull到本地,缺乏了灵活性。因此将zola用workflows来部署。

    主要就是增加workflows文件

    完整的 .github/workflows/main.yml 文件

    name: Deploy website to Pages
    on:
      # Runs on pushes targeting the default branch
      push:
        branches: [$default-branch]
    
      # Allows you to run this workflow manually from the Actions tab
      workflow_dispatch:
    
    # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
    permissions:
      contents: read
      pages: write
      id-token: write
    
    # Allow one concurrent deployment
    concurrency:
      group: "pages"
      cancel-in-progress: true
    
    # Default to bash
    defaults:
      run:
        shell: bash
    
    jobs:
      # Build job
      build:
        runs-on: ubuntu-latest
        env:
          ZOLA_VERSION: 0.19.2
        steps:
          - name: Install Zola
            run: |
              curl -sL https://github.com/getzola/zola/releases/download/v${ZOLA_VERSION}/zola-v${ZOLA_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar xz -C /usr/local/bin
          - name: Checkout
            uses: actions/checkout@v4
            with:
              submodules: recursive
          - name: Build with Zola
            run: zola build
          - name: Upload artifact
            uses: actions/upload-pages-artifact@v3
            with:
              path: ./public
    
      # Deployment job
      deploy:
        environment:
          name: github-pages
          url: ${{ steps.deployment.outputs.page_url }}
        runs-on: ubuntu-latest
        needs: build
        steps:
          - name: Deploy to GitHub Pages
            id: deployment
            uses: actions/deploy-pages@v4
    
    

    本地运行workflows

    gh workflow run main.yml
    

    gh需要安装和登录验证。Mac环境下:

    brew install  gh
    gh login
    

    可以选择跳转到浏览器进行登录验证,之后即可本地用命令运行workflows了