Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 90 additions & 85 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -1,122 +1,127 @@
# .github/workflows/preview.yml
name: Preview deploy all Workers and CLIs
# .github/workflows/release.yml
name: Release all CLIs & Deploy CF Workers

on:
workflow_dispatch:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
branches: [main]
types: [opened, synchronize]
push:
branches: [main]

env:
# each folder under the repo root that contains one of your CLIs
WORKSPACES: create-db create-pg create-postgres

jobs:
preview:
name: 🚧 Preview release (PR #${{ github.event.number }})
# 1) On PRs: bump via Changesets
version:
if: ${{ github.event_name == 'pull_request' }}
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 v8
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Install dependencies (allow lockfile update)
run: pnpm install --workspace-root --no-frozen-lockfile

- name: Version & changelogs via Changesets
uses: changesets/action@v1
with:
version: "pnpm changeset version --yes"
commit: "chore(release): bump [skip ci]"
commitMode: "git-cli"
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# 2) On merge to main: aggregate, tag, publish
publish:
if: ${{ github.event_name == 'push' }}
needs: version
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout full history
- name: Checkout full history
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: true

- name: 🤐 Disable Husky
- name: Disable Husky
run: echo "HUSKY=0" >> $GITHUB_ENV

- name: 📦 Setup pnpm
- name: Setup pnpm v8
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: 🔧 Install dependencies
run: pnpm install
- name: Install dependencies (strict lockfile)
run: pnpm install --workspace-root --frozen-lockfile

- name: ❌ Disable pnpm git-checks
run: pnpm config set git-checks false
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq

- name: 📄 Copy README to child CLIs
- name: Copy root README to each CLI
run: |
for pkg in create-pg create-postgres; do
cp create-db/README.md "$pkg/README.md"
for pkg in $WORKSPACES; do
cp README.md "$pkg/README.md"
done

- name: 🔖 Create unique preview tag
- name: Aggregate changelogs
id: aggregate
run: |
echo "PRE_TAG=pr${{ github.event.number }}-${{ github.event.pull_request.head.ref }}-${{ github.run_id }}" >> $GITHUB_ENV
NEW_VERSION=$(jq -r '.version' package.json)
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "# Release v$NEW_VERSION" > AGGREGATED_CHANGELOG.md

# — 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
for pkg in $WORKSPACES; do
echo "## $pkg" >> AGGREGATED_CHANGELOG.md
sed -n "/^## $NEW_VERSION/,/^## /p" "$pkg/CHANGELOG.md" \
| sed '1d;$d' \
>> AGGREGATED_CHANGELOG.md
echo "" >> AGGREGATED_CHANGELOG.md
done

- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: v${{ env.NEW_VERSION }}
release_name: Release v${{ env.NEW_VERSION }}
body_path: AGGREGATED_CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 🔑 Configure npm auth
- name: Configure npm auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc

- name: 🚀 Bump & publish CLI previews
env:
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
- name: Publish each CLI individually
run: |
for pkg in $WORKSPACES; do
cd "$pkg"
npm version prerelease \
--preid "$PRE_TAG" \
--no-git-tag-version
pnpm publish --access public --tag pr${{ github.event.number }}
cd - >/dev/null
echo "Publishing $pkg@$NEW_VERSION…"
( cd "$pkg" && npm publish --access public )
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
# — CF Worker deploys (uncomment when ready) —
# - name: Deploy create-db-worker
# uses: cloudflare/wrangler-action@v3
# with:
# apiToken: ${{ secrets.CF_API_TOKEN }}
# accountId: ${{ secrets.CF_ACCOUNT_ID }}
# environment: production
# workingDirectory: create-db-worker

- name: Cleanup npm auth
if: ${{ always() }}
run: rm -f ~/.npmrc
Loading
Loading