/
dayekb
/
yml_examples
Обзор
Документация
Войти
/
dayekb
/
yml_examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
github_actions.yml
176 строк
5 KB
dayekb
upload files
14 окт 2025, 05:04
14 окт 2025, 05:04
6d5fc90
Код
Авторство
О чём код?
# GitHub Actions Workflow для Node.js приложения name: CI/CD Pipeline # События, которые запускают workflow on: push: branches: [ main, develop ] pull_request: branches: [ main ] schedule: - cron: '0 2 * * 1' # Каждый понедельник в 2:00 UTC # Переменные окружения env: NODE_VERSION: '18' CACHE_DEPENDENCY_PATH: package-lock.json # Права доступа permissions: contents: read security-events: write pull-requests: write # Задачи jobs: # Проверка кода lint: name: Lint Code runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: 'npm' cache-dependency-path: ${{ env.CACHE_DEPENDENCY_PATH }} - name: Install dependencies run: npm ci - name: Run ESLint run: npm run lint - name: Run Prettier run: npm run format:check # Сборка и тестирование test: name: Test Application runs-on: ubuntu-latest strategy: matrix: node-version: [16, 18, 20] os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v4 - name: Setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: 'npm' - name: Install dependencies run: npm ci - name: Run tests run: npm test - name: Upload coverage reports if: matrix.node-version == 18 && matrix.os == 'ubuntu-latest' uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} # Проверка безопасности security: name: Security Scan runs-on: ubuntu-latest needs: [lint] steps: - uses: actions/checkout@v4 - name: Run Snyk to check for vulnerabilities uses: snyk/actions/node@master env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - name: Run CodeQL Analysis uses: github/codeql-action/init@v2 with: languages: javascript - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 # Сборка Docker образа build: name: Build Application runs-on: ubuntu-latest needs: [test, security] outputs: image-tag: ${{ steps.meta.outputs.tags }} image-digest: ${{ steps.build.outputs.digest }} steps: - uses: actions/checkout@v4 - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} tags: | type=ref,event=branch type=ref,event=pr type=sha - name: Build and push id: build uses: docker/build-push-action@v5 with: context: . push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max # Деплой в staging deploy-staging: name: Deploy to Staging runs-on: ubuntu-latest needs: [build] if: github.ref == 'refs/heads/develop' environment: name: staging url: https://staging.myapp.com steps: - name: Deploy to staging run: | echo "Deploying ${{ needs.build.outputs.image-tag }} to staging" # Здесь будет реальный код деплоя # Деплой в production deploy-production: name: Deploy to Production runs-on: ubuntu-latest needs: [build] if: github.ref == 'refs/heads/main' environment: name: production url: https://myapp.com steps: - name: Deploy to production run: | echo "Deploying ${{ needs.build.outputs.image-tag }} to production" # Здесь будет реальный код деплоя # Concurrency control concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true