diff --git a/.github/workflows/deploy-examples.yml b/.github/workflows/deploy-examples.yml index 01916d7..7925b74 100644 --- a/.github/workflows/deploy-examples.yml +++ b/.github/workflows/deploy-examples.yml @@ -65,8 +65,45 @@ jobs: EOF + - name: Create GitHub deployment + id: create-deployment + uses: actions/github-script@v7 + with: + result-encoding: string + script: | + const { data } = await github.rest.repos.createDeployment({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: context.sha, + environment: 'production', + auto_merge: false, + required_contexts: [], + description: 'Cloudflare Workers', + }); + return String(data.id); + - name: Deploy to Cloudflare - run: pnpm dlx wrangler deploy --assets=./pages + id: deploy + run: | + OUTPUT=$(pnpm dlx wrangler deploy --assets=./pages 2>&1) + echo "$OUTPUT" + URL=$(echo "$OUTPUT" | grep -oE 'https://[a-zA-Z0-9._-]+\.workers\.dev' | tail -1) + echo "url=$URL" >> $GITHUB_OUTPUT env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + + - name: Update deployment status + if: always() + uses: actions/github-script@v7 + with: + script: | + await github.rest.repos.createDeploymentStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + deployment_id: ${{ steps.create-deployment.outputs.result }}, + state: '${{ steps.deploy.outcome }}' === 'success' ? 'success' : 'failure', + environment_url: '${{ steps.deploy.outputs.url }}', + log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, + auto_inactive: true, + });