如何从github存储库将Jekyll网站部署到ftp?

时间:2020-10-16 19:37:28

标签: github build jekyll workflow github-actions

我有一个自定义的Jekyll网站,可以在本地正常运行。

我想将构建的站点部署到托管环境。通过FTP和github操作可以很好地解决此问题: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

我尝试使用_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

1 个答案:

答案 0 :(得分:1)

这是我目前在The World According to Mike Blog上找到的内容。

这使用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/*