Deploying Deno project to Cloudflare Pages using GitHub Actions

Created on February 10, 2025 by Dawid Wasowski

Cloudflare Pages is one of the best options for hosting static websites, primarily due to its robust Content Delivery Network (CDN) and cost-effective pricing, including a generous free tier. The platform delivers excellent performance and global reach. For many projects, integrating Cloudflare Pages with a GitHub repository allows for straightforward automated deployments: changes pushed to the repository trigger automatic builds and deployments.

However, Wrangler, Cloudflare’s official command-line interface (CLI), currently supports only NPM, PNPM, Yarn, and Bun. Making it harder to deploy Deno projects to Cloudflare Pages.

The solution might involve using Node’s package.json to enable Wrangler to build your project. However, if you prefer a pure Deno project, you can use GitHub Actions for automated deployments. This article demonstrates how to do that.

Disable automatic deployments

I assume you already have a GitHub repository connected to Cloudflare Workers & Pages.
If not, you can follow this guide.

Get your Account ID

Generate API Token

Set Account ID and API Token as Secrets in repository

GitHub Actions Workflow file

You need to create a workflow file in your repository.

.github/workflows/deploy.yml

The following code will install Deno, install dependencies, build your project, and deploy it to Cloudflare Pages.

name: Deploy to Cloudflare Pages

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Build and Deploy
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Deno
        uses: denoland/setup-deno@v2
        with:
          deno-version: v2.x

      - name: Install Dependencies
        run: deno install --allow-scripts

      - name: Build Website
        run: deno task build

      - name: Install Wrangler
        run: deno install --global --allow-scripts npm:wrangler@latest

      - name: Deploy Website to Cloudflare
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy ./dist --project-name=awesome --branch=main --commit-dirty=true 

About the workflow file

That’s it!

Hope this article was helpful for you.
Good luck with your awesome projects!