From f0121831f6fbb94b937e0fd6dfdf207592eb5385 Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Mon, 6 Jul 2026 10:06:52 -0500 Subject: [PATCH 1/2] Add Cloudflare Pages deploy workflows for Storybook Deploys both the @craftcms/cp Storybook (packages/craftcms-cp) and the resources/js Storybook to separate Cloudflare Pages projects, with PR preview URLs commented on each pull request and production deploys on push to 6.x. Co-Authored-By: Claude Sonnet 5 --- .github/workflows/storybook-deploy-cp.yml | 94 ++++++++++++++ .../workflows/storybook-deploy-resources.yml | 119 ++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 .github/workflows/storybook-deploy-cp.yml create mode 100644 .github/workflows/storybook-deploy-resources.yml diff --git a/.github/workflows/storybook-deploy-cp.yml b/.github/workflows/storybook-deploy-cp.yml new file mode 100644 index 00000000000..c0d828e26cc --- /dev/null +++ b/.github/workflows/storybook-deploy-cp.yml @@ -0,0 +1,94 @@ +name: 'Deploy / Storybook (craftcms-cp)' +on: + workflow_dispatch: + push: + branches: + - 6.x + paths: + - 'packages/craftcms-cp/**' + pull_request: + paths: + - 'packages/craftcms-cp/**' + +concurrency: + group: storybook-deploy-cp-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + NODE_VERSION: '22' + +permissions: + contents: read + +jobs: + deploy: + name: 'Build + Deploy' + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - name: Install npm dependencies + run: npm ci + env: + CRAFT_FONTAWESOME_TOKEN: ${{ secrets.CRAFT_FONTAWESOME_TOKEN }} + + - name: Build Storybook + run: npm run build:storybook --workspace=@craftcms/cp + + - name: Determine deploy branch + id: branch + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + echo "value=pr-${{ github.event.number }}" >> "$GITHUB_OUTPUT" + else + echo "value=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" + fi + + - name: Deploy to Cloudflare Pages + id: deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy packages/craftcms-cp/storybook-static --project-name=craftcms-cp-storybook --branch=${{ steps.branch.outputs.value }} + + - name: Comment preview URL on PR + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + const url = `${{ steps.deploy.outputs.deployment-url }}`; + const marker = ''; + const body = `${marker}\n**@craftcms/cp Storybook preview:** ${url}`; + const {data: comments} = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + const existing = comments.find((c) => c.body.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body, + }); + } diff --git a/.github/workflows/storybook-deploy-resources.yml b/.github/workflows/storybook-deploy-resources.yml new file mode 100644 index 00000000000..5cf4a24e940 --- /dev/null +++ b/.github/workflows/storybook-deploy-resources.yml @@ -0,0 +1,119 @@ +name: 'Deploy / Storybook (resources)' +on: + workflow_dispatch: + push: + branches: + - 6.x + paths: + - 'resources/js/**' + - 'packages/craftcms-cp/src/**' + - 'src/**/*.php' + pull_request: + paths: + - 'resources/js/**' + - 'packages/craftcms-cp/src/**' + - 'src/**/*.php' + +concurrency: + group: storybook-deploy-resources-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + NODE_VERSION: '22' + PHP_VERSION: '8.5' + +permissions: + contents: read + +jobs: + deploy: + name: 'Build + Deploy' + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.PHP_VERSION }} + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - name: Install Composer dependencies + run: composer install --no-interaction --no-progress + + - name: Install npm dependencies + run: npm ci + env: + CRAFT_FONTAWESOME_TOKEN: ${{ secrets.CRAFT_FONTAWESOME_TOKEN }} + + - name: Build @craftcms/garnish + run: npm run build:garnish + + - name: Build @craftcms/cp + run: npm run build:cp + + - name: Generate TypeScript types + run: npm run generate:types + + - name: Generate Wayfinder routes + run: npm run generate:wayfinder + + - name: Build Storybook + run: npm run build:storybook + + - name: Determine deploy branch + id: branch + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + echo "value=pr-${{ github.event.number }}" >> "$GITHUB_OUTPUT" + else + echo "value=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" + fi + + - name: Deploy to Cloudflare Pages + id: deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy storybook-static --project-name=craftcms-storybook --branch=${{ steps.branch.outputs.value }} + + - name: Comment preview URL on PR + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + const url = `${{ steps.deploy.outputs.deployment-url }}`; + const marker = ''; + const body = `${marker}\n**resources/js Storybook preview:** ${url}`; + const {data: comments} = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + const existing = comments.find((c) => c.body.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body, + }); + } From a3b35e764158bef4dbab65951136d81d90e2e93e Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Mon, 6 Jul 2026 10:08:55 -0500 Subject: [PATCH 2/2] Rename cp Storybook Cloudflare Pages project to craftcms-ui-storybook Co-Authored-By: Claude Sonnet 5 --- .github/workflows/storybook-deploy-cp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/storybook-deploy-cp.yml b/.github/workflows/storybook-deploy-cp.yml index c0d828e26cc..fc0462cd170 100644 --- a/.github/workflows/storybook-deploy-cp.yml +++ b/.github/workflows/storybook-deploy-cp.yml @@ -61,7 +61,7 @@ jobs: with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy packages/craftcms-cp/storybook-static --project-name=craftcms-cp-storybook --branch=${{ steps.branch.outputs.value }} + command: pages deploy packages/craftcms-cp/storybook-static --project-name=craftcms-ui-storybook --branch=${{ steps.branch.outputs.value }} - name: Comment preview URL on PR if: github.event_name == 'pull_request'