workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🚀 Feature Request: better Pages support

Open flyinprogrammer opened this issue 3 years ago • 2 comments
trafficstars

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 [![Cloudflare](https://img.shields.io/badge/Cloudflare%20Pages-F38020?style=for-the-badge&logo=Cloudflare&logoColor=white)](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 [![Cloudflare Pages](https://img.shields.io/badge/Cloudflare%20Pages-F38020?style=for-the-badge&logo=Cloudflare&logoColor=white)](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 avatar Jun 06 '22 03:06 flyinprogrammer

@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

stream7 avatar Jun 07 '22 20:06 stream7

@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

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

rikhuijzer avatar Sep 02 '22 14:09 rikhuijzer

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.

WalshyDev avatar Oct 19 '22 15:10 WalshyDev