Skip to content

DC-4635 Add Tests

DC-4635 Add Tests #186

Workflow file for this run

# .github/workflows/preview.yml
name: Preview deploy all Workers and CLIs
on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
env:
# each folder under the repo root that contains one of your CLIs
WORKSPACES: create-db create-pg create-postgres
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
POSTHOG_API_HOST: ${{ secrets.POSTHOG_API_HOST }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
jobs:
preview:
name: 🚧 Preview release (PR #${{ github.event.number }})
runs-on: ubuntu-latest
steps:
- name: πŸ›ŽοΈ Checkout full history
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: true
- name: 🀐 Disable Husky
run: echo "HUSKY=0" >> $GITHUB_ENV
- name: πŸ“¦ Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8
- name: πŸ”§ Install dependencies
run: pnpm install
- name: ❌ Disable pnpm git-checks
run: pnpm config set git-checks false
- name: πŸ“„ Copy README to child CLIs
run: |
for pkg in create-pg create-postgres; do
cp create-db/README.md "$pkg/README.md"
done
- name: πŸ”– Create unique preview tag
run: |
SAFE_REF=$(echo "${{ github.event.pull_request.head.ref }}" | tr '/' '-')
echo "PRE_TAG=pr${{ github.event.number }}-${SAFE_REF}-${{ github.run_id }}" >> $GITHUB_ENV
# β€” CF Worker preview deploys commented out; we will use pre-built URLs
# - name: ☁️ Deploy create-db-worker (preview)
# uses: cloudflare/wrangler-action@v3
# with:
# apiToken: ${{ secrets.CF_API_TOKEN }}
# accountId: ${{ secrets.CF_ACCOUNT_ID }}
# environment: ${{ env.PRE_TAG }}
# workingDirectory: create-db-worker
#
# - name: ☁️ Deploy claim-db-worker (preview)
# uses: cloudflare/wrangler-action@v3
# with:
# apiToken: ${{ secrets.CF_API_TOKEN }}
# accountId: ${{ secrets.CF_ACCOUNT_ID }}
# environment: ${{ env.PRE_TAG }}
# workingDirectory: claim-db-worker
- name: πŸ”‘ Configure npm auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc
- name: πŸš€ Bump & publish CLI previews
env:
WORKSPACES: create-db create-pg create-postgres
POSTHOG_API_HOST: ${{ secrets.POSTHOG_API_HOST }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
CREATE_DB_WORKER_URL: ${{ env.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ env.CLAIM_DB_WORKER_URL }}
run: |
# Resolve URLs with fallback
CREATE_DB_WORKER_URL="${{ steps.deploy-db.outputs.deployment-url || secrets.CREATE_DB_WORKER_URL }}"
CLAIM_DB_WORKER_URL="${{ steps.deploy-claim.outputs.deployment-url || secrets.CLAIM_DB_WORKER_URL }}"
# Persist for next steps
echo "CREATE_DB_WORKER_URL=$CREATE_DB_WORKER_URL" >> $GITHUB_ENV
echo "CLAIM_DB_WORKER_URL=$CLAIM_DB_WORKER_URL" >> $GITHUB_ENV
echo "Using CREATE_DB_WORKER_URL=$CREATE_DB_WORKER_URL"
echo "Using CLAIM_DB_WORKER_URL=$CLAIM_DB_WORKER_URL"
echo "Using POSTHOG_API_HOST=${POSTHOG_API_HOST}"
for pkg in $WORKSPACES; do
cd "$pkg"
export CREATE_DB_WORKER_URL
export CLAIM_DB_WORKER_URL
export POSTHOG_API_HOST="${POSTHOG_API_HOST}"
export POSTHOG_API_KEY="${POSTHOG_API_KEY}"
npm version prerelease \
--preid "$PRE_TAG" \
--no-git-tag-version
pnpm publish --access public --tag pr${{ github.event.number }}
cd - >/dev/null
done
- name: πŸ’¬ Post preview-testing instructions
uses: actions/github-script@v6
env:
PRE_TAG: ${{ env.PRE_TAG }}
CREATE_DB_WORKER_URL: ${{ steps.deploy-db.outputs.deployment-url }}
CLAIM_DB_WORKER_URL: ${{ steps.deploy-claim.outputs.deployment-url }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tag = process.env.PRE_TAG;
const dbUrl = process.env.CREATE_DB_WORKER_URL;
const clUrl = process.env.CLAIM_DB_WORKER_URL;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `
βœ… **Preview CLIs & Workers are live!**
Test the CLIs locally under tag \`${tag}\`:
\`\`\`bash
npx create-db@pr${{ github.event.number }}
npx create-pg@pr${{ github.event.number }}
npx create-postgres@$pr${{ github.event.number }}
\`\`\`
**Worker URLs**
β€’ Create-DB Worker: ${dbUrl}
β€’ Claim-DB Worker: ${clUrl}
> These will live as long as this PR exists under tag \`${tag}\`.`
});
- name: 🧹 Cleanup npm auth
run: rm -f ~/.npmrc