I recently was figuring out the best way to automatically deploy my website using GitHub Actions and found that it can be done using FTP to my website host.
The best way I found was to use the following YAML file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
name: Build & Upload Site
# Run on pushes to the main branch
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '3.1.3'
# 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: $ # Pass in required secrets.
ftp_username: $ #someawesomeftpusername
ftp_password: $ # somesuperstrongpassword
ftp_folder: $ # /public_html
run: |
ncftpput -R -v -u "$ftp_username" -p "$ftp_password" $ftp_location $ftp_folder _site/*
If you would like to use the above YAML you will need to create 4 Secrets in Github:
FTP_LOCATION- The Server address akaexample.comFTP_USERNAME- Your FTP UsernameFTP_PASSWORD- Your FTP PasswordFTP_FOLDER- The folder where the Files must go to in the destination. If you don’t want to specify a folder because the user goes directly to the correct folder, just use/
One side note is the you need to specify the folder that contains the generated production data. In the last line of the file you need to change _site/* to what ever the folder is that contains the generated site files from Jekyll.