Prompt
GitHub Actions CI/CD setup
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
Here’s a practical GitHub Actions CI/CD setup you can use as a starting point. I’ll keep it generic, then I can tailor it if you tell me your stack (Node, Python, Java, Docker, etc.).
1) Typical CI/CD flow
A simple setup usually has:
- CI on pull requests / pushes to main
- install dependencies
- run tests
- run lint/format checks
- build the app
- CD on merge to main or version tags
- build artifact or Docker image
- push to registry or deploy to server/cloud
2) Example repo structure
.github/
workflows/
ci.yml
cd.yml
3) CI workflow example
This runs tests on every PR and push to main.
name: CI
on:
pull_request:
push:
branches:
- main
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up runtime
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint --if-present
- name: Test
run: npm test --if-present
- name: Build
run: npm run build --if-present
4) CD workflow example
This builds and deploys when you push a version tag like v1.0.0.
name: CD
on:
push:
tags:
- "v*.*.*"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up runtime
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build --if-present
- name: Deploy
run: echo "Add your deployment command here"
5) If you deploy with Docker
Example workflow to build and push an image to GitHub Container Registry:
name: Docker Build and Push
on:
push:
branches:
- main
jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest
6) Secrets and environment variables
Use GitHub Secrets for sensitive data:
DEPLOY_KEYSSH_HOSTAPI_TOKENAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
Add them in:
Repo → Settings → Secrets and variables → Actions
Then reference them like:
${{ secrets.DEPLOY_KEY }}
7) Good practices
- Use
npm ci/ equivalent locked installs in CI - Separate CI and CD workflows
- Use protected branches for
main - Require CI to pass before merge
- Pin action versions (
@v4, not@main) - Use environments for production approvals
- Cache dependencies for faster builds
- Add concurrency to avoid duplicate deploys
Example:
concurrency:
group: production
cancel-in-progress: true
8) Common deployment targets
Depending on your app, CD may deploy to:
- GitHub Pages
- AWS
- Azure
- GCP
- Vercel
- Netlify
- Docker host / VM
- Kubernetes
If you want, I can generate a ready-to-use GitHub Actions workflow for your exact stack, for example:
- Node.js + Jest
- Python + pytest
- Java + Maven
- Docker + Kubernetes
- Deploy to AWS / Azure / Vercel / Netlify
Just tell me your tech stack and deployment target.