few changes #11
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 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| - run: bun install | |
| - run: bun run build | |
| env: | |
| BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }} | |
| ORAMA_CLOUD_API_KEY: ${{ secrets.ORAMA_CLOUD_API_KEY }} | |
| ORAMA_CLOUD_ENDPOINT: ${{ secrets.ORAMA_CLOUD_ENDPOINT }} | |
| CLOUDFLARE_TURNSTILE_SITE_KEY: ${{ secrets.CLOUDFLARE_TURNSTILE_SITE_KEY }} | |
| - name: Set branch name | |
| id: vars | |
| run: | | |
| ref=${{ github.event.pull_request.head.ref }} | |
| if [ "$ref" == "refs/heads/main" ]; then | |
| echo "branch=main" >> $GITHUB_OUTPUT | |
| else | |
| echo "branch=${ref}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Ensure Cloudflare Pages project exists | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| run: | | |
| set -e | |
| project_name="capacitor-tutorial" | |
| api="https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/${project_name}" | |
| status=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" "$api") | |
| if [ "$status" = "404" ]; then | |
| echo "Project does not exist. Creating..." | |
| curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects" \ | |
| -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ | |
| -H "Content-Type: application/json" \ | |
| --data "{\"name\":\"${project_name}\",\"production_branch\":\"main\"}" | |
| else | |
| echo "Project exists or another error occurred (status: $status)." | |
| fi | |
| - run: bunx wrangler@latest pages deploy dist --project-name capacitor-tutorial --branch ${{ steps.vars.outputs.branch }} | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| - name: Comment deployed link on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const branch = '${{ steps.vars.outputs.branch }}'; | |
| const url = `https://${branch}.capacitor-tutorial.pages.dev`; | |
| const body = `🚀 Preview deployed: [${url}](${url})`; | |
| await github.rest.issues.createComment({ | |
| body, | |
| repo: context.repo.repo, | |
| owner: context.repo.owner, | |
| issue_number: context.issue.number, | |
| }); |