GitHub Actions Workflow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
REGISTRY: gcr.io
PROJECT_ID: my-project
SERVICE_NAME: api
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest --cov=src --cov-report=xml
- name: Upload coverage
uses: codecov/codecov-action@v3
build:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
outputs:
image: ${{ steps.build.outputs.image }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: _json_key
password: ${{ secrets.GCP_SA_KEY }}
- name: Build and push
id: build
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.SERVICE_NAME }}
image: ${{ needs.build.outputs.image }}
region: us-central1
|
CI/CD Architecture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| βββββββββββββββ βββββββββββββββββββββββββββββββββββββββ
β Push to ββββββΆβ GitHub Actions β
β main β β β
βββββββββββββββ β βββββββ βββββββ ββββββββββββββββ β
β βTest βββΆβBuildβββΆβDeploy to Prodβ β
βββββββββββββββ β βββββββ βββββββ ββββββββββββββββ β
β Push to ββββββΆβ β
β develop β β βββββββ βββββββ ββββββββββββββββ β
βββββββββββββββ β βTest βββΆβBuildβββΆβDeploy to Dev β β
β βββββββ βββββββ ββββββββββββββββ β
βββββββββββββββ β β
β PR ββββββΆβ βββββββ β
β β β βTest β (no deploy) β
βββββββββββββββ β βββββββ β
βββββββββββββββββββββββββββββββββββββββ
|
Frequently Asked Questions
What are GitHub Actions?
GitHub Actions is a CI/CD platform built into GitHub. It automates workflows triggered by events like pushes, PRs, or schedules. Actions can build, test, and deploy code, run any script, and integrate with thousands of marketplace actions.
How much does GitHub Actions setup cost?
GitHub Actions development typically costs $90-130 per hour. A basic workflow starts around $2,000-5,000, while thorough pipelines with matrix builds, security scanning, and multi-environment deployments range from $10,000-25,000+.
GitHub Actions vs Jenkins: which should I choose?
Choose GitHub Actions for: GitHub repos, simpler maintenance, YAML-based configs, marketplace actions. Choose Jenkins for: complex enterprise needs, on-premise requirements, maximum customization. GitHub Actions is the modern standard for most teams.
What workflows should I automate with GitHub Actions?
Common workflows: CI (lint, test, build), CD (deploy to staging/production), security scanning (Dependabot, CodeQL), release automation, documentation generation, and scheduled jobs (data sync, cleanup).
Can you help optimize expensive GitHub Actions usage?
Yes. I reduce costs through: caching dependencies, canceling redundant runs, using self-hosted runners for heavy workloads, optimizing parallelization, and reducing build times. Proper optimization can reduce Actions minutes significantly.