2025-07-21 by Remi Kristelijn
In this second post of our series, I'll show you how to set up automated deployment using GitHub Actions and Cloudflare Pages. This will enable continuous deployment whenever you push changes to your repository.
Automated deployment eliminates manual deployment steps, reduces human error, and ensures your blog is always up-to-date with your latest changes. With GitHub Actions, every push to your main branch will automatically trigger a build and deployment.
Before setting up automated deployment, you'll need:
npm run ci:buildout/ (leave empty)You'll need two pieces of information from Cloudflare:
In your GitHub repository:
CLOUDFLARE_ACCOUNT_ID: Your Cloudflare account IDCLOUDFLARE_API_TOKEN: Your Cloudflare API tokenCreate .github/workflows/deploy.yml:
1name: Deploy to Cloudflare Pages 2on: 3 push: 4 branches: [main] 5 pull_request: 6 branches: [main] 7 8jobs: 9 deploy: 10 runs-on: ubuntu-latest 11 steps: 12 - name: Checkout code 13 uses: actions/checkout@v4 14 15 - name: Setup Node.js 16 uses: actions/setup-node@v4 17 with: 18 node-version: '18' 19 cache: 'npm' 20 21 - name: Install dependencies 22 run: npm ci 23 24 - name: Build application 25 run: npm run build 26 27 - name: Deploy to Cloudflare Pages 28 uses: cloudflare/pages-action@v1 29 with: 30 apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} 31 accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} 32 projectName: next-blog 33 directory: out 34 gitHubToken: ${{ secrets.GITHUB_TOKEN }}
Ensure your next.config.ts is configured for static export:
1import type { NextConfig } from "next"; 2 3const nextConfig: NextConfig = { 4 output: "export", 5 trailingSlash: true, 6 images: { 7 unoptimized: true 8 } 9}; 10 11export default nextConfig;
In your Cloudflare Pages dashboard:
CLOUDFLARE_API_TOKEN: Authenticates with CloudflareCLOUDFLARE_ACCOUNT_ID: Identifies your accountGITHUB_TOKEN: Provided automatically by GitHubpackage-lock.json is committednpm ci instead of npm installYou can create different workflows for different environments:
1name: Deploy to Staging 2on: 3 push: 4 branches: [develop] 5 6jobs: 7 deploy-staging: 8 runs-on: ubuntu-latest 9 steps: 10 # Similar steps but deploy to staging environment
Only deploy on specific file changes:
1on: 2 push: 3 branches: [main] 4 paths: 5 - 'src/**' 6 - 'package.json' 7 - 'next.config.ts'
In the next post, we'll add MDX functionality to enable enhanced content creation with React components in markdown. This will make your blog more interactive and powerful.
Your Next.js blog now has automated deployment! Every push to your main branch will automatically deploy to Cloudflare Pages. In the next post, we'll enhance the content creation experience with MDX.