Skip
Arish's avatar

3. GitHub Actions Introduction


What is GitHub Actions?

CI/CD platform built into GitHub. Free for public repos.

Key Concepts

  • Workflow - Automated process (YAML file)
  • Job - Set of steps that run on same runner
  • Step - Individual task in a job
  • Action - Reusable unit of code
  • Runner - Server that runs workflows

Your First Workflow

Create .github/workflows/ci.yml:

yaml
1name: CI
2
3on:
4  push:
5    branches: [main]
6  pull_request:
7    branches: [main]
8
9jobs:
10  test:
11    runs-on: ubuntu-latest
12    
13    steps:
14      - name: Checkout code
15        uses: actions/checkout@v4
16      
17      - name: Setup Ruby
18        uses: ruby/setup-ruby@v1
19        with:
20          ruby-version: '3.2'
21          bundler-cache: true
22      
23      - name: Run tests
24        run: bundle exec rspec

Workflow Triggers

yaml
1on:
2  push:                    # On push
3  pull_request:            # On PR
4  schedule:                # Cron schedule
5    - cron: '0 0 * * *'
6  workflow_dispatch:       # Manual trigger

Viewing Results

Check Actions tab in your repository for results.