如何将 Jekyll 站点从 github 存储库部署到我的 ftp?

HuM*_*MaN 2 workflow build github jekyll github-actions

我有一个自定义 Jekyll 网站,它在本地运行良好。

我想将我构建的站点部署到我的托管环境中。通过 FTP 和 github actions 可以正常工作:https: //github.com/SamKirkland/FTP-Deploy-Action

这是 FTP 工作流程:

on: push
name: Publish Website
jobs:
  FTP-Deploy-Action:
    name: FTP-Deploy-Action
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2.1.0
      with:
        fetch-depth: 2
    - name: FTP-Deploy-Action
      uses: SamKirkland/FTP-Deploy-Action@3.1.1
      with:
        ftp-server: ${{ secrets.FTP_HOST }}
        ftp-username: ${{ secrets.FTP_USER }}
        ftp-password: ${{ secrets.FTP_PASSWORD }}
        local-dir: _site
        git-ftp-args: --changed-only
Run Code Online (Sandbox Code Playgroud)

我尝试使用该_site文件夹,并且当不忽略 _site 时,每次提交都会运行操作。

所以最好的是,如果我不提交该_site页面,那么 GitHub 服务器就可以了。我发现了这个动作: https: //github.com/marketplace/actions/jekyll-actions

我的测试流程:

on: push
name: Testing the GitHub Pages building
    
jobs:
  jekyll:
    runs-on: ubuntu-16.04
    steps:
    - uses: actions/checkout@v2

    # Use GitHub Actions' cache to shorten build times and decrease load on servers
    - uses: actions/cache@v1
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gems-

    # Standard usage
    - uses:  humarci/jekyll-action@1.0.0
    
    # FTP maybe from here
Run Code Online (Sandbox Code Playgroud)

小智 5

这是我目前使用的,是我从《迈克的世界》博客中找到的。

这使用 ncftp,它允许您轻松地通过 ftp 上传文件。

name: Build & Upload Site
# Run on pushes to the master branch
on: 
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-ruby@v1
      with:
        ruby-version: '2.7'
    # Install the gems in the gemfile & install ncftp
    - name: Setup Environment.
      run: |
        bundle install
        sudo apt-get install -y ncftp
    
    # Build the site
    - name: Build Site with Jekyll.
      run: JEKYLL_ENV=production bundle exec jekyll build
    
    # Looks kind of complicated but just uploads the content of _site folder to the ftp server. It does not upload the _site folder itself.
    - name: Upload site to FTP.
      env: 
        ftp_location: ${{ secrets.FTP_LOCATION }} # Pass in required secrets.
        ftp_username: ${{ secrets.FTP_USERNAME }}
        ftp_password: ${{ secrets.FTP_PASSWORD }} 
      run: |
        ncftpput -R -v -u "$ftp_username" -p "$ftp_password" $ftp_location / _site/* 
Run Code Online (Sandbox Code Playgroud)

  • 很有帮助。另外,我必须弄清楚如何使其适用于 ncftpput 不支持的 SFTP。我最终使用了 LFTP 并在 GH Actions 脚本中创建了一个known_hosts 文件。在这里查看我的代码:https://github.com/DavidSlr/portfolio/blob/main/.github/workflows/jekyll-build-deploy.yml (2认同)