Skip to content

Deploy

Deploy #19

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows: [CI]
types: [completed]
# No branch filter - deploy previews for all branches after CI passes
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy'
required: true
default: 'main'
concurrency:
group: deploy-${{ github.event.workflow_run.head_branch || github.event.inputs.branch || github.ref }}
cancel-in-progress: true
jobs:
deploy:
name: Build & Deploy
runs-on: ubuntu-latest
if: >
github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'success'
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.event.inputs.branch || github.ref }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Setup Pocketbase
uses: ./.github/actions/setup-pocketbase
- name: Build
run: pnpm build
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
id: deploy
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy docs/.vitepress/dist --project-name=saf-site --branch=${{ github.event.workflow_run.head_branch || github.event.inputs.branch || 'main' }}
- name: Find PR number
if: github.event.workflow_run.event == 'pull_request'
id: find-pr
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: '${{ github.event.workflow_run.head_sha }}',
});
const pr = response.data[0];
if (pr) {
core.setOutput('number', pr.number);
}
- name: Comment on PR
if: steps.find-pr.outputs.number
uses: actions/github-script@v7
with:
script: |
const prNumber = ${{ steps.find-pr.outputs.number }};
const deploymentUrl = '${{ steps.deploy.outputs.deployment-url }}';
const aliasUrl = '${{ steps.deploy.outputs.pages-deployment-alias-url }}';
const body = `## Cloudflare Pages Preview
| | URL |
|---|---|
| **Preview** | ${aliasUrl || deploymentUrl} |
| **Direct** | ${deploymentUrl} |
Deployed from commit ${{ github.event.workflow_run.head_sha }}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' &&
c.body.includes('Cloudflare Pages Preview')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body,
});
}
- name: Output deployment URL
run: |
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**URL:** ${{ steps.deploy.outputs.deployment-url }}" >> $GITHUB_STEP_SUMMARY
echo "**Alias:** ${{ steps.deploy.outputs.pages-deployment-alias-url }}" >> $GITHUB_STEP_SUMMARY