cloudflare / wrangler-action

🧙‍♀️ easily deploy cloudflare workers applications using wrangler and github actions
Apache License 2.0
1.27k stars 160 forks source link

Cannot get CLOUDFLARE_API_TOKEN in Actions #246

Closed wavy-cat closed 7 months ago

wavy-cat commented 8 months ago

Authorization error on v3.4.1:

  ✘ [ERROR] In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.

Workflow:

      - name: Build & Deploy Worker
        uses: cloudflare/wrangler-action@v3.4.1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy ./generate/web --project-name=assets
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

The token was created with all the necessary permissions and was added to Secrets.

aialok commented 7 months ago

I am also getting the same error. https://github.com/json-schema-org/landscape/actions/runs/8840354725/job/24275518908#step:8:25

aialok commented 7 months ago

@wavy-cat If you are running this on pull request from forked branch then this will through error as deployment and secrets are only valid in main repo and on push.

https://github.com/actions/runner/discussions/3039 https://stackoverflow.com/questions/73866908/github-actions-main-repository-secret-not-picked-up-from-pull-request-build

wavy-cat commented 7 months ago

The issue was that the token had been added to the Environment secrets instead of the Repository secrets. Due to this oversight, the deployment did not function as intended. It was a mistake on my part, I'm sorry.