DeveloperBreeze

Github Actions Best Practices Development Tutorials, Guides & Insights

Unlock 1+ expert-curated github actions best practices tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your github actions best practices skills on DeveloperBreeze.

Mastering GitHub Workflows for Continuous Integration and Deployment

Tutorial August 29, 2024

name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Deploy to server
      env:
        SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
      run: |
        ssh-agent bash -c 'ssh-add <(echo "$SSH_PRIVATE_KEY") && ssh -o StrictHostKeyChecking=no user@server "cd /path/to/app && git pull && npm install && pm2 restart all"'
  • on: push: Triggers the workflow when there’s a push to the main branch.
  • secrets.SSH_PRIVATE_KEY: Retrieves the SSH key stored in GitHub Secrets, ensuring secure deployment.