cloudflare / wrangler-action

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

How can you set worker secret for a specific environment? #251

Closed tien closed 5 days ago

tien commented 7 months ago
- uses: cloudflare/wrangler-action@v3
  with:
    apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    command: deploy --env production
    secrets: |
      SUPER_SECRET
  env:
    SUPER_SECRET: ${{ secrets.SUPER_SECRET }}

Assuming the worker name is my-worker doing the above would create 2 workers: my-worker & my-worker-production with the secrets only set for my-worker.

renzor-fist commented 7 months ago

+1, encountering the same issue. Using --env production deploys two workers (worker and worker-production and sets secrets on worker instead of worker-production.

tien commented 7 months ago

From looking at the source code, I found out that there's actually an environment parameter that you can pass to the action. This needs to be documented.

renzor-fist commented 7 months ago

Thanks @tien can you provide an example?

renzor-fist commented 7 months ago

I see what you are referring to, thank you.

https://github.com/cloudflare/wrangler-action/blob/main/src/index.ts#L28

Codex- commented 2 months ago

From looking at the source code, I found out that there's actually an environment parameter that you can pass to the action. This needs to be documented.

This saved me a lot of pain, thank you

Alexkuva commented 2 weeks ago

FYI if someone if looking for the exact match:

- uses: cloudflare/wrangler-action@v3
  with:
    apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    command: deploy --env production
    secrets: |
      SUPER_SECRET
    environment: production
  env:
    SUPER_SECRET: ${{ secrets.SUPER_SECRET }}
courtney-sims commented 5 days ago

Thanks for bringing this up! The docs have been updated.

https://github.com/cloudflare/wrangler-action/pull/324