Deploy to Cloudflare Pages #148
This file contains 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 to Cloudflare Pages | |
on: | |
workflow_run: | |
workflows: ['CI'] | |
types: ['completed'] | |
workflow_dispatch: | |
concurrency: | |
group: pages-${{ github.event.workflow_run.head_branch }} | |
cancel-in-progress: true | |
permissions: | |
pull-requests: write | |
env: | |
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} | |
jobs: | |
deploy-on-ci-success: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Comment start deploying preview | |
if: ${{ github.event.workflow_run.event != 'push' }} | |
uses: mshick/add-pr-comment@v2 | |
with: | |
issue: ${{ github.event.workflow_run.pull_requests[0].number }} | |
message-id: cloudflare-pages-preview-deployment | |
message: | | |
## <span aria-hidden="true">📤</span> Start Deploying preview... | |
| Name | Link | | |
| ---- | ---- | | |
| **Latest commit** | ${{ github.event.workflow_run.head_sha }} | | |
| **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.workflow_run.head_branch }} | |
fetch-depth: 0 | |
- name: Derive appropriate SHAs for base and head for `nx affected` commands | |
uses: nrwl/nx-set-shas@v4 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v3 | |
with: | |
version: 8.15.5 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.node-version' | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm i --frozen-lockfile | |
- name: Build | |
run: pnpm build | |
- name: Deploy | |
uses: cloudflare/pages-action@v1 | |
id: deploy-cloudflare-pages | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
projectName: portfolio | |
directory: ./apps/portfolio/dist/ | |
- name: Comment preview deployed successful | |
if: ${{ github.event.workflow_run.event != 'push' }} | |
uses: mshick/add-pr-comment@v2 | |
with: | |
issue: ${{ github.event.workflow_run.pull_requests[0].number }} | |
message-id: cloudflare-pages-preview-deployment | |
message: | | |
## <span aria-hidden="true">✅</span> Preview Deployed Successfully! | |
| Name | Link | | |
| ---- | ---- | | |
| **Latest commit** | ${{ github.event.workflow_run.head_sha }} | | |
| **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | | |
| **Preview URL (Latest)** | ${{ steps.deploy-cloudflare-pages.outputs.url }} | | |
| **Preview URL (Branch)** | ${{ steps.deploy-cloudflare-pages.outputs.alias }} | |