Get Previews for PRs from forks

Is there any way to get previews of PRs from fork if I am using cloudflare pages? Like the way vercel supports. Thank you !! #pages-help
14 Replies
Cyb3r-Jak3
Cyb3r-Jak39mo ago
Pretty sure it is not currently possible to.
CokaKoala
CokaKoala9mo ago
hey! if you're willing to work with GH actions, then I've forked the official pages-action for this exact purpose: https://github.com/AdrianGonz97/refined-cf-pages-action as well as added a couple of extra features, like deployment summaries (demoed here)
ai.alok
ai.alokOP9mo ago
Can I trust on third party github actions? Like for this I need to remove my official cloudflare github app. @CokaKoala Is there way I write my workflow for getting preview of PRs from fork repo? If you could tell me it would be great. Thank you : ) Is there any way to write my own workflow for this?
Cyb3r-Jak3
Cyb3r-Jak39mo ago
You can use CI with the direct upload feature to get this done yourself.
ai.alok
ai.alokOP9mo ago
but github secrets on not available on pull request
Cyb3r-Jak3
Cyb3r-Jak39mo ago
It is.
Cyb3r-Jak3
Cyb3r-Jak39mo ago
GitHub Security Lab
Keeping your GitHub Actions and workflows secure Part 1: Preventing...
In this article, we’ll discuss some common security malpractices for GitHub Actions and workflows, and how to best avoid them. Our examples are based on real-world GitHub workflow implementation vulnerabilities the GitHub Security Lab has reported to maintainers.
ai.alok
ai.alokOP9mo ago
Thank you, but pull_request_target.yml works only with respect to base branch then how I am going to get build file with respect to PR from fork? This look little promising...try working with this. If you have implemented preview things. Can u please share here? Thank you : )
Cyb3r-Jak3
Cyb3r-Jak39mo ago
I have not implemented it for myself. Just know it should work
Adi
Adi9mo ago
You can absolutely have pull requests make preview branches and comment that back to your PR. Here is how I did it in an existing repo (I've changed some naming up). A few things to note on this workflow - It's built for monorepos where you have multiple webapps (like turborepo) - When it runs on the main branch it will simply deploy all the pages projects - When it runs on a pull request trigger it will create preview deployments and comment those back onto the PR - The code is written in a way where you can easily add more webapps and add them to the preview comment
Adi
Adi9mo ago
Had to send it as a file, the message was too long
ai.alok
ai.alokOP9mo ago
Thank you Adi, can you please send me the repo you are using this? Is the previews for PRs from Fork Repo ? I really need to implement this in one of my repo. Thank you : ) Basically cloudflare support PR previews for the maintainer, collaborator and PR from the same repo but different branches. But it does not support PR previews for fork.
Adi
Adi9mo ago
Unfortunately it's a private repo, I can't share it I haven't tried for forks, but the steps above work for PRs in the main repo. I shared it to give an example of how one might do preview comments. For forks, you'll just have to work out how to grant access to secrets etc. Which I think are available if you approve workflows?
ai.alok
ai.alokOP9mo ago
Previews are builtin provided by cloudflare but only for the source branches not for the fork . Can you tell me which GitHub actions event should I use so that I can get access to secret in PR?

Did you find this page helpful?