cloudflare / pages-action

MIT License
473 stars 97 forks source link

Deploying to preview environment #7

Closed zmilonas closed 2 years ago

zmilonas commented 2 years ago

Hey, i've read through the documentation and source code and it's not clear is it possible to use this action to deploy to preview environment for example for specific pull requests?

It seems to me that it should then require --branch in https://github.com/cloudflare/pages-action/blob/main/src/index.ts#L67 but I am not sure.

If that functionality is not supported I would be happy to contribute with some guidance.

GregBrimble commented 2 years ago

wrangler (and this action) automatically picks up the branch for a git workspace. If you need to override the branch that you're publishing to, you can indeed use the --branch CLI arg on wrangler. We don't currently have any plans to expose that option in this Action, but feel free to call wrangler yourself in Actions.

zmilonas commented 2 years ago

Ah ok, all clear now, thanks.

lxxself commented 2 years ago

What about the uploaded directly? What I upload directly is the production environment, and the default for action deployment is the preview environment. Can I specify the environment when using action?

image
dhess commented 2 years ago

wrangler (and this action) automatically picks up the branch for a git workspace. If you need to override the branch that you're publishing to, you can indeed use the --branch CLI arg on wrangler. We don't currently have any plans to expose that option in this Action, but feel free to call wrangler yourself in Actions.

Sorry, I'm confused. I'm testing this Action in a new workflow with 2 separate jobs where, in the first job, I checkout the repo using actions/checkout@v3 (with no additional options), build the site, and output the static content to an out directory. At the end of that job I upload the out directory as an artifact. In the 2nd job, I download the artifact, obtain secrets, and run cloudflare/pages-action@v1.

When this workflow is run on a PR, the workflow's deployment on the PR branch shows in my page's Deployments as "Production" on the main branch, and the site's production pages.dev domain is updated to point to the PR's deployment. This obviously shouldn't happen on a PR deployment and I assume I'm missing something, but it's not clear what.

[edit: I merged the two jobs into a single job (skipping the artifact upload/download, of course) and now the PR is deploying a "Preview" deployment as expected.]