【问题标题】:How can I deploy Jekyll site from github repo to my ftp?如何将 Jekyll 站点从 github repo 部署到我的 ftp?
【发布时间】:2021-01-31 08:12:24
【问题描述】:

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

我想将我构建的站点部署到我的托管环境。通过带有 github 操作的 FTP 可以正常工作: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

【问题讨论】:

  • 所以据我了解,您正在尝试使用 GitHub 操作来克隆存储库,构建站点,然后通过 FTP 将完成的 _site 文件夹上传到 Web 服务器?
  • 是的。一切都在 github repo 中。我只想构建它,然后通过 ftp 将结果上传到服务器。

标签: github build jekyll workflow github-actions


【解决方案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/* 

【讨论】:

猜你喜欢
  • 2017-08-19
  • 2016-02-04
  • 2023-03-28
  • 2013-02-19
  • 1970-01-01
  • 2019-05-31
  • 1970-01-01
  • 2015-02-25
  • 2015-09-04
相关资源
最近更新 更多