Prompt
How do I automate build test deploy with GitHub Actions?
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
You can automate build, test, and deploy with GitHub Actions by creating a workflow file in your repo that runs on events like push or pull_request.
1) Create a workflow file
Add this file to your repository:
.github/workflows/ci-cd.yml
2) Example workflow
Here’s a simple example for a Node.js app:
name: Build, Test, Deploy
on:
push:
branches: [ "main" ]
pull_request:
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Run tests
run: npm test
deploy:
needs: build-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy
run: echo "Deploying application..."
# Replace this with your real deploy command
3) How it works
- on: defines when the workflow runs
pushtomain- any
pull_request
- jobs: define stages
build-testruns firstdeployruns only ifbuild-testsucceeds
- needs: makes
deploydepend onbuild-test - if: ensures deployment only happens on pushes to
main
4) Store secrets for deployment
If you deploy to a cloud provider, store credentials in:
- GitHub repo → Settings → Secrets and variables → Actions
Then use them like this:
- name: Deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: ./deploy.sh
5) Common deployment targets
GitHub Actions can deploy to:
- AWS
- Azure
- Google Cloud
- Docker / Kubernetes
- Vercel
- Netlify
- GitHub Pages
- Heroku (via CLI or custom action)
6) Best practices
- Run tests on every pull request
- Deploy only from the
mainbranch - Use environment-specific secrets
- Add linting and security scans
- Use job
needsto enforce order - Use reusable actions where possible
If you want, I can give you a ready-to-use GitHub Actions workflow for a specific stack like Node.js, Python, Java, Docker, or React, and a deploy target like AWS, Azure, or GitHub Pages.