Release CLIs #19
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: Release and deploy | |
on: | |
# 1. Trigger for the 'version' job: runs on push to main to create a release PR. | |
push: | |
branches: | |
- main | |
tags: | |
- "v*.*.*" | |
# 3. Manual Trigger: allows you to run either job on any branch for testing. | |
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 # Disable Husky for all CI runs | |
jobs: | |
#================================================================ | |
# JOB 1: Create a "Version Packages" PR after merging to main | |
#================================================================ | |
version: | |
# Runs on push to main OR a manual 'version' dispatch | |
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_name == 'workflow_dispatch' && github.event.inputs.branch || github.ref }} | |
fetch-depth: 0 | |
# We need to persist credentials for the changesets-action to push a new branch | |
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: | |
# This command will create a PR with version bumps and changelogs | |
version: pnpm changeset version | |
commit: "chore(release): version packages for release" | |
title: "chore(release): Version Packages" | |
create-github-releases: false # We will do this in the 'publish' job | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
#================================================================ | |
# JOB 2: Publish to NPM and create GitHub Release from a tag | |
#================================================================ | |
publish: | |
# Runs on a v* tag push OR a manual 'publish' dispatch | |
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_name == 'workflow_dispatch' && 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 individually | |
run: | | |
for pkg in $WORKSPACES; do | |
echo "Publishing $pkgβ¦" | |
pnpm --filter "$pkg" publish --access public --no-git-checks | |
done | |
- name: π© Create GitHub Release | |
if: github.event_name == 'push' # Only create a release on a real tag push | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ github.ref_name }} | |
release_name: Release ${{ github.ref_name }} | |
# This automatically generates release notes from PRs since the last tag. | |
# This is cleaner than your manual aggregation script. | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: π§Ή Cleanup npm auth | |
if: ${{ always() }} | |
run: rm -f ~/.npmrc | |
# Add your Cloudflare Worker deploy steps here | |
# - name: βοΈ Deploy create-db-worker (production) | |
# uses: cloudflare/wrangler-action@v3 | |
# with: β¦ |