Skip to content

feat: setup auto-publish and deploy to CF and npm #19

feat: setup auto-publish and deploy to CF and npm

feat: setup auto-publish and deploy to CF and npm #19

Workflow file for this run

name: Preview & Publish all CLIs
on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
push:
branches:
- main
env:
# each folder under the repo root that contains one of your CLIs
WORKSPACES: create-db create-pg create-postgres
# each folder under the repo root that contains one of your CF Workers
CF_WORKERS: create-db-worker claim-db-worker
jobs:
preview:
if: github.event_name == 'pull_request'
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@v2
with:
version: 8
- name: πŸ”§ Install dependencies
run: pnpm install
- name: ❌ Disable pnpm git-checks
run: pnpm config set git-checks false
- name: 🏷️ Set PRE_TAG
run: echo "PRE_TAG=pr${{ github.event.number }}-${{ github.event.pull_request.head.ref }}-${{ github.run_id }}" >> $GITHUB_ENV
- 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: ☁️ Deploy create-db-worker (preview)
id: deploy-create-db
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)
id: deploy-claim-db
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 previews
env:
PRE_TAG: ${{ env.PRE_TAG }}
CREATE_DB_WORKER_URL: ${{ steps.deploy-create-db.outputs.deployment-url }}
CLAIM_DB_WORKER_URL: ${{ steps.deploy-claim-db.outputs.deployment-url }}
run: |
for pkg in $WORKSPACES; do
echo "β€Ί $pkg β†’ bumping & publishing preview @$PRE_TAG"
cd "$pkg"
npm version prerelease \
--preid "$PRE_TAG" \
--no-git-tag-version
pnpm publish --access public --tag pr${{ github.event.number }}
cd - >/dev/null
done
- name: 🧹 Cleanup npm auth
run: rm -f ~/.npmrc
publish:
if: github.event_name == 'push'
needs: preview
name: πŸš€ Bump & publish real releases
runs-on: ubuntu-latest
steps:
- name: πŸ›ŽοΈ Checkout full & tags
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@v2
with:
version: 8
- name: πŸ”§ Install dependencies
run: pnpm install
- name: πŸ”„ Bump versions & generate changelogs
run: pnpm changeset version
- 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: πŸ’Ύ Commit & push version bump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git commit -am "chore: version packages [skip ci]" || echo "no version changes"
git push origin main --follow-tags
- name: πŸ”‘ Configure npm auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc
- name: πŸš€ Publish all real releases
env:
NPM_TOKEN: ${{ secrets.CREATE_DB_TOKEN_NPM }}
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
run: |
for pkg in $WORKSPACES; do
echo "β€Ί publishing $pkg"
cd "$pkg"
pnpm publish --access public
cd - >/dev/null
done
- name: ☁️ Deploy create-db-worker (production)
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
workingDirectory: create-db-worker
- name: ☁️ Deploy claim-db-worker (production)
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
workingDirectory: claim-db-worker
- name: 🧹 Cleanup npm auth
run: rm -f ~/.npmrc