GitHub Actions を用いてFTPサーバーへ自動Deployする方法 - samidevjp/Tips GitHub Wiki
参考:https://qiita.com/hoshimado/items/e2073b7a6d40a23cfb55
FTPサーバー側の設定(さくらサーバーの場合)
GitHub > Setting > Secrets > Actions > New repository sercet
「Add secret」ボタンを押下
以下の「キー」を追加し、それぞれの値を設定する(※キー名称は変更可能だが、その場合は後述のyamlファイル記載も合わせて変更の事)
FTP_SERVER
FTPサーバーアドレス
FTP_USERNAME
FTPログインユーザー名
FTP_PASSWORD
FTPログインパスワード
FTP_SERVER_DIR
FTPサーバー側の格納先フォルダパス
例:「~/www/static-webapp/app-name/」
最後を「/」で終えること。理由は以下を参照
環境変数は
/file-name/git/
のように、ルートディレクトリからかくのでOK
https://github.com/SamKirkland/FTP-Deploy-Action#settings
server-dir
Folder to upload to (on the server), must end with trailing slash /
GitHub Actoinsを設定
GitHub > Actions
「set up a workflow yourself」ボタンを押下
テンプレートとして以下が提示されるので、これを編集
name: FTP for XXXXXX to sakura
# Controls when the workflow will run
on:
# Triggers the workflow on push but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "ftp-deploy". The default job name is "build".
ftp-deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Sync files
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
server-dir: ${{ secrets.FTP_SERVER_DIR }}
local-dir: ./public/