This GitHub Action can publish a website built by Retype in a previous action-build step to a FTP server using the git-ftp tool.
The Retype's git-ftp action will commit and push back a Retype website to its GitHub repository, then sync it with the specified FTP host. The website needs to be built during a previous step by using the retypeapp/action-build action.
FTP credentials are required via the ftp-host, ftp-pass, ftp-root and ftp-user arguments in order to publish files to the FTP endpoint. Please use at least ftp-pass as a secret in your repository.
Like the action-github-pages, this one includes options to push to a branch, a directory within a branch, and create a pull request, which can then be merged after human review.
Keeping a branch to hold change history allows for much faster FTP synchronization, as it uses git history to decide which files should be sent or removed on the remote server.
The following functionality is configurable by this action:
- Target a
branch, or - Target a
directorywithin a branch - Configure whether the branch should be updated or copied (
update-branch) - Configure GitHub API access token to allow the action to make a Pull Request when needed (
github-token)
The following arguments are required for this action to run:
- FTP hostname/IP (
ftp-host) - FTP directory (root in the remote host,
ftp-root) - FTP username (
ftp-user) - FTP password (
ftp-passmake sure this is passed as a secret!)
The git-ftp tool uses a control file that is stored in the FTP server as .git-ftp.log additionally to the actual documentation website. See more in the git-ftp documentation page.
This action requires the output of the retypeapp/action-build in a previous step of the workflow.
The following retype.yaml file demonstrates a typical scenario where a workflow should publish Retype website when changes are pushed to the repo. The fresh Retype powered website is then pushed to a retype branch which will hold change history to optimally update the remote FTP endpoint as commits are pushed on.
name: Publish Retype powered website to FTP
on:
workflow_dispatch:
push:
branches:
- main
jobs:
publish:
name: Publish to the FTP host
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: retypeapp/action-build@latest
- uses: retypeapp/action-git-ftp@latest
with:
ftp-host: ${{ secrets.FTP_SERVER_ADDRESS }}
ftp-root: public_html
ftp-user: ${{ secrets.FTP_USERNAME }}
ftp-pass: ${{ secrets.FTP_PASSWORD }}
branch: retype
update-branch: trueIt is recommended to pass all input prefixed with ftp- as GitHub Encrypted Secrets to preserve sensitive information. The output of git-ftp always prints the used credentials and addresses; if they are used as secrets, GitHub would replace them with ***.
Specifies the target branch where the Retype output will be merged to. The git-ftp tool uses a branch to determine file changes based in git history, uploading only changes since last sync.
- Default:
retype - Accepts: A string or the
HEADkeyword. Examples:gh-pages,main,website,HEAD
-
If the branch does not exist: The action will create a new, orphan branch; then copy over the files, commit, and push.
-
If the branch exists:
- And
update-branchinput is nottrue: The action will fork from that branch into a new uniquely-named branch. The action will then wipe clean the entire branch (or a subdirectory within that branch, seedirectorybelow), then copy over the Retype output files, commit and push. This branch can then be merged or be used to make a pull request to the target branch. This action can create the pull request, seegithub-tokeninput below. - The
update-branchinput istrue: The action will wipe clean the branch (or directory), then copy over the Retype output, commit, and then push to the target branch.
- And
-
The argument is
HEADkeyword:update-branchis impliedtrueand Retype output files will be committed to the current branch. In this scenario, the action will ONLY run if adirectoryhas been configured, as it would otherwise result in the replacement of all branch contents with the Retype output. -
Detached HEAD: If the argument is
HEADand commit SHA points to no branch or tag (detached head), then no commit will be possible and the action will fail. -
When wiping a branch or directory, if there is a
CNAMEfile in its root, the existingCNAMEfile will be preserved. -
If the
cnameproperty is configured within your projectsretype.jsonfile, theCNAMEfile from the Retype build output will override it. -
If the
HEADkeyword is used and.,/, or any path coinciding with the repository root is specified todirectoryinput, then the whole branch data will be replaced with the generated documentation. Likewise, if the path passed as input conflicts with any existing path within the repository, it will be wiped clean by the action, replaced by the Retype output.
Specifies the root where to place the Retype output files. The path is relative to the repository. This allows, for instance, to have the output in the same branch the input (source) files are in.
- Default: null (root of the repository)
- Accepts: A string. Example:
docs
-
Using
/or.is equivalent to not specifying an input, as it will be changing to the.//and./.directories respectively. Use of upper-level directories (../) is accepted but may result in files being copied outside the repository, in which case the action might fail due to being outside the repository boundaries. -
If the
directorypoints to a subirectory within Retype's input, a recursive replication of the output directory may occur. Adding it as a Retype exclude path should be enough to avoid this.
The hostname or IP address of the remote FTP server to sync files to. May specify the port with the format <host_or_ip>:<port>.
- Default: This argument is required and there's no default.
- Accepts: a string in the format
<hostname>or<hostname>:<port>representing the remote FTP host.
The password used to authenticate with in the remote FTP host.
- Default: This argument is required and there's no default.
- Accepts: a string representing a password stored as a GitHub Secret.
- Passwords beginning with
--are not supported bygit-ftp. - Use this as a GitHub Encrypted Secret; failing to do so will expose the password in the workflow output log as git-ftp always prints it out.
The root directory in the remote host where to place and sync the files.
- Default: This argument is required and there's no default.
- Accepts: a string representing a relative path to the FTP starting location.
- use
/or.if the files should be placed in the starting FTP directory. - the directory must exist in the remote host; this may help avoid mistakes.
- common names for this are
public_htmlfor linux hosts andwwwrootfor windows hosts.
The username used to authenticate with in the remote FTP host.
- Default: This argument is required and there's no default.
- Accepts: a string representing an username.
Indicates whether the action should update the target branch instead of creating a unique named branch.
- Default: null
- Accepts:
trueorfalse
-
When this option is configured, no pull request will be attempted even if
github-tokenis specified. -
When
branch: HEADinput is specified, this setting is assumedtrueas there will not be a reference to fork off (or pull request to) asHEADis not a valid branch name. -
When this option is unset or
false(default), although it may not push the changes to the target specified branch, it will sync with the remote FTP host. This means that, in case the branch or pull request is not accepted/merged, the next run will need a full sync, or fail. This can be fixed by merging the branch, or resetting the FTP directory.
Specifies a GitHub Access Token that enables the action to make a pull request whenever needs to push a new branch. See Using the GITHUB_TOKEN in a workflow and Creating a personal access token for more details.
- Default: null
- Accepts: A string representing a valid GitHub Access Token either for User, Repository, or Action.
- The action will never use the access token if
- the branch does not exist,
update-branch: true, orbranch: HEADis specified.
The following retype.yaml workflow file will serve as our starting template for most of the samples below.
name: GitHub Action for Retype
on:
workflow_dispatch:
push:
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: retypeapp/action-build@latest
- uses: retypeapp/action-git-ftp@latest
with:
ftp-host: ${{ secrets.FTP_SERVER_ADDRESS }}
ftp-root: public_html
ftp-user: ${{ secrets.FTP_USERNAME }}
ftp-pass: ${{ secrets.FTP_PASSWORD }}
branch: retype
update-branch: true- uses: retypeapp/action-git-ftp@latest
with:
ftp-host: ${{ secrets.FTP_SERVER_ADDRESS }}
ftp-root: public_html
ftp-user: ${{ secrets.FTP_USERNAME }}
ftp-pass: ${{ secrets.FTP_PASSWORD }}
branch: retype
update-branch: trueIf the branch does not exist, it will be created as an orphan branch. This means the branch history won't be mixed with any other branch in the repository. This also means that, once the branch is deleted, GitHub will eventually wipe all history when it does its internal garbage collection.
When the documentation should be held in a subdirectory in the target website, say, /documentation, this would be used:
- uses: retypeapp/action-build@latest
with:
base: documentation
- uses: retypeapp/action-git-ftp@latest
with:
ftp-host: ${{ secrets.FTP_SERVER_ADDRESS }}
ftp-root: public_html/documentation
ftp-user: ${{ secrets.FTP_USERNAME }}
ftp-pass: ${{ secrets.FTP_PASSWORD }}
branch: ftp-history
update-branch: trueNotice:
-
It is required that the
public_html/documentation/directory exists in the ftp site prior to running the workflow, or it will fail. To avoid uploading to undesired locations, the Git-FTP Action won't create the root directory itself. But it will create subdirectories in the website as needed. -
The
basesetting is not required if theurlproject setting is set to the same directory (documentation). It is also not required if Retype is configured to support relative pathing (available since version 2.3.0). It would only be required if nourlis specified in Retype configuration file, and the Retype website is not going to be served from the host's root website directory. See more in Retype documentation on theurlproject setting.
This example will use a subfolder within the main branch to store history of the website changes.
- uses: retypeapp/action-git-ftp@latest
with:
ftp-host: ${{ secrets.FTP_SERVER_ADDRESS }}
ftp-root: wwwroot
ftp-user: ${{ secrets.FTP_USERNAME }}
ftp-pass: ${{ secrets.FTP_PASSWORD }}
branch: main
directory: docs
update-branch: trueIn this context, one would probably prefer the action to be triggered only on pushes/merges to the main branch, thus the workflow file would rather be configured like the following:
name: GitHub Action for Retype
on:
push:
branches:
- main
jobs:
job1:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: retypeapp/action-build@latest
- uses: retypeapp/action-git-ftp@latest
with:
ftp-host: ${{ secrets.FTP_SERVER_ADDRESS }}
ftp-root: wwwroot
ftp-user: ${{ secrets.FTP_USERNAME }}
ftp-pass: ${{ secrets.FTP_PASSWORD }}
branch: main
directory: docs
update-branch: trueIn the following sample, whenever a new Release is created in GitHub, the documentation will be published to a FTP host, having its change history kept in the retype branch. If GitHub Pages was configured to the same branch, it should then become in sync with the FTP published one.
name: Publish Retype powered website on a new release
on:
push:
branches:
- main
jobs:
publish:
name: Assemble and publish docs
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: retypeapp/action-build@latest
- uses: retypeapp/action-git-ftp@latest
with:
ftp-host: ${{ secrets.FTP_SERVER_ADDRESS }}
ftp-root: wwwroot
ftp-user: ${{ secrets.FTP_USERNAME }}
ftp-pass: ${{ secrets.FTP_PASSWORD }}
update-branch: true