fix: switch Cloudflare Pages deploy from tar+octet-stream to multipart+manifest API
CI / test (push) Successful in 1m49s
CI / docker (push) Successful in 21s

This commit is contained in:
zwitschi committed 2026-08-10 21:11:00 +02:00
1 parent 187d288e2e
commit af2e94aa46
2 files changed
+66 -18

No files matched your search

+34 -4
View File
@@ -25,16 +25,46 @@ jobs:
- name: Build - name: Build
run: cd frontend && npm run build run: cd frontend && npm run build
- name: Create deployment artifact - name: Generate deployment manifest
run: tar -czf site.tgz -C frontend/dist . run: |
cd frontend/dist
echo "{" > manifest.json
first=true
for file in $(find . -type f | sed 's|^\./||'); do
hash=$(sha256sum "$file" | awk '{print $1}')
if [ "$first" = true ]; then
first=false
else
echo "," >> manifest.json
fi
printf ' "%s": "%s"' "$file" "$hash" >> manifest.json
done
echo "" >> manifest.json
echo "}" >> manifest.json
echo "Generated manifest with $(grep -c ':' manifest.json) files"
- name: Deploy to Cloudflare Pages - name: Deploy to Cloudflare Pages
env: env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: | run: |
cd frontend/dist
# Build multipart form arguments from all files + manifest
form_args="-F manifest=@manifest.json"
for file in $(find . -type f ! -name manifest.json | sed 's|^\./||'); do
form_args="$form_args -F $file=@$file"
done
# Get short commit hash for deployment metadata
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
COMMIT_MSG=$(git log -1 --pretty=%B 2>/dev/null | head -1 || echo "Gitea Actions deploy")
curl -sS -X POST \ curl -sS -X POST \
"https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/linearvoid/deployments" \ "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/linearvoid/deployments" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: application/octet-stream" \ -H "Content-Type: multipart/form-data" \
--data-binary @site.tgz -F "commit_hash=${COMMIT_HASH}" \
-F "commit_message=${COMMIT_MSG}" \
-F "commit_dirty=false" \
$form_args
+32 -14
View File
@@ -53,7 +53,7 @@ jobs:
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 22
- name: Install dependencies - name: Install dependencies
run: cd frontend && npm ci run: cd frontend && npm ci
@@ -71,24 +71,42 @@ jobs:
gitHubToken: ${{ secrets.GITEA_TOKEN }} gitHubToken: ${{ secrets.GITEA_TOKEN }}
``` ```
If the `cloudflare/pages-action@v1` action is unavailable from Gitea, use the direct API approach: If the `cloudflare/pages-action@v1` action is unavailable from Gitea, use the direct Cloudflare Pages API (multipart/form-data with manifest):
```yaml ```yaml
- name: Create deployment artifact - name: Generate deployment manifest
run: tar -czf site.tgz -C frontend/dist . run: |
cd frontend/dist
echo "{" > manifest.json
first=true
for file in $(find . -type f | sed 's|^\./||'); do
hash=$(sha256sum "$file" | awk '{print $1}')
if [ "$first" = true ]; then first=false; else echo "," >> manifest.json; fi
printf ' "%s": "%s"' "$file" "$hash" >> manifest.json
done
echo "" >> manifest.json && echo "}" >> manifest.json
- name: Deploy to Cloudflare Pages - name: Deploy to Cloudflare Pages
env: env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: | run: |
curl -sS -X POST \ cd frontend/dist
"https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/linearvoid/deployments" \ form_args="-F manifest=@manifest.json"
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ for file in $(find . -type f ! -name manifest.json | sed 's|^\./||'); do
-H "Content-Type: application/octet-stream" \ form_args="$form_args -F $file=@$file"
--data-binary @site.tgz done
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
curl -sS -X POST \
"https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/linearvoid/deployments" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: multipart/form-data" \
-F "commit_hash=${COMMIT_HASH}" \
$form_args
``` ```
This matches the Cloudflare Pages Direct Upload API: `Content-Type: multipart/form-data`, each file as a separate form field, and a `manifest` JSON mapping filenames to SHA-256 hashes.
## Secrets to add in Gitea ## Secrets to add in Gitea
| Secret | Value | | Secret | Value |