Skip to content

feat: support for 'image' shape in spawner #58

feat: support for 'image' shape in spawner

feat: support for 'image' shape in spawner #58

Workflow file for this run

name: playground
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.15.9
- name: Get pnpm store directory
id: pnpm_store
shell: bash
run: |
STORE_PATH="$(pnpm store path --silent)"
echo "STORE_PATH=${STORE_PATH}" >> "$GITHUB_ENV"
echo "store_path=${STORE_PATH}" >> "$GITHUB_OUTPUT"
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm_store.outputs.store_path }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm -r install --frozen-lockfile --prod=false
- name: Verify build tooling
run: pnpm --filter @cazala/party exec -- rollup --version
- name: Build
run: |
set -euo pipefail
pnpm --filter=@cazala/party build
# Typecheck + build once (base="/party/").
pnpm --filter=@cazala/playground type-check
VITE_PUBLIC_BASE=/party/ pnpm --filter=@cazala/playground exec -- vite build
- name: Install Wrangler
run: npm install -g wrangler@3
- name: Create Cloudflare Pages project if it doesn't exist
run: |
# Set up wrangler authentication
export CLOUDFLARE_API_TOKEN="${{ secrets.CLOUDFLARE_API_TOKEN }}"
export CLOUDFLARE_ACCOUNT_ID="${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"
# Check if project exists, create if it doesn't.
# NOTE: avoid substring matches.
if ! wrangler pages project list 2>/dev/null | grep -qE '(^|[[:space:]])party-playground([[:space:]]|$)'; then
echo "Creating Cloudflare Pages project 'party-playground'..."
wrangler pages project create party-playground --production-branch=main || true
else
echo "Project 'party-playground' already exists"
fi
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deploy to Cloudflare Pages (preview)
id: deploy_preview
if: github.event_name == 'pull_request'
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
set -euo pipefail
# Capture deploy output so we can extract the preview URL for the PR comment.
wrangler pages deploy packages/playground/dist \
--project-name party-playground \
--branch "pr-${{ github.event.pull_request.number }}" \
--commit-dirty=true \
2>&1 | tee wrangler-deploy.log
PREVIEW_URL="$(grep -Eo 'https://[^ ]+\.pages\.dev[^ ]*' wrangler-deploy.log | head -n 1 || true)"
if [ -z "${PREVIEW_URL}" ]; then
echo "Could not detect Cloudflare Pages preview URL from wrangler output."
echo "url=" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Detected preview URL: ${PREVIEW_URL}"
echo "url=${PREVIEW_URL}" >> "$GITHUB_OUTPUT"
- name: Create GitHub deployment (preview)
if: github.event_name == 'pull_request' && steps.deploy_preview.outputs.url != ''
uses: actions/github-script@v7
env:
PREVIEW_URL: ${{ steps.deploy_preview.outputs.url }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const ref = context.payload.pull_request?.head?.sha || context.sha;
const environment = 'preview';
const environment_url = process.env.PREVIEW_URL;
const deployment = await github.rest.repos.createDeployment({
owner,
repo,
ref,
environment,
auto_merge: false,
required_contexts: [],
transient_environment: true,
production_environment: false,
description: `Cloudflare Pages preview: ${environment_url}`,
});
await github.rest.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.data.id,
state: 'success',
environment,
environment_url,
log_url: environment_url,
description: 'Deployed to Cloudflare Pages (preview)',
});
- name: Comment on PR with preview URL
if: github.event_name == 'pull_request' && steps.deploy_preview.outputs.url != ''
uses: actions/github-script@v7
env:
PREVIEW_URL: ${{ steps.deploy_preview.outputs.url }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const marker = '<!-- party-preview-url -->';
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.payload.pull_request.number;
const url = process.env.PREVIEW_URL;
// For pull_request events, context.sha is the temporary merge commit SHA.
// Use the PR head SHA so reviewers can find the real commit in the repo.
const sha = context.payload.pull_request?.head?.sha || context.sha;
const body = [
marker,
`**Preview deployment ready**`,
'',
`- **URL**: ${url}`,
`- **Commit**: ${sha}`,
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
// If multiple marker comments exist (e.g. from a historical bug), update the most recent one.
const existing = [...comments]
.reverse()
.find(c => typeof c.body === 'string' && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
- name: Deploy to Cloudflare Pages (production)
id: deploy_production
if: github.event_name == 'push'
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
set -euo pipefail
wrangler pages deploy packages/playground/dist \
--project-name party-playground \
--branch "${{ github.ref_name }}" \
--commit-dirty=true \
2>&1 | tee wrangler-deploy.log
PRODUCTION_URL="$(grep -Eo 'https://[^ ]+\.pages\.dev[^ ]*' wrangler-deploy.log | head -n 1 || true)"
echo "url=${PRODUCTION_URL}" >> "$GITHUB_OUTPUT"
- name: Create GitHub deployment (production)
if: github.event_name == 'push' && steps.deploy_production.outputs.url != ''
uses: actions/github-script@v7
env:
PRODUCTION_URL: ${{ steps.deploy_production.outputs.url }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const ref = context.sha;
const environment = 'production';
const environment_url = process.env.PRODUCTION_URL;
const deployment = await github.rest.repos.createDeployment({
owner,
repo,
ref,
environment,
auto_merge: false,
required_contexts: [],
transient_environment: false,
production_environment: true,
description: `Cloudflare Pages production: ${environment_url}`,
});
await github.rest.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.data.id,
state: 'success',
environment,
environment_url,
log_url: environment_url,
description: 'Deployed to Cloudflare Pages (production)',
});