Gestionarea modulelor cookie care sunt utilizate pentru publicitate, cum ar fi personalizarea anunțurilor, remarketing și analiza performanței anunțurilor.
2.19.9. Deploy using GitHub Actions
GitHub Actions is a set of tools for automating workflows on GitHub. They can be used to trigger various actions when certain events occur. One example is automatically uploading project code from GitHub to hosting when changes are pushed to the repository.
SSH
Attention!
On deployment, the directory on the hosting is cleaned up. The contents of the directory will match the contents of the repository.Setting up automatic deployment using the Rsync Deployments Action as an example.
- Configure SSH key-based authentication:
- Generate and add key to your account.
- Bind key to the hosting account where the deploy is to be performed.
- Open your repository on GitHub.
- Add the data required for the deployment to the secrets:
How to add secrets:
- Switch to the "Settings" tab.
- Select "Secrets and variables → Actions" from the side menu.
- Click "New repository secret".
- Specify the name of the secret in the "Name" field and the value in the "Value" field.
- Click "Add secret".
Each parameter is added as a separate secret.
Name Value REMOTE_HOSTSSH host REMOTE_USERSSH login REMOTE_KEYThe private key data in PEM format (starts with -----BEGIN RSA PRIVATE KEY-----). ⚠️ Key must be private, not public.REMOTE_KEY_PASSPrivate key passphrase (if not used, can be not added or added with any value). REMOTE_PATHAbsolute path to the directory on the hosting, to which the upload should be performed. - Configure action:
- Switch to the "Actions" tab.
- Click "set up a workflow yourself" or first "New workflow" and then "set up a workflow yourself".
- Replace the code in the "Edit new file" field with this:
name: SSH deploy on push on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - name: rsync deploy uses: burnett01/rsync-deployments@v8 with: switches: -avzr --delete path: . remote_host: ${{ secrets.REMOTE_HOST }} remote_user: ${{ secrets.REMOTE_USER }} remote_key: ${{ secrets.REMOTE_KEY }} remote_key_pass: ${{ secrets.REMOTE_KEY_PASS }} remote_path: ${{ secrets.REMOTE_PATH }} - Click "Start commit" and then "Commit new file".
- Switch to the "Actions" tab and check the status of the deployment. Click on the workflow name in the "All workflows" list and then on "build" to view details — if successful, there should be a checkmark next to each operation.
FTP
Attention!
On deployment, the directory on the hosting is not cleaned up. Files that are not in the repository are not removed from the directory.Server sent FIN packet unexpectedly
If you get the error "Server sent FIN packet unexpectedly" when deploying a project with a large number of files, it is recommended to switch to SSH. For FTP may help, downgrading the action version to 3.1.2-patch. This will require modifying the action: replace theuses: SamKirkland/FTP-Deploy-Action@v4.3.5 line with uses: SamKirkland/FTP-Deploy-Action@v3.1.2-patch, rename the server, username and password parameters to ftp-server, ftp-username and ftp-password. Also, the server-dir parameter will not work in this case and the deploy directory will only need to be set by changing the access directory of FTP user.
Setting up automatic deployment using the FTP Deploy action as an example.
- Create an FTP user on the hosting with access to the directory to which the upload should be performed.
- Disable FTP access restrictions.
- Open your repository on GitHub.
- Add the data required for the deployment to the secrets:
How to add secrets:
- Switch to the "Settings" tab.
- Select "Secrets and variables → Actions" from the side menu.
- Click "New repository secret".
- Specify the name of the secret in the "Name" field and the value in the "Value" field.
- Click "Add secret".
Each parameter is added as a separate secret.
Name Value REMOTE_HOSTFTP host FTP_USERFTP login FTP_PASSWORDFTP password FTP_PATHRelative path from FTP access directory to the directory on the hosting where the deploy should be performed. ⚠️ The path must end with the slash /. Also, if your project hasliboretcdirectories, the FTP user access directory should be such that they are not in the root. - Configure action:
- Switch to the "Actions" tab.
- Click "set up a workflow yourself" or first "New workflow" and then "set up a workflow yourself".
- Replace the code in the "Edit new file" field with this:
name: FTP deploy on push on: push: branches: - main jobs: web-deploy: name: Deploy runs-on: ubuntu-latest steps: - name: Get latest code uses: actions/checkout@v4 - name: Sync files uses: SamKirkland/FTP-Deploy-Action@v4.3.5 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 the "Actions" tab and check the status of the deployment. Click on the workflow name in the "All workflows" list and then on "build" to view details — if successful, there should be a checkmark next to each operation.
(3)
Comentarii
Будь ласка, додайте інструкцію для Gitlab
Підтримую. Цікавить інструкція для GitLab. Дякую.
як налаштувати деплой через sftp в GitHub Actions?
Спосіб «SSH» в цій статті це по суті і є такий деплой.
on:
push:
branches:
- main