Skip to content

feat(ci): add CSP, HSTS headers and PR preview deployments #1

feat(ci): add CSP, HSTS headers and PR preview deployments

feat(ci): add CSP, HSTS headers and PR preview deployments #1

Workflow file for this run

name: Preview Deployment
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: "preview-${{ github.head_ref }}"
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
preview:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.1.42"
- name: Cache Bun dependencies
uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Install dependencies
run: bun install
- name: Build
run: bun run build
- name: Deploy Preview
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=soumyo-com --branch=${{ github.head_ref }}
- name: Comment Preview URL
uses: actions/github-script@v7
with:
script: |
const output = `${{ steps.deploy.outputs.deployment-url }}`;
const body = `## Preview Deployment Ready!\n\n**Preview URL:** ${output}\n\n*This preview will be automatically updated when you push new commits.*`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c => c.body.includes('Preview Deployment Ready'));
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}