workers-sdk
workers-sdk copied to clipboard
🚀 Feature Request: better Pages support
Describe the solution
Context
I went to use the wrangler-action to replace the CF Pages build tooling because my pages project generates documentation from my code, and installing all the deps of my code is always going to suck without caching (10+ minute builds downloading and installing mindless python packages), and I highly doubt the CF Pages build infrastructure will ever have smart ideas around caching because caching is miserable.
So anyways, now I want this action to do PR commenting like the CF Pages app does, but this action doesn't do that yet, and maybe it never will, and that's chill, I'm just here because I want to articulate that the wrangler CLI probably needs to do a better job of being CI friendly.
Problem
So let's look at this Github Action Workflow:
on:
push:
branches: main
pull_request:
jobs:
build-lint-publish:
name: Build, Lint, and Publish
runs-on: ubuntu-latest
steps:
- name: Upload to cloudflare
id: wrangler
uses: cloudflare/[email protected]
with:
postCommands: |
echo CF_URL=$(grep -o 'https*://[^"]*' ./wrangler.stdout) >> $GITHUB_ENV
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
command: pages publish --project-name=project dir | tee wrangler.stdout
- name: CF Pages Summary
run: |
echo "## Deploying with [](https://pages.dev)" >> $GITHUB_STEP_SUMMARY
echo "<strong>Preview URL:</strong> <a href='${{ env.CF_URL }}'>${{ env.CF_URL }}</a>" >> $GITHUB_STEP_SUMMARY
- name: Comment PR
if: ${{ github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@v1
with:
comment_includes: '## Deploying with [![Cloudflare Pages]'
message: |
## Deploying with [](https://pages.dev)
<table><tr><td><strong>Latest commit:</strong> </td><td>
<code>${{ github.sha }}</code>
</td></tr>
<tr><td><strong>Preview URL:</strong></td><td>
<a href='${{ env.CF_URL }}'>${{ env.CF_URL }}</a>
</td></tr>
</table>
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Let's take apart the kind of hacky pieces.
| tee wrangler.stdout
Currently the wrangler pages publish command doesn't have a way to output machine parsable data, so instead I just tee this to a file.
echo CF_URL=$(grep -o 'https*://[^"]*' ./wrangler.stdout) >> $GITHUB_ENV
What's an example of machine parsable data? Well the deployment URL and the build log URL would be nice.
Extra credit: get wrangler pages deployment list --project-name project to dump something you can actually grep, the table formatter in Ink is very not unix friendly.
comment_includes: '## Deploying with [![Cloudflare Pages]'
If you're going to post PR comments, it'd be nice to allow upserting.
message
It could be rad if the CLI had some prebuilt CI markdown formats that might be easy to use inside/outside of the GH Actions, then y'alls branding would be consistent across platforms.
Also, feel free to immediately close this as I recognize it spans across multiple repos. 🤞 a product manager reads this.
@flyinprogrammer did you manage to create a deployment where the Environment would be set to Production? I always get Preview and can't find any way to update it via the wrangler cli. cc @petebacondarwin
@flyinprogrammer did you manage to create a deployment where the
Environmentwould be set toProduction? I always getPreviewand can't find any way to update it via thewranglercli. cc @petebacondarwin
Answered in https://github.com/cloudflare/wrangler2/issues/1050#issuecomment-1129945293 by @GregBrimble. Set --branch=foo where foo is the name of your production branch. By default the production branch is called production. So, use
wrangler pages publish $DIR --project_name $PROJECT_NAME --branch production
Tracking in https://github.com/cloudflare/pages-action/issues/16
The Wrangler action is unlikely to get this, we would suggest (and be open to PRs adding it) to use the pages-action instead.