diff --git a/.github/workflows/storybook-deploy-cp.yml b/.github/workflows/storybook-deploy-cp.yml new file mode 100644 index 00000000000..fc0462cd170 --- /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-ui-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, + }); + }