GithubHelp home page GithubHelp logo

akarachen / cloudflare-pages-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudflare/pages-action

0.0 0.0 0.0 2.21 MB

Cloudflare Page Action, but with pnpm

License: MIT License

Shell 0.01% JavaScript 99.48% TypeScript 0.32% CSS 0.13% HTML 0.07%

cloudflare-pages-action's Introduction

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@v1
            with:
              apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
              accountId: YOUR_ACCOUNT_ID
              projectName: YOUR_PROJECT_NAME
              directory: YOUR_BUILD_OUTPUT_DIRECTORY
              # Optional: Enable this if you want to have GitHub Deployments triggered
              gitHubToken: ${{ secrets.GITHUB_TOKEN }}
              # Optional: Switch what branch you are publishing to.
              # By default this will be the branch which triggered this workflow
              branch: main
              # Optional: Change the working directory
              workingDirectory: my-site
              # Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
              wranglerVersion: "3"
  4. Replace YOUR_ACCOUNT_ID, YOUR_PROJECT_NAME and YOUR_BUILD_OUTPUT_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 Cloudflare’s 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.

Specifying a working directory

By default Wrangler will run in the root package directory. If your app lives in a monorepo and you want to run Wrangler from its directory, add workingDirectory: YOUR_PACKAGE_DIRECTORY.

Wrangler v3

You can use the newly released Wrangler v3 with the wranglerVersion property.

- name: Publish to Cloudflare Pages
  uses: cloudflare/pages-action@v1
  with:
    apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    accountId: YOUR_ACCOUNT_ID
    projectName: YOUR_PROJECT_NAME
    directory: YOUR_BUILD_OUTPUT_DIRECTORY
    # Enable Wrangler v3
    wranglerVersion: "3"

Outputs

Name Description
id The ID of the pages deployment
url The URL of the pages deployment
alias The alias if it exists otherwise the deployment URL
environment The environment that was deployed to

cloudflare-pages-action's People

Contributors

aaronadamsca avatar akarachen avatar cherry avatar davidshefcik avatar ekwuno avatar ghostdevv avatar gregbrimble avatar ianvs avatar iiroj avatar jasikpark avatar mitch528 avatar osumatrix avatar perrornet avatar sidharthachatterjee avatar spencerreeves avatar walshydev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.