Goal
Produce a working workflow file that catches broken code on every pull request and deploys only tested code from the main branch.
Inputs
- Language and package manager: [e.g. Node 20 with npm, Python 3.12 with pip]
- Commands: [install, lint, test, build]
- Deploy target: [e.g. static hosting, container registry, server over SSH, none]
- Branches: [e.g. pull requests to main, pushes to main]
- Secrets needed: [names only]
Steps
- Trigger on pull requests and pushes to the chosen branches.
- Set up the runtime and cache dependencies.
- Run lint and tests; fail fast on errors.
- Build and upload the build output as an artifact.
- Add a deploy job that needs the build job and runs only on the main branch.
Output format
- The full YAML file in one code block, with short comments explaining each job.
- | Secret name | Used in step | Where to create it |
- What runs on a pull request versus a push to main, as two short lists.
- How to test the workflow safely before the first deploy.
Check before answering
- Secrets are read through the secrets context, never written in the file.
- Permissions are set to the minimum needed, with read-only contents by default.
- Third-party actions are pinned to a version.
- A concurrency rule stops two deploys running at once.
- The deploy job never runs on pull requests from forks.






