🐙
CI/CD & GitOps

GitHub Actions

CI/CD automation built into GitHub repositories with workflow YAML

🐧 Linux🍎 Mac🪟 Windows📋 Quick reference →
Reviewed: Tested on: GitHub-hosted runners · Ubuntu 22.04 · Kubernetes 1.29

✓ Team golden path — CI/CD

Colocated with PRs; OIDC to AWS/EKS

What is this?

GitHub Actions runs automated tests and deployments when you push code to GitHub.

📁

Config files for GitHub Actions

Where to create or edit the main configuration — paths below match the setup steps.

  • .github/workflows/*.yml

    Location: Repository root → .github/workflows/

    Workflow definitions — build, test, deploy on push/PR

📥

Step 01

Set Up GitHub Actions

(01)Create workflow file

No install needed — add .github/workflows/ci.yml to your repo.

Linux
1mkdir -p .github/workflows
2cat > .github/workflows/ci.yml << 'EOF'
3name: CI
4on: [push, pull_request]
5jobs:
6 build:
7 runs-on: ubuntu-latest
8 steps:
9 - uses: actions/checkout@v4
10 - uses: actions/setup-node@v4
11 with:
12 node-version: 20
13 - run: npm ci && npm test
14EOF

Step 02

Verify

(01)Check workflow runs

Linux
1gh run list
2gh run view

Step 03

Workflow Patterns

(01)Docker build & push workflow

Linux
1# .github/workflows/docker.yml snippet:
2# - uses: docker/login-action@v3
3# with:
4# username: ${{ secrets.DOCKER_USER }}
5# password: ${{ secrets.DOCKER_TOKEN }}
6# - uses: docker/build-push-action@v5
7# with:
8# push: true
9# tags: user/app:latest
🔧

Step 04

Common Problems

#1Workflow not triggering on push

Linux
1# Check workflow path: .github/workflows/*.yml
2# Verify branch filter matches your branch
3git branch --show-current
4gh run list

#2Job failed — permission denied

Linux
1# Add to workflow:
2# permissions:
3# contents: read
4# For forks: check Settings → Actions → General

📋Config templates

1 YAML template for GitHub Actions. Copy and deploy after setup.

1 ready-to-copy template. Expand one, copy the YAML, then run the deploy commands.

.github/workflows/ci.yml

Node.js — install, test, build Docker image, push to registry

yaml
1name: CI Pipeline
2
3on:
4 push:
5 branches: [main, develop]
6 pull_request:
7 branches: [main]
8
9env:
10 REGISTRY: ghcr.io
11 IMAGE_NAME: ${{ github.repository }}
12
13jobs:
14 build-and-test:
15 runs-on: ubuntu-latest
16 steps:
17 - uses: actions/checkout@v4
18
19 - name: Setup Node.js
20 uses: actions/setup-node@v4
21 with:
22 node-version: "20"
23 cache: "npm"
24
25 - name: Install dependencies
26 run: npm ci
27
28 - name: Run tests
29 run: npm test
30
31 - name: Build Docker image
32 run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
33
34 - name: Log in to GitHub Container Registry
35 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
36 uses: docker/login-action@v3
37 with:
38 registry: ${{ env.REGISTRY }}
39 username: ${{ github.actor }}
40 password: ${{ secrets.GITHUB_TOKEN }}
41
42 - name: Push image
43 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
44 run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}

.github/workflows/java-ci.yml

Spring Boot / Maven — compile, test, package JAR

yaml
1name: Java CI
2
3on:
4 push:
5 branches: [main]
6 pull_request:
7 branches: [main]
8
9jobs:
10 build:
11 runs-on: ubuntu-latest
12 steps:
13 - uses: actions/checkout@v4
14
15 - name: Set up JDK 21
16 uses: actions/setup-java@v4
17 with:
18 java-version: "21"
19 distribution: "temurin"
20 cache: maven
21
22 - name: Build and test
23 run: mvn -B verify
24
25 - name: Upload JAR artifact
26 uses: actions/upload-artifact@v4
27 with:
28 name: app-jar
29 path: target/*.jar
📄

Step 01

Use the Workflow

(01)Add workflow to your repo

Linux
1mkdir -p .github/workflows
2cp ci.yml .github/workflows/ci.yml
3git add .github/workflows/
4git commit -m "Add CI pipeline"
5git push origin main
6# View runs: GitHub → Actions tab

(02)Add secrets (for registry push)

Linux
1# GitHub repo → Settings → Secrets and variables → Actions
2# GITHUB_TOKEN is automatic; add DOCKERHUB_TOKEN if pushing to Docker Hub