Skip to content

Commit da8cda1

Browse files
committed
ci: verify Cloudflare Pages project via API before deploy
1 parent 2726150 commit da8cda1

2 files changed

Lines changed: 46 additions & 22 deletions

File tree

.github/workflows/cloudflare-pages-runtime.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,31 @@ jobs:
5858
- name: 🏗 Build Cloudflare Pages output (functions + static)
5959
run: pnpm dlx @cloudflare/next-on-pages@1
6060

61-
- name: 🔎 Debug Cloudflare Pages access
62-
uses: cloudflare/wrangler-action@v3
63-
with:
64-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
65-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
66-
command: >-
67-
pages project list
68-
69-
- name: 📝 Debug target Pages project
70-
run: |
71-
echo "Target Pages project: $PROJECT_NAME"
61+
- name: 🔎 Verify Cloudflare Pages project exists
7262
env:
63+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
64+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
7365
PROJECT_NAME: ${{ secrets.CLOUDFLARE_PAGES_PROJECT_NAME_RUNTIME }}
66+
run: |
67+
RESPONSE=$(curl -fsSL \
68+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
69+
-H "Content-Type: application/json" \
70+
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects")
71+
72+
COUNT=$(printf '%s' "$RESPONSE" | jq '.result | length')
73+
MATCH=$(printf '%s' "$RESPONSE" | jq --arg name "$PROJECT_NAME" 'any(.result[]?; .name == $name)')
74+
75+
echo "Pages projects visible in this account: $COUNT"
76+
77+
if [ "$MATCH" != "true" ]; then
78+
echo "Configured Pages project was not found in the provided Cloudflare account."
79+
echo "Verify CLOUDFLARE_ACCOUNT_ID points to the same account that owns the Pages project."
80+
echo "Visible project names:"
81+
printf '%s' "$RESPONSE" | jq -r '.result[]?.name'
82+
exit 1
83+
fi
84+
85+
echo "Configured Pages project exists in the target account."
7486
7587
- name: 🚀 Deploy runtime app to Cloudflare Pages
7688
uses: cloudflare/wrangler-action@v3

.github/workflows/cloudflare-pages.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,31 @@ jobs:
4646
run: |
4747
pnpm build
4848
49-
- name: 🔎 Debug Cloudflare Pages access
50-
uses: cloudflare/wrangler-action@v3
51-
with:
52-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
53-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
54-
command: >-
55-
pages project list
56-
57-
- name: 📝 Debug target Pages project
58-
run: |
59-
echo "Target Pages project: $PROJECT_NAME"
49+
- name: 🔎 Verify Cloudflare Pages project exists
6050
env:
51+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
52+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
6153
PROJECT_NAME: ${{ secrets.CLOUDFLARE_PAGES_PROJECT_NAME }}
54+
run: |
55+
RESPONSE=$(curl -fsSL \
56+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
57+
-H "Content-Type: application/json" \
58+
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects")
59+
60+
COUNT=$(printf '%s' "$RESPONSE" | jq '.result | length')
61+
MATCH=$(printf '%s' "$RESPONSE" | jq --arg name "$PROJECT_NAME" 'any(.result[]?; .name == $name)')
62+
63+
echo "Pages projects visible in this account: $COUNT"
64+
65+
if [ "$MATCH" != "true" ]; then
66+
echo "Configured Pages project was not found in the provided Cloudflare account."
67+
echo "Verify CLOUDFLARE_ACCOUNT_ID points to the same account that owns the Pages project."
68+
echo "Visible project names:"
69+
printf '%s' "$RESPONSE" | jq -r '.result[]?.name'
70+
exit 1
71+
fi
72+
73+
echo "Configured Pages project exists in the target account."
6274
6375
- name: 🚀 Deploy to Cloudflare Pages
6476
uses: cloudflare/wrangler-action@v3

0 commit comments

Comments
 (0)