2.27.2. Deploy with GitHub Actions
GitHub Actions is a collection of workflow automation tools on GitHub. With their help, you can run various actions when certain events occur. One example is the automatic upload of the project code from GitHub to the hosting when pushing changes to the repository.
Deploy via FTP
Attention!
Directory on hosting during deployment not cleared. Files that are not in the repository are not removed from the directory.Setting up automatic deployment on the example of an action FTP Deploy.
- Create hosted by an FTP user with access to the directory where the deployment should be performed.
- Disable FTP access restrictions.
- Open your repository on GitHub.
- Add the data necessary for deployment to the secrets:
How to add secrets:
- Switch to tab "Settings".
- Pleaseselect "Secrets → Actions" in the side menu.
- Click "New repository secret".
- Specify the name of the secret in the field "Name" and the value in the field "Value".
- Click "Add secret".
Each setting is added as a separate secret.
Name Value REMOTE_HOST
FTP host FTP_USER
FTP Login FTP_PASSWORD
FTP password FTP_PATH
Relative way from FTP access directory to the directory on the hosting where the deployment should be performed. Attention! Way necessarily must end with a slash /
. Also if your project has directorieslib
oretc
, the FTP user's access directory must be such that they end up not at the root. - Set up the action:
- Switch to tab "Actions".
- Click "set up a workflow yourself" or first "New workflow", and then "set up a workflow yourself".
- Replace the code in the field "Edit new file" on this one:
name: FTP deploy on push on: push jobs: web-deploy: name: Deploy runs-on: ubuntu-latest steps: - name: Get latest code uses: actions/checkout@v2 - name: Sync files uses: SamKirkland/FTP-Deploy-Action@4.3.0 with: server: ${{ secrets.REMOTE_HOST }} username: ${{ secrets.FTP_USER }} password: ${{ secrets.FTP_PASSWORD }} server-dir: ${{ secrets.FTP_PATH }}
- Click "Start commit" and then "Commit new file".
- Switch to tab "Actions" and check the deployment status. To view details, click on the workflow name in the list "All workflows" and then on "build" - if successful, each operation should have a checkmark next to it.
Deploy via SSH
Attention!
Directory on hosting during deployment cleared. The contents of the directory will match the contents of the repository.Setting up automatic deployment on the example of an action Rsync Deployments Action.
- Set up SSH key authentication:
- Generate and add account key.
- Bind the key to the hosting account where the deployment should be performed.
- Open your repository on GitHub.
- Add the data necessary for deployment to the secrets:
How to add secrets:
- Switch to tab "Settings".
- Pleaseselect "Secrets → Actions" in the side menu.
- Click "New repository secret".
- Specify the name of the secret in the field "Name" and the value in the field "Value".
- Click "Add secret".
Each setting is added as a separate secret.
Name Value REMOTE_HOST
SSH host REMOTE_USER
SSH Login REMOTE_KEY
Data private key in PEM format (starts with -----BEGIN RSA PRIVATE KEY-----
). Attention! The key must be private, not public.REMOTE_PATH
Absolute path to the directory on the hosting where the deployment should be performed. - Set up the action:
- Switch to tab "Actions".
- Click "set up a workflow yourself" or first "New workflow", and then "set up a workflow yourself".
- Replace the code in the field "Edit new file" on this one:
name: SSH deploy on push on: push jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: rsync deploy uses: burnett01/rsync-deployments@5.2 with: switches: -avzr --delete path: . remote_host: ${{ secrets.REMOTE_HOST }} remote_user: ${{ secrets.REMOTE_USER }} remote_key: ${{ secrets.REMOTE_KEY }} remote_path: ${{ secrets.REMOTE_PATH }}
- Click "Start commit" and then "Commit new file".
- Switch to tab "Actions" and check the deployment status. To view details, click on the workflow name in the list "All workflows" and then on "build" - if successful, each operation should have a checkmark next to it.