Skip to content

Commit 69385d3

Browse files
committed
Switch to CloudFlare pages Issue #144
1 parent 8c89a73 commit 69385d3

10 files changed

Lines changed: 277 additions & 81 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# .github/workflows/build-pr.yml
2+
name: 1 - Check and Build Web Page PR
3+
4+
on:
5+
pull_request:
6+
branches: [ "main" ]
7+
8+
jobs:
9+
linter:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
permissions:
13+
contents: read
14+
deployments: write
15+
pull-requests: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- uses: actions/setup-python@v6
21+
with:
22+
python-version: 3.12
23+
cache: pip
24+
25+
- name: pre-commit
26+
uses: pre-commit/action@v3.0.1
27+
with:
28+
extra_args: "--from-ref origin/main --to-ref HEAD"
29+
30+
- name: Install dependencies
31+
run: pip install -r requirements.txt
32+
- name: Build docs
33+
run: mkdocs build
34+
35+
- name: Upload Static Site Artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: preview-site
39+
path: site/
40+
41+
# NEW: Save the PR number to a file
42+
- name: Save PR number
43+
run: echo ${{ github.event.pull_request.number }} > pr-number.txt
44+
45+
# NEW: Upload the PR number as its own artifact
46+
- name: Upload PR Number Artifact
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: pr-metadata
50+
path: pr-number.txt

.github/workflows/clean-pr.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# .github/workflows/build-pr.yml
2+
name: 1 - Clean Web Page PR
3+
4+
on:
5+
pull_request:
6+
types: [closed]
7+
8+
jobs:
9+
clean:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
permissions:
13+
contents: read
14+
deployments: write
15+
pull-requests: write
16+
steps:
17+
18+
# NEW: Save the PR number to a file
19+
- name: Save PR number
20+
run: echo ${{ github.event.pull_request.number }} > pr-number.txt
21+
22+
# NEW: Upload the PR number as its own artifact
23+
- name: Upload PR Number Artifact
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: pr-metadata
27+
path: pr-number.txt

.github/workflows/delete-pr.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# .github/workflows/deploy-pr.yml
2+
name: 2 - Clean Web Page PR
3+
4+
on:
5+
workflow_run:
6+
workflows: ["1 - Clean Web Page PR"]
7+
types: [completed]
8+
9+
# CRITICAL: Grant the workflow permission to write comments on PRs
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
deploy-preview:
15+
if: github.event.workflow_run.conclusion == 'success'
16+
runs-on: ubuntu-latest
17+
environment: Cloudflare Pages
18+
permissions:
19+
# actions: read # Only required for private GitHub Repo
20+
contents: read
21+
deployments: write
22+
pull-requests: write
23+
24+
steps:
25+
# NEW: Download the PR metadata artifact
26+
- name: Download PR Number Artifact
27+
uses: actions/download-artifact@v4
28+
with:
29+
name: pr-metadata
30+
run-id: ${{ github.event.workflow_run.id }}
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Set PR Number Context
34+
run: |
35+
PR_NUMBER=$(cat pr-number.txt)
36+
# This syntax makes it available to subsequent steps as ${{ env.PR_NUMBER }}
37+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
38+
39+
- name: Delete Cloudflare Deployments
40+
env:
41+
# Pull your secrets securely
42+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
43+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
44+
PROJECT_NAME: "openshift-examples"
45+
PR_NUMBER: ${{ env.PR_NUMBER }}
46+
run: |
47+
echo "Cleaning up deployments for PR #$PR_NUMBER..."
48+
49+
# 1. Install the Cloudflare Wrangler CLI
50+
npm install -g wrangler
51+
52+
# 2. Fetch all project deployments as a JSON payload
53+
wrangler pages deployment list --project-name $PROJECT_NAME --json > deployments.json
54+
55+
# 3. Use 'jq' to filter the JSON for deployments matching this PR's branch
56+
# (In our previous step, we named the branch 'pr-123')
57+
TARGET_IDS=$(jq -r ".[] | select(.Branch == \"pr-$PR_NUMBER\") | .Id" deployments.json)
58+
59+
# Check if any deployments were actually found
60+
if [ -z "$TARGET_IDS" ]; then
61+
echo "No preview deployments found for pr-$PR_NUMBER."
62+
exit 0
63+
fi
64+
65+
# 4. Loop through the matching IDs and force-delete them
66+
for ID in $TARGET_IDS; do
67+
echo "Deleting deployment ID: $ID..."
68+
wrangler pages deployment delete $ID --project-name $PROJECT_NAME --force
69+
done
70+
71+
echo "🎉 Cleanup complete!"

.github/workflows/deploy-pr.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# .github/workflows/deploy-pr.yml
2+
name: 2 - Deploy Web Page PR
3+
4+
on:
5+
workflow_run:
6+
workflows: ["1 - Check and Build Web Page PR"]
7+
types: [completed]
8+
9+
# CRITICAL: Grant the workflow permission to write comments on PRs
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
deploy-preview:
15+
if: github.event.workflow_run.conclusion == 'success'
16+
runs-on: ubuntu-latest
17+
environment: Cloudflare Pages
18+
permissions:
19+
# actions: read # Only required for private GitHub Repo
20+
contents: read
21+
deployments: write
22+
pull-requests: write
23+
24+
steps:
25+
- name: Download Site Artifact
26+
uses: actions/download-artifact@v4
27+
with:
28+
name: preview-site
29+
path: site/
30+
run-id: ${{ github.event.workflow_run.id }}
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
# NEW: Download the PR metadata artifact
34+
- name: Download PR Number Artifact
35+
uses: actions/download-artifact@v4
36+
with:
37+
name: pr-metadata
38+
run-id: ${{ github.event.workflow_run.id }}
39+
github-token: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Set PR Number Context
42+
run: |
43+
PR_NUMBER=$(cat pr-number.txt)
44+
# This syntax makes it available to subsequent steps as ${{ env.PR_NUMBER }}
45+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
46+
47+
- name: Deploy
48+
id: deploy
49+
uses: cloudflare/wrangler-action@v3
50+
with:
51+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
52+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
53+
command: |
54+
pages deploy site/ --project-name=openshift-examples --branch pr-${{ env.PR_NUMBER }}
55+
# Optional: Enable this if you want to have GitHub Deployments triggered
56+
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
57+
58+
- name: Comment on PR
59+
env:
60+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
CMD_OUTPUT: ${{ steps.deploy.outputs.command-output }}
62+
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
63+
run: |
64+
gh pr comment ${{ env.PR_NUMBER }} \
65+
--repo ${{ github.repository }} \
66+
--body "🚀 **Preview Deployment Success!** View your live changes here: $DEPLOYMENT_URL\n\n$CMD_OUTPUT"

.github/workflows/deploy.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
name: 'Deploy'
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
permissions:
11+
# actions: read # Only required for private GitHub Repo
12+
contents: read
13+
deployments: write
14+
pull-requests: write
15+
runs-on: ubuntu-latest
16+
environment: Cloudflare Pages
17+
timeout-minutes: 5
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- uses: actions/setup-python@v6
23+
with:
24+
python-version: 3.12
25+
cache: 'pip'
26+
- name: Install Dependencies
27+
run: |
28+
pip install -r requirements.txt
29+
30+
- name: Build Docs Website
31+
run: mkdocs build
32+
33+
- name: Deploy to Cloudflare Pages
34+
uses: andykenward/github-actions-cloudflare-pages@v3.0.0
35+
id: pages
36+
with:
37+
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
38+
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
39+
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
40+
directory: site
41+
github-token: ${{ secrets.GITHUB_TOKEN }}
42+
github-environment: Cloudflare Pages

.github/workflows/pr-check.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/pr-close.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/publish-main-releases.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ rosetta
55
.local
66
share
77
hooks/__pycache__/
8+
9+
# wrangler files
10+
.wrangler
11+
.dev.vars*
12+
!.dev.vars.example
13+
.env*
14+
!.env.example

wrangler.jsonc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "node_modules/wrangler/config-schema.json",
3+
"name": "openshift-examples",
4+
"compatibility_date": "2026-04-30",
5+
"observability": {
6+
"enabled": true
7+
},
8+
"assets": {
9+
"directory": "site"
10+
},
11+
"compatibility_flags": [
12+
"nodejs_compat"
13+
]
14+
}

0 commit comments

Comments
 (0)