Go to file
Daniel Walsh c4f0d2e08d
Merge pull request #19 from spencerreeves/main
Add support for specifying branch
2022-07-26 21:43:33 +01:00
.github Add Pages team as codeowners 2022-05-19 13:48:42 +01:00
.husky Initial commit 2022-05-10 11:10:48 +01:00
example Initial commit 2022-05-10 11:10:48 +01:00
src Add support for specifying branch (#1) 2022-06-29 18:31:02 -07:00
.gitignore Initial commit 2022-05-10 11:10:48 +01:00
action.yml Add support for specifying branch (#1) 2022-06-29 18:31:02 -07:00
index.js Add support for specifying branch (#1) 2022-06-29 18:31:02 -07:00
LICENSE Initial commit 2022-05-10 11:10:48 +01:00
package-lock.json Initial commit 2022-05-10 11:10:48 +01:00
package.json Initial commit 2022-05-10 11:10:48 +01:00
README.md Add support for specifying branch (#1) 2022-06-29 18:31:02 -07:00

Cloudflare Pages GitHub Action

GitHub Action for creating Cloudflare Pages deployments, using the new Direct Upload feature and Wrangler integration.

Usage

  1. Create an API token in the Cloudflare dashboard with the "Cloudflare Pages — Edit" permission.

  2. Add that API token as a secret to your GitHub repository, CLOUDFLARE_API_TOKEN.

  3. Create a .github/workflows/publish.yml file in your repository:

    on: [push]
    
    jobs:
      publish:
        runs-on: ubuntu-latest
        permissions:
          contents: read
          deployments: write
        name: Publish to Cloudflare Pages
        steps:
          - name: Checkout
            uses: actions/checkout@v3
    
          # Run a build step here if your project requires
    
          - name: Publish to Cloudflare Pages
            uses: cloudflare/pages-action@1
            with:
              apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
              accountId: YOUR_ACCOUNT_ID
              projectName: YOUR_PROJECT_NAME
              directory: YOUR_ASSET_DIRECTORY
              gitHubToken: ${{ secrets.GITHUB_TOKEN }}
    
  4. Replace YOUR_ACCOUNT_ID, YOUR_PROJECT_NAME and YOUR_ASSET_DIRECTORY with the appropriate values to your Pages project.

Get account ID

To find your account ID, log in to the Cloudflare dashboard > select your zone in Account Home > find your account ID in Overview under API on the right-side menu. If you have not added a zone, add one by selecting Add site . You can purchase a domain from Cloudflares registrar.

If you do not have a zone registered to your account, you can also get your account ID from the pages.dev URL. E.g: https://dash.cloudflare.com/<ACCOUNT_ID>/pages

Generate an API Token

To generate an API token:

  1. Log in to the Cloudflare dashboard.
  2. Select My Profile from the dropdown menu of your user icon on the top right of your dashboard.
  3. Select API Tokens > Create Token.
  4. Under Custom Token, select Get started.
  5. Name your API Token in the Token name field.
  6. Under Permissions, select Account, Cloudflare Pages and Edit:
  7. Select Continue to summary > Create Token.

More information can be found on our guide for making Direct Upload deployments with continous integration.

Specifying a branch

The branch name is used by Cloudflare Pages to determine if the deployment is production or preview. Read more about git branch build controls.

If you are in a Git workspace, Wrangler will automatically pull the branch information for you. You can override this manually by adding the argument branch: YOUR_BRANCH_NAME.