Let’s dive into Continuous Integration (CI) and Continuous Deployment (CD).

Continuous Integration (CI) is a software development practice where developers frequently integrate their code changes into a shared repository. The main goal of CI is to catch integration issues early by automatically building and testing the software as soon as new changes are introduced. The process typically involves using a version control system (e.g., Git) to merge code changes into a central repository and triggering an automated build process, which compiles the code, runs unit tests, and performs other checks. If any issues are detected during the CI process, developers are notified immediately, allowing them to fix the problems before they become more significant. CI promotes collaboration, reduces the risk of integration failures, and ensures a consistent and stable codebase.

Continuous Deployment (CD), as mentioned earlier, is the practice of automatically deploying software changes to production environments. It involves extending CI by automatically releasing successfully tested code changes to production, eliminating the need for manual intervention. CD relies on robust automated testing and deployment processes to ensure the stability and reliability of the software. With CD, each code change that passes the automated tests is deployed, which leads to a continuous flow of new features, bug fixes, and improvements reaching the end-users quickly.

To summarize, Continuous Integration focuses on frequent integration of code changes into a shared repository, running automated tests, and catching integration issues early. It promotes collaboration and maintains a stable codebase. On the other hand, Continuous Deployment extends CI by automatically deploying successfully tested code changes to production, enabling rapid and frequent releases to end-users. Both practices contribute to building a robust and efficient software development pipeline.

For my purposes github has article how to setup CI for ruby https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-ruby

and fly.io how to setup CD https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

at the end I finish with that file

name: Ruby

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

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Ruby
        uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
        with:
          ruby-version: '3.2.1'
      - name: Install dependencies
        run: bundle install
      - name: Run tests
        run: bundle exec rspec
  deploy:
    name: Deploy app
    runs-on: ubuntu-latest
    needs: [test]
    if: github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v3
      - uses: superfly/flyctl-actions/setup-flyctl@master
      - run: flyctl deploy --remote-only
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

As you can see, deploy is going to run after test success, and it runs only on the main branch.