mirror of
https://github.com/expo/eas-cli.git
synced 2026-11-15 17:31:46 -10:00
* [ci] Version packages and generate changelogs with changesets PRs now add a changeset in .changeset/ instead of editing CHANGELOG.md. The manual release workflow runs scripts/src/versionPackages.ts, which runs `changeset version` for one fixed group of all packages, writes the root CHANGELOG.md section with the existing emoji categories, and then commits, tags, and pushes vX.Y.Z. The tag-driven publish is unchanged, except that it reads the changelog section from the tagged commit. The PR check validates changesets with @changesets/parse and rejects direct CHANGELOG.md edits. The "no changelog" label still skips it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Correct "no changelog" documentation in .changeset/README.md * [ci] Fail on CHANGELOG.md edits even with the "no changelog" label Co-Authored-By: Claude Opus 5.5 <[email protected]> * [ci] Skip the changeset check for Dependabot PRs Dependabot PRs only update dependencies, so they need no changeset, and their read-only token cannot post the PR comment. The job skips both for them. The CHANGELOG.md check still runs. The workflow now sets explicit token permissions. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Remove the "## main" block from CHANGELOG.md Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
106 lines
3.9 KiB
TypeScript
106 lines
3.9 KiB
TypeScript
/* eslint-disable no-console */
|
|
|
|
import { getReleasePlan } from '@changesets/get-release-plan';
|
|
import { getCommitsThatAddFiles } from '@changesets/git';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
import { getAttributionAsync } from '../../.changeset/changelog.mjs';
|
|
import { formatEntry } from '../../.changeset/formatEntry.mjs';
|
|
import { ROOT_DIR, readPackageDirsByNameAsync } from './changesets/packages.js';
|
|
import {
|
|
type RootEntry,
|
|
formatPackagePrefix,
|
|
getHighestBumpType,
|
|
getSharedVersion,
|
|
insertRootSection,
|
|
renderRootSection,
|
|
} from './changesets/rootChangelog.js';
|
|
|
|
const ROOT_CHANGELOG_PATH = path.join(ROOT_DIR, 'CHANGELOG.md');
|
|
const LERNA_JSON_PATH = path.join(ROOT_DIR, 'lerna.json');
|
|
|
|
function run(command: string, args: string[]): string {
|
|
return execFileSync(command, args, { cwd: ROOT_DIR, encoding: 'utf8' });
|
|
}
|
|
|
|
function runWithOutput(command: string, args: string[]): void {
|
|
execFileSync(command, args, { cwd: ROOT_DIR, stdio: 'inherit' });
|
|
}
|
|
|
|
function isPublishingRun(): boolean {
|
|
const userName = run('git', ['config', 'get', '--global', 'user.name']).trim();
|
|
const userEmail = run('git', ['config', 'get', '--global', 'user.email']).trim();
|
|
return (
|
|
userName === 'Expo CI' &&
|
|
userEmail === '[email protected]' &&
|
|
process.env.INPUT_DRY_RUN !== 'true'
|
|
);
|
|
}
|
|
|
|
async function buildRootEntriesAsync(): Promise<{ version: string; entries: RootEntry[] }> {
|
|
const releasePlan = await getReleasePlan(ROOT_DIR);
|
|
if (releasePlan.changesets.length === 0) {
|
|
throw new Error('There are no changesets in .changeset/. Nothing to release.');
|
|
}
|
|
const version = getSharedVersion(releasePlan.releases);
|
|
const dirByPackageName = await readPackageDirsByNameAsync();
|
|
const commits = await getCommitsThatAddFiles(
|
|
releasePlan.changesets.map(changeset => `.changeset/${changeset.id}.md`),
|
|
{ cwd: ROOT_DIR }
|
|
);
|
|
const entries = await Promise.all(
|
|
releasePlan.changesets.map(async (changeset, index) => {
|
|
const attribution = await getAttributionAsync({ ...changeset, commit: commits[index] });
|
|
const prefix = formatPackagePrefix(changeset.releases, dirByPackageName);
|
|
const text = formatEntry(changeset.summary, attribution);
|
|
return {
|
|
bumpType: getHighestBumpType(changeset.releases),
|
|
text: prefix ? `${prefix} ${text}` : text,
|
|
};
|
|
})
|
|
);
|
|
return { version, entries };
|
|
}
|
|
|
|
async function updateLernaVersionAsync(version: string): Promise<void> {
|
|
const lernaJson = JSON.parse(await readFile(LERNA_JSON_PATH, 'utf8'));
|
|
lernaJson.version = version;
|
|
await writeFile(LERNA_JSON_PATH, `${JSON.stringify(lernaJson, null, 2)}\n`);
|
|
}
|
|
|
|
async function updateRootChangelogAsync(section: string): Promise<void> {
|
|
const changelog = await readFile(ROOT_CHANGELOG_PATH, 'utf8');
|
|
await writeFile(ROOT_CHANGELOG_PATH, insertRootSection(changelog, section));
|
|
}
|
|
|
|
async function mainAsync(): Promise<void> {
|
|
const { version, entries } = await buildRootEntriesAsync();
|
|
const date = new Date().toISOString().slice(0, 10);
|
|
const section = renderRootSection(version, date, entries);
|
|
|
|
runWithOutput('yarn', ['changeset', 'version']);
|
|
await updateLernaVersionAsync(version);
|
|
runWithOutput('yarn', ['install', '--mode=update-lockfile']);
|
|
runWithOutput('yarn', ['workspace', 'eas-cli', 'run', 'version']);
|
|
await updateRootChangelogAsync(section);
|
|
|
|
const tag = `v${version}`;
|
|
if (!isPublishingRun()) {
|
|
console.log(`Dry run: ${tag} was not committed, tagged, or pushed.\n`);
|
|
console.log(section);
|
|
runWithOutput('git', ['status', '--short']);
|
|
return;
|
|
}
|
|
runWithOutput('git', ['add', '--all']);
|
|
runWithOutput('git', ['commit', '--message', tag]);
|
|
runWithOutput('git', ['tag', '--annotate', tag, '--message', tag]);
|
|
runWithOutput('git', ['push', '--atomic', '--no-verify', 'origin', 'main', tag]);
|
|
}
|
|
|
|
mainAsync().catch(error => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|