Prompt
GitHub Actions for automated testing and deployment
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
Here’s a solid GitHub Actions setup for automated testing and deployment. I’ll keep it generic and practical, and you can adapt it to your stack.
Typical workflow
A common CI/CD flow is:
- Run tests on every push / pull request
- Build the app
- Deploy only from a protected branch like
main - Optionally tag releases and deploy from tags
Example: CI workflow for testing
Create .github/workflows/ci.yml:
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
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: Run tests
run: npm test
Example: CD workflow for deployment
Create .github/workflows/deploy.yml:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
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 project
run: npm run build
- name: Deploy application
run: |
echo "Add your deployment command here"
# Example:
# npm run deploy
Recommended improvements
1. Use a single pipeline with separate jobs
You can combine test and deploy in one workflow and make deployment depend on tests passing:
name: CI/CD
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm test
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm run deploy
2. Store secrets safely
Use GitHub Secrets for credentials:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYDEPLOY_TOKENSSH_PRIVATE_KEY
Access them like this:
- name: Deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: npm run deploy
3. Add branch protections
Protect main so that:
- PRs must pass tests before merge
- direct pushes are restricted
- required reviews are enabled
4. Use environments for safer deployments
GitHub Environments let you add:
- approval gates
- environment-specific secrets
- separate staging/production configs
Example:
environment: production
Example for Docker-based deployment
name: Deploy Docker App
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t my-app .
- name: Log in to registry
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Push image
run: |
docker tag my-app myrepo/my-app:latest
docker push myrepo/my-app:latest
Best practices
- Run tests on PRs
- Deploy only on merged code
- Use
npm ciinstead ofnpm installfor consistency - Cache dependencies to speed up workflows
- Separate staging and production
- Keep deployment credentials in Secrets
- Pin action versions like
actions/checkout@v4
If you want, I can generate a full GitHub Actions workflow tailored to your stack—for example:
- Node.js
- Python
- Java / Maven
- Docker
- AWS / Azure / GCP
- Static site (GitHub Pages, Netlify, Vercel)