fix: Explicitly specify entry point and worker name in deploy command #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Branch to Cloudflare Workers | |
on: | |
push: | |
branches-ignore: | |
- main | |
- v1 | |
permissions: | |
contents: read | |
deployments: write | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up Hugo (extended) | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
extended: true | |
- name: Make scripts executable | |
run: chmod +x scripts/*.sh tools/*/*/*.sh || true | |
- name: Build site with Makefile | |
run: make dist | |
- name: Create sanitized worker name from branch | |
id: worker-name | |
run: | | |
# Convert branch name to valid worker name (lowercase, replace / and _ with -, limit length) | |
BRANCH_NAME="${{ github.ref_name }}" | |
WORKER_NAME=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[/_]/-/g' | sed 's/[^a-z0-9-]//g' | cut -c1-63) | |
echo "name=$WORKER_NAME" >> $GITHUB_OUTPUT | |
echo "Worker name will be: $WORKER_NAME" | |
- name: Create wrangler.json | |
run: | | |
cat > wrangler.json <<EOF | |
{ | |
"name": "${{ steps.worker-name.outputs.name }}", | |
"compatibility_date": "2025-08-27", | |
"main": "src/index.js", | |
"assets": { | |
"directory": "./dist", | |
"binding": "ASSETS", | |
"html_handling": "auto-trailing-slash" | |
} | |
} | |
EOF | |
- name: Create Worker entry point | |
run: | | |
mkdir -p src | |
cat > src/index.js <<EOF | |
// Static site handler for Hugo branch deployment | |
export default { | |
async fetch(request, env) { | |
return env.ASSETS.fetch(request); | |
} | |
}; | |
EOF | |
- name: Debug - Check created files | |
run: | | |
echo "=== Current directory ===" | |
pwd | |
ls -la | |
echo "=== dist directory ===" | |
ls -la dist/ | head -10 | |
echo "=== src directory ===" | |
ls -la src/ | |
echo "=== wrangler.json ===" | |
cat wrangler.json | |
echo "=== src/index.js ===" | |
cat src/index.js | |
- name: Deploy to Cloudflare Workers | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: deploy src/index.js --name ${{ steps.worker-name.outputs.name }} | |
- name: Output deployment URL | |
run: | | |
echo "🚀 Deployed to: https://${{ steps.worker-name.outputs.name }}.${CF_WORKERS_SUBDOMAIN:-your-subdomain}.workers.dev" | |
env: | |
CF_WORKERS_SUBDOMAIN: ${{ secrets.CF_WORKERS_SUBDOMAIN }} |