launch-sync-environment-variables-from-env-example

作者: contentstack

Fetch environment variables from a Contentstack Launch project, compare them with a local `.env.example` file, and patch the target environment to add any…

npx skills add https://github.com/contentstack/contentstack-agent-skills --skill launch-sync-environment-variables-from-env-example

Sync Launch environment variables from .env.example

Description

Fetch environment variables from a Contentstack Launch project, compare them with a local .env.example file, and patch the target environment to add any missing keys.

When to Use

Use when a Launch environment must match the keys defined in a local .env.example file. Use to audit missing environment variables before a deployment. Use to add missing variable names to a Launch environment without manually editing config.

User Problem

A Launch environment can drift from the variables expected by a frontend project. This skill checks the environment against .env.example and updates Launch when keys are missing.

Success Criteria

All keys present in .env.example exist in the target Launch environment. Missing keys are added through the Launch Projects/Environments API. The script reports what was missing and what was updated. No secrets are printed in logs.

Expected Inputs

  • Launch project UID
  • Launch environment UID
  • Path to local .env.example file
  • Launch API credentials or authenticated context
  • Optional: dry-run flag

Expected Outputs

  • List of keys found in .env.example
  • List of keys already present in Launch
  • List of missing keys that were patched
  • Summary of API calls made
  • Exit code indicating success or failure

Example User Requests

  • Generate a Node.js script that syncs Launch environment variables from .env.example.
  • Compare my Launch environment variables with .env.example and add any missing keys.
  • Write a script to patch missing Launch environment variables for project abc123 and environment dev456.

Workflow Summary

Read and parse the local .env.example file. Fetch the target Launch environment and its current variables. Compare keys from the file against keys in Launch. Build a minimal patch payload containing only missing keys. Call PATCH /projects/{project_uid}/environments/{environment_uid}. Report the changes and stop without exposing values.

Instructions

Parse input

Read the local .env.example file and extract variable names. Ignore comments, blank lines, and malformed entries.

Fetch Launch state

Use the Launch API to get the target project and environment, then read the current environment variables.

Compare keys

Compare .env.example keys against Launch keys. Identify only missing keys unless the user explicitly asks to update existing values.

Patch environment

Call PATCH /projects/{project_uid}/environments/{environment_uid} with the minimal update needed to add missing keys.

Report results

Return a concise summary of missing keys, patched keys, and any errors. Never print secret values or tokens.

Output Format

Use concise, machine-readable summaries. Do not print secret values from Launch or local files. Show missing keys and updated keys separately. Include the project UID and environment UID in the summary. If running in dry-run mode, clearly label that no changes were made.

Tooling Notes

Use the Launch API and Projects/Environments endpoints. Validate project and environment UIDs before patching. Avoid logging deployment tokens or environment secrets. Use the smallest possible PATCH payload. If the API returns validation errors, surface them without retrying blindly.

Security

Defaults

Never expose deployment tokens or environment secrets. Validate project and environment targets before patching. Do not print variable values in logs or output. Require explicit user intent before making any change. Prefer dry-run behavior unless the user asks to apply changes.

Destructive Actions

Treat any PATCH that changes Launch configuration as a destructive external action. Confirm the target project and environment before applying changes. Do not broaden the update beyond missing keys unless the user explicitly requests it.

Secrets

Never reveal secret values from .env.example or Launch. Log only key names and counts. Redact tokens, API keys, and environment values in all output.

Environment Variables

Read environment variables only as needed for authentication and target selection. Never echo env var values. Support loading from local .env.example for comparison only, not for secret disclosure.

Product Context

    • Product: Launch
    • Description: Contentstack Launch: hosting, deployment, edge delivery, serverless functions, environment management, and CI/CD for Contentstack-powered frontends.
    • Product safety rules: - Never expose deployment tokens or environment secrets.
  • Validate deployment targets before triggering.
  • Require confirmation for production deployments.
  • Never auto-deploy to production without review.
    • Default tools: ["Launch API", "Projects", "Environments", "Deployments", "Serverless Functions", "Edge Delivery", "Custom Domains"]
    • Default connectors: ["Launch Proxy", "GitHub", "CI/CD Pipelines"]

來自 contentstack 的更多技能

brand-kit-assistant
contentstack
為使用者提供 Contentstack Brand Kit 概念、設定、治理及符合品牌形象的 AI 生成建議。將 API 特定任務導向正確的 Brand Kit 功能或…
official
cms-assets
contentstack
為開發人員提供關於在 Contentstack 中組織、傳遞和轉換資產的建議,涵蓋資料夾結構、Image Delivery API 轉換、發佈…
official
cms-branches-aliases
contentstack
為開發人員提供使用 Contentstack 分支進行隔離內容開發,以及使用別名實現零停機內容部署的建議。涵蓋分支策略、…
official
cms-data-modeling-best-practices
contentstack
引導開發人員使用最簡單的可重複使用結構,在 Contentstack 中建立內容模型。此技能說明何時使用內容類型、參照、全域……
official
cms-entries
contentstack
為開發人員提供關於查詢、本地化、版本管理、發佈及結構化 Contentstack 條目的建議,以實現高效傳遞。重點在於 CDA 的使用、參考…
official
cms-environments-publishing
contentstack
為開發人員提供配置環境、發佈內容、使用傳遞和預覽令牌、利用同步 API 以及理解 CDN 和…的建議。
official
cms-live-preview-visual-builder-support-assistant
contentstack
診斷並引導 Contentstack Live Preview 與 Visual Builder 的實作。追蹤預覽上下文,識別中斷的合約,並建議…
official
cms-localization
contentstack
為開發人員提供 Contentstack 本地化建議:語言設定、回退鏈、本地化與非本地化條目、不可本地化欄位以及多語言環境…
official