From d73fa42fd3f93134d2a593a3d7cbbd416f5b0f3e Mon Sep 17 00:00:00 2001 From: Florent Benoit Date: Wed, 1 Jul 2026 22:43:32 +0200 Subject: [PATCH] feat: add PR website preview via Cloudflare Pages Add two workflows to enable website preview deployments for pull requests: - pr-check.yaml: builds the website on PRs and uploads the artifact - publish-website-pr-cloudflare.yaml: deploys the artifact to Cloudflare Pages Co-Authored-By: Claude Opus 4.6 Signed-off-by: Florent Benoit --- .github/workflows/pr-check.yaml | 66 +++++++++++++++++++ .../publish-website-pr-cloudflare.yaml | 56 ++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 .github/workflows/pr-check.yaml create mode 100644 .github/workflows/publish-website-pr-cloudflare.yaml diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml new file mode 100644 index 0000000..f481aa9 --- /dev/null +++ b/.github/workflows/pr-check.yaml @@ -0,0 +1,66 @@ +# +# Copyright (C) 2026 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +name: pr-check + +on: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + website-build: + if: ${{ !github.event.pull_request.draft }} + name: Build website + runs-on: ubuntu-24.04 + + steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - name: Setup Node + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 24 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Store pull request details for publish-cloudflare + run: | + echo "${{ github.event.number }}" > PR_NUMBER + echo "${{ github.event.pull_request.head.sha }}" > PR_SHA + + - name: Upload artifact website-content + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: website-content + path: | + build + PR_NUMBER + PR_SHA diff --git a/.github/workflows/publish-website-pr-cloudflare.yaml b/.github/workflows/publish-website-pr-cloudflare.yaml new file mode 100644 index 0000000..e267de0 --- /dev/null +++ b/.github/workflows/publish-website-pr-cloudflare.yaml @@ -0,0 +1,56 @@ +# +# Copyright (C) 2026 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +name: Publish pull request content on cloudflare pages + +on: + workflow_run: + workflows: + - 'pr-check' + types: + - completed + +permissions: + actions: read + contents: read + deployments: write + +jobs: + publish: + name: Publish website preview on Cloudflare Pages + runs-on: ubuntu-24.04 + if: ${{ github.event.workflow_run.conclusion == 'success' }} + + steps: + - name: Download website content artifact + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + run-id: ${{ github.event.workflow_run.id }} + name: website-content + path: content + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy to Cloudflare Pages + uses: AdrianGonz97/refined-cf-pages-action@45ea15c1c69a7bce8ffbb79ba114daa2b52f0cff # v1.3.0 + with: + apiToken: ${{ secrets.CLOUDFLARE_AUTH_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + githubToken: ${{ secrets.GITHUB_TOKEN }} + projectName: kaiden-website-pr + deploymentName: Website Preview + comment: false + directory: content/build