|
| 1 | +# Deploy to Contentstack Launch with GitHub Actions using Launch API |
| 2 | + |
| 3 | +This repository shows how to deploy a Next.js app to **Contentstack Launch** using the [Launch Public API](https://www.contentstack.com/docs/developers/apis/launch-api) file upload with **GitHub Actions**. The workflow (`.github/workflows/deploy.yml`) runs on push to `main` and uses the deployment script `deploy-api.js`. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## What you need |
| 8 | + |
| 9 | +The Launch API supports [**M2M**, **OAuth**, or **Authtoken**](https://www.contentstack.com/docs/developers/apis/launch-api#authentication). This repo uses **M2M** (Client ID + Client Secret). |
| 10 | + |
| 11 | +| Variable | Description | |
| 12 | +|----------|-------------| |
| 13 | +| `CONTENTSTACK_CLIENT_ID` | M2M/OAuth app ID | |
| 14 | +| `CONTENTSTACK_CLIENT_SECRET` | M2M/OAuth app secret | |
| 15 | +| `CONTENTSTACK_REGION` | Region: <small>`AWS_NA`, `AWS_EU`, `AWS_AU`, `AZURE_NA`, `AZURE_EU`, `GCP_NA`, `GCP_EU`</small> | |
| 16 | +| `PROJECT_UID` | Launch project UID | |
| 17 | +| `ENVIRONMENT_UID` | Launch environment UID | |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Quick start |
| 22 | + |
| 23 | +1. Clone or copy this repo. |
| 24 | +2. Create an app with `launch:manage` or `launch.projects:write` scope (this repo uses M2M; OAuth/Authtoken are also supported by the API). |
| 25 | +3. Set the required variables as **GitHub Actions secrets**, or use `.env` for local runs. |
| 26 | +4. Push to `main` (or run `npm run deploy` locally). |
| 27 | + |
| 28 | +**Run locally:** Copy `.env.example` to `.env`, fill in values, then run `npm run deploy`. |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## GitHub Actions |
| 33 | + |
| 34 | +Workflow: `.github/workflows/deploy.yml` — on push to `main`: checkout → `npm install` → `node deploy-api.js`. |
| 35 | + |
| 36 | +**Secrets** (Settings → Secrets and variables → Actions): `CONTENTSTACK_CLIENT_ID`, `CONTENTSTACK_CLIENT_SECRET`, `CONTENTSTACK_REGION`, `PROJECT_UID`, `ENVIRONMENT_UID`. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## What gets included in the deployment zip |
| 41 | + |
| 42 | +The deploy script (`deploy-api.js`) zips only the files and folders listed in the **`essentialFiles`** array inside `createZipFile()`. There is no config file — the list is hardcoded. |
| 43 | + |
| 44 | +**Default list:** `package.json`, `package-lock.json`, `next.config.js`, `pages`, `public`, `app`, `functions` |
| 45 | + |
| 46 | +**To customize:** Edit `deploy-api.js` and change the `essentialFiles` array in `createZipFile()` so it matches your project (e.g. add `src`, `components`, or `lib`; remove `app` or `functions` if you don’t use them). Only entries in that array are included in the zip. |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## References |
| 51 | + |
| 52 | +- [Launch API – Authentication](https://www.contentstack.com/docs/developers/apis/launch-api#authentication) |
| 53 | +- [Contentstack OAuth](https://www.contentstack.com/docs/developers/developer-hub/contentstack-oauth) |
| 54 | +- [Contentstack Launch API](https://www.contentstack.com/docs/developers/apis/launch-api) |
0 commit comments