From 22c03f2c8d99f70be2d273073797757a6de9a0c8 Mon Sep 17 00:00:00 2001 From: razorblade23 <81590614+razorblade23@users.noreply.github.com> Date: Sat, 5 Sep 2026 14:57:28 +0200 Subject: [PATCH 1/3] Added workflow to deploy a preview page and auto delete on PR closing --- .github/workflows/preview-changes.yml | 101 ++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/preview-changes.yml diff --git a/.github/workflows/preview-changes.yml b/.github/workflows/preview-changes.yml new file mode 100644 index 0000000..215ae8a --- /dev/null +++ b/.github/workflows/preview-changes.yml @@ -0,0 +1,101 @@ +name: Preview Pages Management + +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened, closed] + paths-ignore: + - 'bot_challenges/**' + +jobs: + # DEPLOY PREVIEW: Triggered when PRs are opened, updated, or reopened + deploy-preview: + name: Deploy Preview to Cloudflare Pages + if: github.event.action != 'closed' + runs-on: ubuntu-latest + permissions: + pull-requests: write # Required to post/update the preview link comment + contents: read + steps: + - name: Checkout Curriculum (PR Code) + uses: actions/checkout@v4 + with: + path: Curriculum + + - name: Checkout Engine + uses: actions/checkout@v4 + with: + repository: ThePythonLedger/Docusaurus-engine + path: engine + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + cache-dependency-path: engine/package-lock.json + + - name: Build Site Assets + run: | + cd engine + npm ci + npm run build + + - name: Deploy to Cloudflare Pages + uses: cloudflare/wrangler-action@v4 + id: cloudflare_deploy + with: + apiToken: ${{ secrets.CF_API_TOKEN }} + accountId: ${{ secrets.CF_ACCOUNT_ID }} + command: pages deploy engine/build --project-name=python-ledger-preview --branch=pr-${{ github.event.number }} + + - name: Comment Preview Link on PR + uses: actions/github-script@v7 + with: + script: | + const prNumber = context.issue.number; + const previewUrl = `https://pr-${prNumber}.python-ledger-preview.pages.dev`; + const message = `🚀 **Preview Deployment Ready!**\n\nContributors can view changes live at:\n${previewUrl}`; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + const botComment = comments.find(c => c.body.includes('Preview Deployment Ready!')); + + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: message, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: message, + }); + } + + # CLEANUP PREVIEW: Triggered when the PR is closed or merged + cleanup-preview: + name: Delete Cloudflare Pages Preview + if: github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Delete Cloudflare Pages Branch + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} + run: | + BRANCH_NAME="pr-${{ github.event.number }}" + echo "Deleting Cloudflare Pages branch: $BRANCH_NAME" + npx wrangler pages project delete-branch python-ledger-preview --branch="$BRANCH_NAME" --yes From 58cbaf43d9d38ff4f1dbb954e5313f4ff7f40a9b Mon Sep 17 00:00:00 2001 From: razorblade23 <81590614+razorblade23@users.noreply.github.com> Date: Sat, 5 Sep 2026 15:28:57 +0200 Subject: [PATCH 2/3] Update to workflow to use env variables --- .github/workflows/preview-changes.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview-changes.yml b/.github/workflows/preview-changes.yml index 215ae8a..03748d9 100644 --- a/.github/workflows/preview-changes.yml +++ b/.github/workflows/preview-changes.yml @@ -36,6 +36,9 @@ jobs: cache-dependency-path: engine/package-lock.json - name: Build Site Assets + env: + DOCUSAURUS_URL: https://pr-${{ github.event.number }}.python-ledger-preview.pages.dev + DOCUSAURUS_BASE_URL: / run: | cd engine npm ci @@ -45,8 +48,8 @@ jobs: uses: cloudflare/wrangler-action@v4 id: cloudflare_deploy with: - apiToken: ${{ secrets.CF_API_TOKEN }} - accountId: ${{ secrets.CF_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy engine/build --project-name=python-ledger-preview --branch=pr-${{ github.event.number }} - name: Comment Preview Link on PR @@ -93,8 +96,8 @@ jobs: - name: Delete Cloudflare Pages Branch env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} run: | BRANCH_NAME="pr-${{ github.event.number }}" echo "Deleting Cloudflare Pages branch: $BRANCH_NAME" From 6fcb5c7ee2a445e46718803e842a99b7bcda5eac Mon Sep 17 00:00:00 2001 From: razorblade23 <81590614+razorblade23@users.noreply.github.com> Date: Sat, 5 Sep 2026 15:32:16 +0200 Subject: [PATCH 3/3] Fixed ENV variables in CI --- .github/workflows/preview-changes.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview-changes.yml b/.github/workflows/preview-changes.yml index 03748d9..d1c1607 100644 --- a/.github/workflows/preview-changes.yml +++ b/.github/workflows/preview-changes.yml @@ -48,8 +48,8 @@ jobs: uses: cloudflare/wrangler-action@v4 id: cloudflare_deploy with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CF_API_TOKEN }} + accountId: ${{ secrets.CF_ACCOUNT_ID }} command: pages deploy engine/build --project-name=python-ledger-preview --branch=pr-${{ github.event.number }} - name: Comment Preview Link on PR @@ -96,8 +96,8 @@ jobs: - name: Delete Cloudflare Pages Branch env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} run: | BRANCH_NAME="pr-${{ github.event.number }}" echo "Deleting Cloudflare Pages branch: $BRANCH_NAME"