Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to define if production or preview env #63

Open
giladv opened this issue Feb 22, 2023 · 13 comments
Open

No way to define if production or preview env #63

giladv opened this issue Feb 22, 2023 · 13 comments

Comments

@giladv
Copy link

giladv commented Feb 22, 2023

Hey,

So want to use CF pages on a monorepo which the new workingDirectory feature was designed for.
Problem is, to use with monorepos, project has to be defined as a "direct upload" project which doesn't has a production branch setting in it. The only way to do it is to allow this action to have a productionBranch setting which is missing.

Please advise.

@raiyansarker
Copy link

I am having the same issue. Every push or pr in any branch results in production deployment.

@ari-becker
Copy link

I had the same issue, the workaround is to invoke the API directly to patch the production_branch field to be the real production branch: https://developers.cloudflare.com/api/operations/pages-project-update-project

@aaronadamsCA
Copy link
Contributor

aaronadamsCA commented Mar 10, 2023

workingDirectory support was only released yesterday, so you should probably try again and see if you're still having this problem.

That said, the production branch name comes from the Cloudflare API, but I'm not sure the value can be changed from main. I believe that would be a dashboard gap, since that value should still be configurable for direct uploads.

@lostpebble
Copy link

We have multiple branches for multiple deployments and previews (our own version of a preview, that needs to be available directly at our subdomain)- but now anything we run that is not "master" branch (like PR actions etc.) are all being deployed as "preview" which is useless because now those deployments are not visible and live at our subdomain.

I've run into this kind of issue before. I think Cloudflare needs to have good defaults- but always give the option to make a deployment a "production" deployment... Why can't we just provide a flag "--production" or whatever.

@WalshyDev
Copy link
Member

WalshyDev commented Mar 17, 2023

I've run into this kind of issue before. I think Cloudflare needs to have good defaults- but always give the option to make a deployment a "production" deployment... Why can't we just provide a flag "--production" or whatever.

You... can. Just specify the branch as your production branch (--branch=<production-branch> in wrangler)
With this action, it's just

branch: <production-branch>

@lostpebble
Copy link

lostpebble commented Mar 17, 2023

Would be amazing if there was more documentation about this!

EDIT: Nevermind, I see it in the Readme. My mistake, but would be nice to just have an "options" area that shows all the options available.

@lostpebble
Copy link

image

Still is set as preview... This DX is really not so great. Now I have to guess what the actual "production" branch is- probably "main". I can't set this anywhere because the page project is a "direct upload" one, because we are using Github Actions.

The idea of a single "production" branch doesn't really work in a lot of cases either.

@WalshyDev
Copy link
Member

It'll either be "main" or "production" probably

The idea of a single "production" branch doesn't really work in a lot of cases either.

You have to remember we use to have only Git, not Direct Uploads. Specifying a --production is the same as a --branch=<prod-branch>

We could technically add an option to just do that but not sure I like that personally (feel free to put up an issue on the Wrangler docs though)

@lostpebble
Copy link

lostpebble commented Mar 17, 2023

We've managed to win with "main". Its just a lil weird because we don't even have a "main" branch (still using "master" on this repo). So overall, just opening the door for confusion.

I understand that Git was how things originally worked- but surely when it comes to direct uploads, sometimes these won't even be coming from a git repo- an option just to say --production seems like a no-brainer to me. Should have been there from the get-go.

@aaronadamsCA
Copy link
Contributor

@WalshyDev I think the CF dash should be updated to let folks change the production branch when the project is set to manual upload. Right now it basically hard-codes to main, which is not always going to be correct.

IMHO the rest of the functionality is fine here and the only real problem is in the CF dash.

@WalshyDev
Copy link
Member

I think the CF dash should be updated to let folks change the production branch when the project is set to manual upload

Yes, it needs to have this indeed. Unfortunately, it's been one of those things that just slipped into the backlog and have not been prioritized.
It's on my todo list but things keep taking higher priority.

@nickdandakis
Copy link

For anyone else that's bumping into this and wants a quick overview on how to fix up their project's production branch as of right now...

There's two steps required here:

  1. Ensure branch: YOUR_PRODUCTION_BRANCH_HERE is set in your Action's yaml file
  2. Update your Cloudflare Pages project's production_branch. Here's a helpful cURL (h/t @ari-becker)
curl --request PATCH \
  --url https://api.cloudflare.com/client/v4/accounts/YOUR_ACCOUNT_IDENTIFIER_HERE/pages/projects/YOUR_PROJECT_IDENTIFIER_HERE \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_TOKEN_HERE' \
  --data '{ "production_branch": "YOUR_PRODUCTION_BRANCH_HERE" }'

Replace YOUR_ACCOUNT_IDENTIFIER_HERE, YOUR_PROJECT_IDENTIFIER_HERE, YOUR_API_TOKEN_HERE with your own. All of which can be found or created in your Cloudflare dashboard. Note that YOUR_API_TOKEN_HERE needs the Cloudflare Pages:Edit permission.

Replace PRODUCTION_BRANCH_HERE with your repo's branch (e.g. for me it's trunk). This should match the branch: PRODUCTION_BRANCH_HERE set in your Action yaml.

🚀

@Keavon
Copy link

Keavon commented Aug 16, 2023

Hints for the above:

YOUR_ACCOUNT_IDENTIFIER_HERE

  1. Go to your dashboard, copy the hash from the URL immediately after the hostname

YOUR_PROJECT_IDENTIFIER_HERE

  1. Use the name of your CF Pages site as it appears in the dashboard

YOUR_API_TOKEN_HERE

  1. Go to https://dash.cloudflare.com/profile/api-tokens
  2. Click "Create Token"
  3. At the bottom under "Custom token" beside "Create Custom Token" click "Get Started"
  4. Give the token a name, it doesn't matter what
  5. Under "Permissions", select "Account" from the first dropdown, "Cloudflare Pages" from the second, and "Edit" from the third
  6. Leave the rest blank and click "Continue to summary" then "Create token"
  7. Click "Copy"

YOUR_PRODUCTION_BRANCH_HERE

  1. Probably master or whatever your actual Git production branch is named instead of the default of main which has no UI to be changed

After making those 4 changes, copy and paste it into a Linux terminal (not command prompt, for some reason the API returns an error using the built-in Windows bash). It might be easier/more reliable to remove the \ after each line and make it all one line. As a one-liner for convenience:

curl --request PATCH --url https://api.cloudflare.com/client/v4/accounts/YOUR_ACCOUNT_IDENTIFIER_HERE/pages/projects/YOUR_PROJECT_IDENTIFIER_HERE --header 'Content-Type: application/json' --header 'Authorization: Bearer YOUR_API_TOKEN_HERE' --data '{ "production_branch": "YOUR_PRODUCTION_BRANCH_HERE" }'

Important: I found that using the bash built into Windows didn't work in command prompt. I kept getting errors from the API. Using the exact same command from WSL bash did work, though. Not sure why, but hopefully that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants