Context
Deploying {{project_name}} ({{project_type}}) to Netlify. You will follow a strict 6-phase Deployment Lifecycle Contract.
Instructions
Execute the following phases in order:
Phase 1: Authentication
- Ensure the
NETLIFY_AUTH_TOKENenvironment variable is set to a valid Netlify Personal Access Token. - If running locally, you may authenticate interactively with
npx netlify login. However, for automated agents, ensure the token is provided. - Validate by running
npx netlify status.
Phase 2: Build
- Prepare the artifacts for deployment.
- Run your framework's build command (e.g.,
npm run buildoryarn build) to generate the output directory (e.g.,dist/orbuild/). - If using Netlify Functions, ensure they are compiled or placed in the designated functions directory (e.g.,
netlify/functions).
Phase 3: Install / Provisioning
- Ensure the target Netlify site exists.
- Check for
netlify.tomlin the project root. This file should define build commands and publish directories. - Ensure the site is linked to the current directory by running
npx netlify linkor explicitly providing theNETLIFY_SITE_IDenvironment variable.
Phase 4: Deploy
- Ship the artifact to Netlify.
- For a draft/preview deployment, run
npx netlify deploy --build --site $NETLIFY_SITE_ID. - For a production deployment, run
npx netlify deploy --prod --build --site $NETLIFY_SITE_ID.
Phase 5: Checking
- Verify the deployment was successful.
- After a successful deploy, Netlify outputs a Draft URL or a Live URL.
- Use
curl -sSf <URL>to ensure the application returns a 200 OK status code. If it fails, check build logs usingnpx netlify build:logsor the dashboard.
Phase 6: Update / Rollback
- If Phase 5 fails, immediately initiate a rollback.
- Netlify supports atomic deploys. You can rollback to a previous successful deploy via the Netlify dashboard or by triggering a redeploy of an older Git commit.
- Note the failure in the progress log.
Validation
- Netlify authentication (
netlify status) succeeds. - Build succeeds.
- Artifacts are deployed.
- Health check (curl) returns 200 OK.