Skip to content
Merged
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
9 changes: 9 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changesets

This repo uses [Changesets](https://github.com/changesets/changesets) for versioning and publishing.

- Config: `config.json`. One public package, `@llazyemail/template-runtime-display`.
- Add a fragment: `npm run changeset` (or the **Add changeset** GitHub Action). Renovate and Dependabot dependency PRs get a patch fragment automatically from `add-bot-changeset.yml`.
- On push to `main`, `changesets.yml` opens a **Version packages** PR while fragments are pending.
- When that PR merges (no fragments left), the same workflow runs `changeset git-tag`, pushes the `@llazyemail/template-runtime-display@<version>` tag, creates the GitHub Release from `CHANGELOG.md`, and dispatches `publish.yml` for that tag.
- `publish.yml` does the actual `npm publish` to GitHub Packages. Releases created by `GITHUB_TOKEN` do not fire `release: published`, which is why the workflow is dispatched explicitly.
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
64 changes: 64 additions & 0 deletions .github/workflows/add-bot-changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Add a patch changeset to Renovate / Dependabot dependency PRs so
# changesets.yml can open a Version packages PR when they merge.
# Tooling-only PRs (packageManager bumps, GitHub Actions) are skipped.
# If Renovate later rebases and drops the file, this workflow writes it again.

name: Add changeset for bot dependency PRs

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'package.json'
- 'package-lock.json'

permissions:
contents: write
pull-requests: write

concurrency:
group: add-bot-changeset-${{ github.event.pull_request.head.ref }}
cancel-in-progress: true

jobs:
add-changeset:
name: Add patch changeset
if: >
github.event.pull_request.head.repo.full_name == github.repository &&
(
github.event.pull_request.user.login == 'renovate[bot]' ||
github.event.pull_request.user.login == 'dependabot[bot]'
)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch the PR base
run: git fetch origin "${{ github.base_ref }}" --depth=1

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Write and commit a patch changeset if needed
env:
BASE_REF: origin/${{ github.base_ref }}
TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.pull_request.number }}
COMMIT: '1'
run: bash scripts/add-bot-changeset.sh

- name: Push
run: |
remote_ref="origin/${{ github.head_ref }}"
if git rev-parse "$remote_ref" >/dev/null 2>&1 && [ "$(git rev-parse HEAD)" = "$(git rev-parse "$remote_ref")" ]; then
echo "No new commit to push."
else
git push origin "HEAD:${{ github.head_ref }}"
fi
119 changes: 119 additions & 0 deletions .github/workflows/add-changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Add a Changeset from the Actions UI.
#
# Writes a changeset, commits it, and opens a pull request.
# Merging that PR triggers "Version packages", which opens the Version PR.
# Merging the Version Packages PR tags the release, creates the GitHub Release,
# and dispatches publish.yml (GitHub Packages).

name: Add changeset

on:
workflow_dispatch:
inputs:
bump:
description: Semver bump
required: true
type: choice
options:
- patch
- minor
- major
default: minor
summary:
description: User-facing summary (one or more lines)
required: true
type: string
branch_prefix:
description: Branch name prefix
required: false
type: string
default: changeset

permissions:
contents: write
pull-requests: write

concurrency:
group: add-changeset
cancel-in-progress: false

jobs:
add-changeset:
name: Create changeset PR
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Write changeset file
id: changeset
env:
BUMP: ${{ inputs.bump }}
SUMMARY: ${{ inputs.summary }}
run: |
set -euo pipefail
mkdir -p .changeset
id=$(date -u +%Y%m%d%H%M%S)-${BUMP}
file=".changeset/${id}.md"
{
echo "---"
echo "\"@llazyemail/template-runtime-display\": ${BUMP}"
echo "---"
echo ""
printf '%s\n' "$SUMMARY"
echo ""
} > "$file"
echo "file=$file" >> "$GITHUB_OUTPUT"
echo "id=$id" >> "$GITHUB_OUTPUT"
echo "Wrote $file:"
cat "$file"

- name: Commit and open pull request
env:
BUMP: ${{ inputs.bump }}
SUMMARY: ${{ inputs.summary }}
BRANCH_PREFIX: ${{ inputs.branch_prefix }}
FILE: ${{ steps.changeset.outputs.file }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
branch="${BRANCH_PREFIX}/${BUMP}-$(date -u +%Y%m%d%H%M%S)"
git checkout -b "$branch"
git add "$FILE"
git commit -m "chore: add ${BUMP} changeset

${SUMMARY}"
git push -u origin "$branch"

pr_url=$(gh pr create \
--title "chore: add ${BUMP} changeset" \
--body "$(cat <<EOF
## Changeset

Opened by the **Add changeset** workflow.

- Package: \`@llazyemail/template-runtime-display\`
- Bump: \`${BUMP}\`
- Summary:

${SUMMARY}

### Next steps

1. Merge this PR.
2. **Version packages** opens a Version PR (bumps package.json / CHANGELOG).
3. Merge that Version PR to release / publish to GitHub Packages.
EOF
)" \
--base main \
--head "$branch")

echo "Opened: $pr_url"
64 changes: 64 additions & 0 deletions .github/workflows/changesets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Version packages

on:
push:
branches: [main]

concurrency:
group: changesets
cancel-in-progress: false

# Publishing itself happens in publish.yml (GitHub Packages). This job only
# versions, tags, creates the GitHub Release, and dispatches publish.yml for
# the new tag. Releases created with GITHUB_TOKEN do not fire release: published.
permissions:
contents: write
pull-requests: write
actions: write
packages: read

jobs:
version:
name: Open version PR or publish
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26
cache: npm
registry-url: https://npm.pkg.github.com
scope: '@llazyemail'

- name: Install
run: npm ci --no-audit --no-fund
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Version PR, or tag + GitHub Release after it merges
id: changesets
uses: changesets/action@v2.1.2
with:
version-script: npm run version-packages
publish-script: npx changeset git-tag
pr-title: Version packages
commit-message: Version packages
create-github-releases: true

- name: Publish the new tag to GitHub Packages (publish.yml)
if: steps.changesets.outputs.published == 'true'
env:
GH_TOKEN: ${{ github.token }}
PUBLISHED: ${{ steps.changesets.outputs.published-packages }}
run: |
version="$(echo "$PUBLISHED" | jq -r '.[] | select(.name == "@llazyemail/template-runtime-display") | .version')"
if [ -z "$version" ]; then
echo "@llazyemail/template-runtime-display was not tagged in this run; nothing to publish."
exit 0
fi
gh workflow run publish.yml --ref "@llazyemail/template-runtime-display@${version}"
echo "Dispatched publish.yml for @llazyemail/template-runtime-display@${version}" >> "$GITHUB_STEP_SUMMARY"
7 changes: 5 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Publish @llazyemail/template-runtime-display to GitHub Packages.
#
# Runs when a GitHub Release is published, and when someone starts the
# workflow by hand. A manual run publishes unless "Pack only" is checked.
# Runs when a GitHub Release is published, when Version packages dispatches
# this workflow for a new tag, and when someone starts the workflow by hand.
# A manual run publishes unless "Pack only" is checked.
# Releases created with GITHUB_TOKEN do not fire release: published, so
# changesets.yml dispatches this workflow for the tag.
# GITHUB_TOKEN is provided by Actions. The package scope must stay @llazyemail.

name: Publish to GitHub Packages
Expand Down
15 changes: 12 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ npm run generate # build, render a letter, print explain(), write generate
npm run publint # export and types check; requires dist/
npm run smoke # load the ESM, CJS, and IIFE builds; requires dist/
npm run check # format, lint, typecheck, build, test, smoke, publint
npm run changeset # write a .changeset fragment (or use the Add changeset workflow)
npm run version-packages # consume fragments; usually via changesets.yml on main
```

Renovate and Dependabot PRs that change `package.json` or `package-lock.json` get a patch changeset from `add-bot-changeset.yml`. Do not add one by hand unless the workflow skipped the PR (`packageManager` bumps and GitHub Actions-only updates are skipped on purpose).

## Hard rules for AI agents

These two rules are non-negotiable. Fail the task if either is skipped.
Expand Down Expand Up @@ -92,8 +96,13 @@ test/polish.test.ts inspector sections, trace JSON, --json, /trace.json, wit
test/cli.test.ts CLI, child process and dev server spec (fixtures in test/fixtures)
test/write.test.ts writes a rendered letter through markup-generator and reads it back
scripts/generate.mjs prints explain() and writes generated/letter.html
scripts/add-bot-changeset.sh patch fragment for Renovate / Dependabot PRs
.changeset/ changeset fragments and config
.github/workflows/ci.yml
.github/workflows/publish.yml GitHub Packages on release, or a manual run
.github/workflows/add-changeset.yml manual fragment PR
.github/workflows/add-bot-changeset.yml patch fragment on bot dependency PRs
.github/workflows/changesets.yml Version packages PR, then tag + Release
.github/workflows/publish.yml GitHub Packages on release, dispatch, or a manual run
llms.txt short index for agents
llms-full.txt runtime contract and fragment props
tsup.config.ts ESM + CJS + IIFE, dts, sourcemaps
Expand Down Expand Up @@ -177,5 +186,5 @@ Use it to render a whole HTML email, to run a batch of templates that share one
- Node: `engines.node` is `>=24`. CI runs on Node 24 and newer (currently 24 and 26).
- Do not lower coverage thresholds or `noUncheckedIndexedAccess`.
- Docs: extend or annotate outdated guidance; do not delete existing docs content.
- Release: GitHub Release (or manual `publish.yml`) publishes to GitHub Packages under `@llazyemail`.
- Workflows that run `npm ci` (CI, ESLint, Generate, Publish) configure `https://npm.pkg.github.com` for the `@llazyemail` scope and pass `NODE_AUTH_TOKEN: secrets.GITHUB_TOKEN` with `packages: read`. Keep that in any new workflow that installs dependencies.
- Release: add a changeset (`npm run changeset` or the Add changeset workflow). Push to `main` opens a Version packages PR. Merging that PR tags `@llazyemail/template-runtime-display@<version>`, creates the GitHub Release, and dispatches `publish.yml` to GitHub Packages under `@llazyemail`.
- Workflows that run `npm ci` (CI, ESLint, Generate, Publish, Version packages) configure `https://npm.pkg.github.com` for the `@llazyemail` scope and pass `NODE_AUTH_TOKEN: secrets.GITHUB_TOKEN` with `packages: read`. Keep that in any new workflow that installs dependencies.
Loading