Skip to content

remarkablemark/cloudflare-pages-action-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare-pages-action-demo

publish-to-cloudflare-pages

Cloudflare Pages GitHub Action demo.

Setup

Login to Cloudflare.

API Token

Go to My Profile > API Tokens > Create Token > enter Token name:

Cloudflare Pages

Add Permissions:

Type Service Permission
Account Cloudflare Pages Edit

Click Continue to summary > Create Token.

Copy the API token and save it in your repository's Settings > Secrets and variables > Actions > New repository secret:

CLOUDFLARE_PAGES_API_TOKEN

Repeat the step above for Dependabot.

Account ID

Copy your Cloudflare's account ID by going to the dashboard, navigating to Workers, or copying it from the browser URL:

https://dash.cloudflare.com/abcdef1234567890abcdef1234567890

Your account ID is a hexadecimal string that looks like abcdef1234567890abcdef1234567890

Create a New repository secret like the previous step:

CLOUDFLARE_ACCOUNT_ID

Pages

Go to Pages > Create a project > Direct Upload and name the project after your repository.

You can also use Connect to Git but you'll need to disable automatic deployments on production and preview branches.

Action

Create the workflow file:

touch .github/workflows/publish-to-cloudflare-pages.yml

Update the workflow:

name: publish-to-cloudflare-pages
on: push

permissions:
  contents: read
  deployments: write

jobs:
  publish-to-cloudflare-pages:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Publish to Cloudflare Pages
        uses: cloudflare/pages-action@v1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          projectName: ${{ github.event.repository.name }}
          directory: public
          gitHubToken: ${{ github.token }}

Make sure to update the asset directory for your project.

Save the action and it should deploy your project to Cloudflare Pages! 🚀

License

MIT