Release CLIs #22
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
# .github/workflows/release.yml | |
name: Release and deploy | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "v*.*.*" | |
workflow_dispatch: | |
inputs: | |
job_to_run: | |
description: "Job to run manually" | |
required: true | |
type: choice | |
options: | |
- version | |
- publish | |
default: "publish" | |
branch: | |
description: "Branch to run on (defaults to main)" | |
required: true | |
default: "main" | |
env: | |
WORKSPACES: create-db create-pg create-postgres | |
HUSKY: 0 | |
jobs: | |
#============================================================== | |
# 1. Create a "Version Packages" PR (runs after main merge) | |
#============================================================== | |
version: | |
if: | | |
(github.event_name == 'push' && github.ref == 'refs/heads/main') || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.job_to_run == 'version') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.branch || github.ref }} | |
fetch-depth: 0 | |
persist-credentials: true | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Install dependencies | |
run: pnpm install | |
- name: Create Version PR | |
uses: changesets/action@v1 | |
with: | |
version: pnpm changeset version | |
commit: "chore(release): version packages for release" | |
title: "chore(release): Version Packages" | |
create-github-releases: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
#============================================================== | |
# 2. Publish Packages to NPM | |
#============================================================== | |
publish: | |
if: | | |
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.job_to_run == 'publish') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.branch || github.ref }} | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Copy README to child CLIs | |
run: | | |
for pkg in $WORKSPACES; do | |
if [ "$pkg" != "create-db" ]; then | |
cp create-db/README.md "$pkg/README.md" | |
fi | |
done | |
- name: Configure npm auth | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc | |
- name: Publish each CLI (sequential) | |
run: | | |
for pkg in $WORKSPACES; do | |
echo "🚀 Publishing $pkg..." | |
cd "$pkg" | |
npm publish --access public --no-git-checks || exit 1 | |
cd - >/dev/null | |
done | |
- name: Create GitHub Release | |
if: github.event_name == 'push' | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ github.ref_name }} | |
release_name: Release ${{ github.ref_name }} | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Cleanup npm auth | |
if: ${{ always() }} | |
run: rm -f ~/.npmrc | |
# Optional Cloudflare Worker Deploys | |
# - name: Deploy create-db-worker | |
# uses: cloudflare/wrangler-action@v3 | |
# with: | |
# apiToken: ${{ secrets.CF_API_TOKEN }} | |
# accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
# workingDirectory: create-db-worker |