Skip to content

[Release] Version packages (beta) #1675

[Release] Version packages (beta)

[Release] Version packages (beta) #1675

name: Changeset Auto Release Checkbox

Check warning on line 1 in .github/workflows/changeset-auto-release.yml

View workflow run for this annotation

GitHub Actions / Changeset Auto Release Checkbox

Workflow execution policy warning (evaluate mode)

On November 2, 2026, GitHub will restrict `pull_request_target` on public repositories by default. To continue allowing the event trigger, configure an Actions policy. Learn more: https://gh.io/securely-using-pull_request_target#default-policy-for-pull_request_target
on:
pull_request:
types: [opened, reopened, synchronize, edited]
pull_request_target:
types: [opened, reopened, synchronize, edited]
permissions:
contents: read
pull-requests: write
jobs:
sync-auto-release-checkbox:
name: Sync auto-release checkbox
runs-on: ubuntu-latest
if: >-
github.repository == 'udecode/plate' && (
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository) ||
(github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository)
)
steps:
- name: 📥 Checkout workflow helper
uses: actions/checkout@v4
with:
ref: >-
${{
github.event_name == 'pull_request'
&& github.event.pull_request.head.sha
|| github.event.repository.default_branch
}}
persist-credentials: false
- name: 🔁 Sync auto-release checkbox
uses: actions/github-script@v7
with:
script: |
const { readFile } = await import('node:fs/promises');
const { resolve } = await import('node:path');
const { pathToFileURL } = await import('node:url');
const helperUrl = pathToFileURL(
`${process.env.GITHUB_WORKSPACE}/tooling/scripts/auto-release-pr.mjs`
).href;
const {
getChangesetReleaseType,
shouldManageAutoReleaseBlock,
upsertAutoReleaseBlock,
} = await import(helperUrl);
const pullRequest = context.payload.pull_request;
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
per_page: 100,
});
const headRepository = pullRequest.head.repo;
const isHeadCheckedOut = headRepository?.full_name === context.payload.repository.full_name;
const filesWithContents = [];
for (const file of files) {
const isChangeset =
file.filename.startsWith('.changeset/') &&
file.filename.endsWith('.md') &&
file.filename !== '.changeset/README.md' &&
file.status !== 'removed';
if (!isChangeset) {
filesWithContents.push(file);
continue;
}
let contents;
if (isHeadCheckedOut) {
contents = await readFile(
resolve(process.env.GITHUB_WORKSPACE, file.filename),
'utf8'
);
} else {
const { data } = await github.rest.repos.getContent({
owner: headRepository?.owner.login ?? context.repo.owner,
repo: headRepository?.name ?? context.repo.repo,
path: file.filename,
ref: pullRequest.head.sha,
});
if (Array.isArray(data) || data.type !== 'file' || data.encoding !== 'base64') {
throw new Error(`Could not read ${file.filename} from the pull request head.`);
}
contents = Buffer.from(data.content, 'base64').toString('utf8');
}
filesWithContents.push({ ...file, contents });
}
const hasChangeset = shouldManageAutoReleaseBlock({
files: filesWithContents,
title: pullRequest.title ?? '',
});
const releaseType = hasChangeset
? getChangesetReleaseType(filesWithContents)
: null;
const currentBody = pullRequest.body ?? '';
const nextBody = upsertAutoReleaseBlock(currentBody, {
defaultChecked: releaseType === 'patch',
hasChangeset,
});
if (nextBody === currentBody) {
core.info('PR body already matches auto-release policy.');
return;
}
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
body: nextBody,
});