All Guides

Настройка GitHub Actions CI/CD

Создайте автоматизированный пайплайн тестирования и деплоя.

Intermediate25 мин.

Setup Steps

1. Create .github/workflows/ directory in your repository

2. Create a workflow file (.github/workflows/ci.yml):

name: CI/CD Pipeline

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm test
      - run: npm run build

3. Add a deploy job:

deploy:
    needs: test
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to server
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.SERVER_HOST }}
          username: ${{ secrets.SERVER_USER }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /var/www/app
            git pull
            npm ci
            npm run build
            pm2 restart app

4. Add required secrets in GitHub Settings > Secrets

5. Trigger the workflow by pushing

6. Monitor results in the Actions tab