chore: configure Conventional Commits, Husky, and Changesets #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: π 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 CF Workers (preview) | |
id: deploy-workers-preview | |
env: | |
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | |
run: | | |
PRE_TAG="pr${{ github.event.number }}-${{ github.event.pull_request.head.ref }}-${{ github.run_id }}" | |
echo "PRE_TAG=$PRE_TAG" >> $GITHUB_ENV | |
for worker in $CF_WORKERS; do | |
echo "βΊ deploying $worker β env $PRE_TAG" | |
resp=$(wrangler publish \ | |
--env "$PRE_TAG" \ | |
--account-id "$CF_ACCOUNT_ID" \ | |
--api-token "$CF_API_TOKEN" \ | |
--json) | |
url=$(echo "$resp" | grep -Po '"url":"\K[^"]+') | |
if [ "$worker" = "create-db-worker" ]; then | |
echo "create_db_worker_url=$url" >> $GITHUB_OUTPUT | |
else | |
echo "claim_db_worker_url=$url" >> $GITHUB_OUTPUT | |
fi | |
done | |
- name: π Configure npm auth | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc | |
- name: π Bump & publish previews | |
env: | |
NPM_TOKEN: ${{ secrets.CREATE_DB_TOKEN_NPM }} | |
CREATE_DB_WORKER_URL: ${{ steps.deploy-workers-preview.outputs.create_db_worker_url }} | |
CLAIM_DB_WORKER_URL: ${{ steps.deploy-workers-preview.outputs.claim_db_worker_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 CF Workers (production) | |
env: | |
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | |
run: | | |
for worker in $CF_WORKERS; do | |
echo "βΊ deploying $worker to production" | |
cd $worker | |
wrangler publish \ | |
--account-id $CF_ACCOUNT_ID \ | |
--api-token $CF_API_TOKEN | |
cd - >/dev/null | |
done | |
- name: π§Ή Cleanup npm auth | |
run: rm -f ~/.npmrc |