Quick answer
Separate validation of proposed changes from deployment of trusted releases. Install locked dependencies, run the project’s required checks, build the artifact, and deploy only through an explicitly scoped release job. Keep deployment credentials out of untrusted pull-request execution. A green workflow proves the checks that actually ran; it does not establish production health, safe database migration, or successful rollback.
Practical implementation steps
1. Use the same required commands as local development
Name actual scripts rather than inventing npm test when the repository has no test script. Fail required checks instead of using if-present to silently skip them. Match the application runtime and commit its lockfile. Cache package downloads to improve speed, but do not treat the cache as a replacement for installation or a proof of dependency integrity. A clean runner should produce the same artifact contract.
2. Treat pull-request code as executable input
A build or test can execute repository scripts and dependencies. Give validation only the token permissions it needs and avoid production secrets. Do not combine pull_request_target authority with checkout and execution of untrusted head code. Review reusable actions as dependencies; GitHub recommends full commit-SHA pinning for immutable action versions. Human-readable major tags are useful for examples but need an update and review policy in a hardened pipeline.
3. Promote an identifiable release artifact
Record the commit, build configuration, and artifact or image digest. Deploy the tested artifact where the hosting platform supports it instead of silently rebuilding different output in a later job. Separate runtime secrets from public build-time variables, especially variables bundled into browser code. A release job should explain its environment, credentials, deployment command, health check, and recovery action.
4. Coordinate releases and recovery
Use environment protection appropriate to the team and a shared concurrency group for jobs targeting the same environment. Concurrency is configured separately from the environment and only coordinates jobs using that group. Cancel obsolete validation runs freely when safe; canceling a deployment mid-migration can leave an incomplete release. Define rollback from the previous artifact and compatible schema before enabling automatic production promotion.
Implementation example
This validation workflow uses scripts that exist in this portfolio: lint, typecheck, localization tests, and build. It deliberately shows CI only; a deployment job requires the actual hosting contract and cannot be represented by a pretend deploy command. The action major versions match GitHub’s current Node.js documentation; pin reviewed SHAs for stronger immutability and ensure runner compatibility when self-hosting.
name: Validate web application
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: validate-${{ github.ref }}
cancel-in-progress: true
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: "22"
cache: npm
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm run test:i18n
- run: npm run build
Tradeoffs and alternatives
One validation job is easy to understand and sufficient for a small application. Separate jobs can improve feedback or isolate tool requirements, while adding artifact handoffs and coordination. A hosted deployment integration can automate promotion, but its source, secrets, checks, and rollback still need review. Add a version matrix only when the application intentionally supports multiple runtimes; more jobs do not automatically increase relevant coverage.
Common mistakes
Avoid deployment secrets in pull-request builds, silently optional required checks, mutable artifacts without provenance, and cancel-in-progress on a non-interruptible migration. Do not mark a release healthy merely because the CLI exited successfully. A check that only hits a static homepage can miss broken authentication or an unavailable data service. Choose a representative smoke check and monitor the deployed version before concluding promotion succeeded.
Production checklist
- Validation scripts exist and fail when required checks fail.
- Untrusted code has no production credentials.
- Actions and runtime versions have an update policy.
- Release artifact provenance is recorded.
- Deployment concurrency, health, and rollback are explicit.
FAQ
Should every push deploy production?
Only when the trusted branch, checks, artifact, and recovery contract justify it. Automatic deployment is a policy choice, not an inherent requirement of CI.
Does a passing build prove the live website works?
No. It verifies build-time checks. Production configuration, credentials, routing, and dependencies need release-specific smoke checks.
Next step
Run the validation workflow on a safe proposed change, inspect its actual checks, and document the release artifact contract. Add the production job only after its environment, health criteria, and rollback procedure are concrete and reviewable.
Primary sources
Related guides and examples
Need this implemented in a real product?
One connected implementation across the interface, application logic, APIs, and data layer.