Write a GitHub Actions workflow that builds, tests and deploys a Node.js app with least-privilege permissions, pinned actions, OIDC cloud credentials and environment approvals.
Write a GitHub Actions workflow for the Node.js application below. Use the repository's real commands, keep permissions minimal, and gate production behind a GitHub environment. Platform-neutral pipeline design is a separate task; this one produces workflow YAML. ## Inputs Node.js version and package manager: [NODE_AND_PACKAGE_MANAGER] Install, lint, unit test, integration/end-to-end test and build commands: [COMMANDS] Code-quality or security tools already used (for example CodeQL, SonarQube Cloud, npm audit): [ANALYSIS_TOOLS] Deployment targets for staging and production (for example AWS Elastic Beanstalk, ECS, EC2): [DEPLOY_TARGETS] Cloud authentication available (OIDC role or stored keys): [CLOUD_AUTH] Triggers and branches (pull requests, pushes to main, tags): [TRIGGERS] Post-deploy checks and monitoring hooks (smoke test URL, deployment markers): [POST_DEPLOY] ## Instructions 1. Triggers: run tests on pull requests; deploy only from [TRIGGERS] pushes. 2. Set top-level `permissions` to read-only and grant extra scopes per job (for example `id-token: write` only on deploy jobs). 3. Reference third-party actions by full-length commit SHA with the version in a comment. Do not invent SHAs; leave a clear placeholder if you cannot look them up. 4. Jobs: build (install with the lock file, lint, build, upload artifact); test (unit and end-to-end with [COMMANDS]; publish coverage as an artifact); analysis (only the tools in [ANALYSIS_TOOLS]); deploy-staging; deploy-production. 5. Deploy jobs download the tested artifact rather than rebuilding, use `environment: staging` and `environment: production`, and authenticate with OIDC when [CLOUD_AUTH] allows it. 6. Add `concurrency` so two deployments to the same environment cannot overlap. 7. After deployment, run the smoke test and any deployment marker in [POST_DEPLOY]. Monitoring setup itself happens outside the workflow. ## Return 1. `.github/workflows/ci-cd.yml` 2. Repository settings to configure: environments, required reviewers, secrets and variables, OIDC role trust policy. 3. A table of each job, what it blocks, and its permissions. 4. Items to verify on the first run. ## Acceptance checks - Every `uses:` reference is a full SHA or an explicit placeholder. - No long-lived cloud keys when OIDC is available. - Production deploy requires the `production` environment. - No claim that the workflow ran successfully.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Node: 22 with npm and package-lock.json Commands: npm ci; npm run lint; npm test -- --coverage; npx playwright test; npm run build Analysis: CodeQL (default setup already enabled), npm audit --audit-level=high Targets: AWS Elastic Beanstalk environments app-staging and app-prod Cloud auth: IAM role trusted for GitHub OIDC Triggers: pull_request to main; push to main deploys staging then production Post-deploy: curl -f https://staging.example.com/healthz and the production equivalent
A workflow with permissions: contents: read at the top; build and test jobs on pull_request and push; npm audit in an analysis job while CodeQL stays in its existing default setup rather than being duplicated; deploy-staging and deploy-production jobs on push to main only, each with id-token: write, aws-actions/configure-aws-credentials referenced by SHA placeholder, environment: staging/production, concurrency groups per environment, the uploaded build artifact reused, and a curl -f smoke test after deploy. The settings list includes required reviewers on the production environment. Illustrative expectation; a local static checker flagged unpinned uses: lines and a missing permissions block on a synthetic workflow fixture (see report).
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts: