name: Deploy to Cloudflare Pages on: workflow_run: workflows: ["Sync to Pages and Functions"] types: - completed branches: - main workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: false env: WRANGLER_VERSION: "4.76.0" jobs: deploy: runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: read deployments: write if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} steps: - name: Checkout pages branch uses: actions/checkout@v6 with: ref: pages - name: Ensure Cloudflare Pages project exists env: CF_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CF_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CF_PAGES_PROJECT: xget CF_PRODUCTION_BRANCH: main shell: bash run: | set -euo pipefail api_base="https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/pages/projects" auth_header="Authorization: Bearer ${CF_API_TOKEN}" echo "Checking Pages project: ${CF_PAGES_PROJECT}" if curl -fsS -H "${auth_header}" "${api_base}/${CF_PAGES_PROJECT}" >/dev/null; then echo "Pages project exists." exit 0 fi echo "Pages project not found. Creating..." create_payload="$(printf '{"name":"%s","production_branch":"%s"}' "${CF_PAGES_PROJECT}" "${CF_PRODUCTION_BRANCH}")" curl -fsS -X POST -H "${auth_header}" -H "Content-Type: application/json" \ --data "${create_payload}" \ "${api_base}" >/dev/null echo "Pages project created." - name: Setup Node.js uses: actions/setup-node@v6 with: node-version: "24" - name: Install Wrangler CLI run: npm install --global wrangler@${{ env.WRANGLER_VERSION }} - name: Deploy to Cloudflare Pages env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} run: wrangler pages deploy . --project-name=xget --branch=${{ github.ref_name }}