This example demonstrates how to deploy a file upload project to Contentstack Launch whenever there is a push to the main branch — using GitHub Actions and the Contentstack CLI.
Before setting up this CI/CD workflow:
- Your project should already be deployed once manually using Contentstack UI.
- You must have a valid
.cs-launch.jsonconfiguration file in your project using cli, or you can refer to cs-launch.json in this repo, and replace the IDs as per your launch project. - Your GitHub repository must include:
- Project source code
- A valid
package.jsonwith abuildscript (npm run build) .cs-launch.json(in the root or a custom path)- The
otplibpackage installed (used to generate TOTP tokens for two-factor authentication):npm install otplib
To securely authenticate during deployment, add these secrets to your GitHub repository:
- Navigate to:
GitHub > Your Repo > Settings > Secrets and variables > Actions - Click "New repository secret" and add the following:
| Secret Name | Value |
|---|---|
CSDX_EMAIL |
Your Contentstack account email |
CSDX_PASSWORD |
Your Contentstack account password |
CSDX_TOTP_SECRET |
Your TOTP secret key for two-factor authentication |
To use TOTP-based authentication in your CI/CD pipeline:
- Enable Multi-Factor Authentication (MFA) on your Contentstack account via the website.
- Log out of your account.
- When logging in again, enter your email and password.
- You'll be shown a QR code and a secret key.
- Save the secret key — this is your
CSDX_TOTP_SECRET. - Use this secret to generate TOTP codes programmatically.
Do not share this key. Store it securely as a GitHub secret.
Every time you push changes to the main branch:
- The workflow installs project dependencies.
- It builds your project using
npm run build. - It logs the most recent commit ID and message for traceability.
- Then, it authenticates using Contentstack CLI.
- Finally, it triggers a re-deployment to your existing Contentstack Launch project, uploading any changed files.
- Make sure you manually deploy once using
csdx launchto set up your project on Launch before relying on this workflow. - Your
.cs-launch.jsonfile must exist in the root (or use--configto point to it). - Make sure to store all required secrets (
CSDX_EMAIL,CSDX_PASSWORD,CSDX_TOTP_SECRET) in GitHub.
After this one-time setup, every push to main will update your Launch project — no extra steps needed.