Skip to content

Commit d8cdab9

Browse files
committed
Deploy to Contentstack Launch with GitHub Actions using Launch API
0 parents  commit d8cdab9

10 files changed

Lines changed: 2110 additions & 0 deletions

File tree

‎.env.example‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copy this file to .env and fill in your values:
2+
# cp .env.example .env
3+
4+
# Required: M2M app credentials (Developer Hub → Your App → Authentication → M2M)
5+
CONTENTSTACK_CLIENT_ID="your_client_id"
6+
CONTENTSTACK_CLIENT_SECRET="your_client_secret"
7+
8+
# Region: AWS_NA, AWS_EU, AWS_AU, AZURE_NA, AZURE_EU, GCP_NA, GCP_EU
9+
CONTENTSTACK_REGION="AWS_NA"
10+
11+
# Required: Launch project and environment
12+
ENVIRONMENT_UID="your_environment_uid"

‎.github/workflows/deploy.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Deploy to Contentstack Launch
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '22'
20+
21+
- name: Install deployment script dependencies
22+
run: npm install form-data archiver dotenv
23+
24+
- name: Deploy to Contentstack Launch
25+
env:
26+
CONTENTSTACK_CLIENT_ID: ${{ secrets.CONTENTSTACK_CLIENT_ID }}
27+
CONTENTSTACK_CLIENT_SECRET: ${{ secrets.CONTENTSTACK_CLIENT_SECRET }}
28+
CONTENTSTACK_REGION: ${{ secrets.CONTENTSTACK_REGION }}
29+
PROJECT_UID: ${{ secrets.PROJECT_UID }}
30+
ENVIRONMENT_UID: ${{ secrets.ENVIRONMENT_UID }}
31+
run: node deploy-api.js

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.env
3+
.env*.local
4+
.next/
5+
.DS_Store

‎README.md‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)