AI Hints
Home›CI/CD with GitHub Actions Tutorial›Projects: Releases and the Full Pipeline
CI/CD with GitHub Actions · Lesson 123 of 138

Project: The Full Pipeline

From commit to production.

⏱ 2 min read▶ Video at 2:23:05🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

The final project puts it all together. Pull requests get tested. Pushes to main get tested, deployed to staging, and then promoted to production, using one build from one commit.

Project: The Full Pipeline
From the video: Project: The Full Pipeline
  • PRs get tested
  • Main goes to staging
  • Then to production

pipeline.yml

It runs on pushes to main, and on pull requests. The test job lints and tests. Staging only runs on pushes, not on pull requests, and needs test. Production needs staging, and its environment would require an approval.

.github/workflows/pipeline.ymlyaml
name: Pipeline
on: { push: { branches: [main] }, pull_request: }
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pip install -q -r requirements.txt && flake8 && pytest -q
  staging:
    if: github.event_name == 'push'
    needs: test
    environment: staging
    runs-on: ubuntu-latest
    steps: [ { run: "echo Deploy sha-${GITHUB_SHA::7} to staging" } ]
  production:
    needs: staging
    environment: production
    runs-on: ubuntu-latest
    steps: [ { run: "echo Deploy sha-${GITHUB_SHA::7} to production" } ]

A pull request, then a push

As a pull request, only the test job runs. Staging is skipped by its condition, and production is skipped because staging didn't run. As a push to main, all three jobs run in order, with the same commit SHA.

Terminal
run-steps .github/workflows/pipeline.yml --event pull_request | grep -E "^Job|skipped|Deploy"
Job: test
Job: staging
  - skipped, because its if: condition was false
Job: production
  - skipped, because a job it needs was skipped
run-steps .github/workflows/pipeline.yml | grep -E "^Job|Deploy"
Job: test
Job: staging
  ✓ Run echo Deploy sha-${GITHUB_SHA::7} to staging
      Deploy sha-7418016 to staging
Job: production
  ✓ Run echo Deploy sha-${GITHUB_SHA::7} to production
      Deploy sha-7418016 to production

Summary

Test every change, deploy main to staging, and promote the same build to production. That's a complete CICD pipeline. Next, other tools you might meet.

Key takeaways
  • PRs: test
  • main: staging
  • Then production
Next up: Other CI Tools — beyond GitHub Actions