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
3 changes: 3 additions & 0 deletions .github/workflows/changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ concurrency:
jobs:
changeset:
# The Version Packages PR from release.yml consumes changesets, so it never has one.
# Dependabot PRs get theirs from dependabot-changeset.yml; its push uses GITHUB_TOKEN,
# which doesn't re-trigger this workflow, so checking them here would stay red.
if: >-
!startsWith(github.head_ref, 'changeset-release/') &&
github.event.pull_request.user.login != 'dependabot[bot]' &&
!contains(github.event.pull_request.labels.*.name, 'no-changeset')
runs-on: ubuntu-latest
steps:
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/dependabot-changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Dependabot changeset

# Dependabot doesn't know about Changesets, so its PRs would always fail the changeset
# check in changeset.yml (which skips them). This writes a patch changeset for the
# packages a Dependabot PR touches and pushes it to the PR branch.
#
# pull_request_target is needed because Dependabot-triggered pull_request runs only get a
# read-only token. It runs with write access, so it must never execute code from the PR:
# no install, build or package scripts, only git and reading package.json as data.
on:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened]

permissions:
contents: read

concurrency:
group: dependabot-changeset-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
changeset:
if: >-
github.event.pull_request.user.login == 'dependabot[bot]' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Add changeset if missing
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
set -euo pipefail
git fetch --no-tags origin main

if git diff --name-only --diff-filter=A origin/main...HEAD -- '.changeset/*.md' | grep -qv '^.changeset/README.md$'; then
echo "PR already has a changeset."
exit 0
fi

# Same scope changeset.yml enforces: anything under packages/*, plus root
# workspace/lockfile changes (security overrides), which ship as patch releases.
changed=$(git diff --name-only origin/main...HEAD)
dirs=$(printf '%s\n' "$changed" | sed -n 's#^packages/\([^/]*\)/.*#\1#p' | sort -u)
root=$(printf '%s\n' "$changed" | grep -E '^(pnpm-workspace\.yaml|pnpm-lock\.yaml)$' || true)

packages=()
for dir in $dirs; do
if [ -f "packages/$dir/package.json" ]; then
packages+=("$(jq -r .name "packages/$dir/package.json")")
fi
done
# Lockfile-only bumps don't map to a package; core is in the fixed release group,
# so bumping it releases every published package.
if [ ${#packages[@]} -eq 0 ] && [ -n "$root" ]; then
packages+=("@crypt.fyi/core")
fi
if [ ${#packages[@]} -eq 0 ]; then
echo "No package or lockfile changes; no changeset needed."
exit 0
fi

file=".changeset/dependabot-${PR_NUMBER}.md"
{
echo '---'
for pkg in "${packages[@]}"; do
echo "'$pkg': patch"
done
echo '---'
echo
printf '%s\n' "$PR_TITLE" | sed 's/^chore(deps[^)]*): //; s/^./\U&/'
} > "$file"
cat "$file"

git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add "$file"
git commit -m "chore: add changeset for Dependabot PR #${PR_NUMBER}"
git push origin "HEAD:refs/heads/${HEAD_REF}"
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pnpm release # build, publish npm packages, tag, upload Chrome extens

On `main`, `.github/workflows/release.yml` opens a Version Packages PR or runs `pnpm release`.

Pull requests must include a changeset when they change files under `packages/*` or the root `pnpm-workspace.yaml` / `pnpm-lock.yaml` (dependency and security override bumps ship as patch releases). `.github/workflows/changeset.yml` enforces this. For changes that don't need a release (docs, tests, CI), run `pnpm changeset --empty` or ask a maintainer to add the `no-changeset` label.
Pull requests must include a changeset when they change files under `packages/*` or the root `pnpm-workspace.yaml` / `pnpm-lock.yaml` (dependency and security override bumps ship as patch releases). `.github/workflows/changeset.yml` enforces this. For changes that don't need a release (docs, tests, CI), run `pnpm changeset --empty` or ask a maintainer to add the `no-changeset` label. Dependabot PRs are exempt from that check: `.github/workflows/dependabot-changeset.yml` pushes a patch changeset to them instead.

## Pull Request Process

Expand Down
Loading