Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Move to changeset #5241

Merged
merged 22 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
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.0.2/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["@fast-check/examples", "website"]
}
18 changes: 0 additions & 18 deletions .github/workflows/build-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,6 @@ jobs:
check-latest: true
- name: Ensure no dedupe required
run: yarn dedupe --check
all_version_bump_declared:
name: 'All version bump declared'
needs: warmup_yarn_cache
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.pull_request.user.login != 'renovate[bot]'
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Using Node v20.x
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: '20.x'
cache: 'yarn'
cache-dependency-path: yarn.lock
check-latest: true
- name: Ensure versions have been properly bumped
run: yarn version check
package_quality:
name: 'Package quality'
needs: warmup_yarn_cache
Expand Down
75 changes: 40 additions & 35 deletions .github/workflows/scripts/generate-changelog.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const {
promises: { readFile, writeFile },
promises: { readFile, writeFile, rm },
existsSync,
} = require('fs');
const path = require('path');
Expand Down Expand Up @@ -189,45 +189,36 @@ function isInitialTag(tagName) {
return tagName.endsWith('v0.0.0');
}

/**
* Extract the kind of release
* @param {string} oldTagName
* @param {string} newTagName
* @returns {'major'|'minor'|'patch'}
*/
function extractReleaseKind(oldTagName, newTagName) {
const oldTagVersion = extractMajorMinorPatch(oldTagName);
const newTagVersion = extractMajorMinorPatch(newTagName);
const releaseKind =
newTagVersion.major !== oldTagVersion.major
? 'major'
: newTagVersion.minor !== oldTagVersion.minor
? 'minor'
: 'patch';
return releaseKind;
}

/**
* @returns {Promise<{branchName:string, commitName:string, errors:string[], changelogs: string[]}>}
*/
async function run() {
const allErrors = [];

// Get packages to be bumped via yarn
const { stdout: yarnOut } = await execFile('yarn', ['version', 'apply', '--all', '--dry-run', '--json']);
const allBumps = yarnOut
.split('\n')
.filter((line) => line.trim().length !== 0)
.map((line) => JSON.parse(line));
// Get packages to be bumped via changeset
const temporaryChangelogFile = 'changelog.json';
await execFile('yarn', ['changeset', 'status', `--output=${temporaryChangelogFile}`]);
const temporaryChangelogFileContentBuffer = await readFile(temporaryChangelogFile);
const temporaryChangelogFileContent = JSON.parse(temporaryChangelogFileContentBuffer.toString());
await rm(temporaryChangelogFile);
// Array of {name, type, oldVersion, newVersion, changesets}
const allBumps = await Promise.all(
temporaryChangelogFileContent.releases
.filter((entry) => entry.type !== 'none')
.map(async (entry) => {
// Extracting the location of the package from the workspace
const { stdout: packageLocationUnsafe } = await execFile('yarn', ['workspace', entry.name, 'exec', 'pwd']);
const packageLocation = packageLocationUnsafe.split('\n')[0].trim();
return { ...entry, packageLocation };
}),
);

for (const packageBump of allBumps) {
const { oldVersion, newVersion, cwd: packageLocation, ident: packageName } = packageBump;
for (const { oldVersion, newVersion, name: packageName, type: releaseKind, packageLocation } of allBumps) {
console.debug(`[debug] Checking ${packageName} between version ${oldVersion} and version ${newVersion}`);

// Extract metas for changelog
const oldTag = computeTag(oldVersion, packageName);
const newTag = computeTag(newVersion, packageName);
const releaseKind = extractReleaseKind(oldTag, newTag);
console.debug(`[debug] Checking ${packageName} between tag ${oldTag} and tag ${newTag}`);
const { breakingSection, newFeaturesSection, maintenanceSection, errors } = await extractAndParseDiff(
oldTag,
Expand Down Expand Up @@ -274,16 +265,30 @@ async function run() {
const previousContent = existsSync(changelogPath) ? await readFile(changelogPath) : '';
await writeFile(changelogPath, `${body}\n\n${releaseKind !== 'patch' ? `---\n\n` : ''}${previousContent}`);
await execFile('git', ['add', changelogPath]);
}

// Bump towards latest version and add files for upcoming commit
await execFile('yarn', ['version', 'apply', '--all']);
for (const packageBump of allBumps) {
const { cwd: packageLocation } = packageBump;
// Update the package.json
await execFile('npm', ['--no-git-tag-version', '--workspaces-update=false', 'version', releaseKind], {
cwd: packageLocation,
});
const packageJsonPath = path.join(packageLocation, 'package.json');
await execFile('git', ['add', packageJsonPath]);
}
await execFile('git', ['add', '.yarn/versions']);

// Force yarn reinstall
await execFile('yarn');
await execFile('git', ['add', 'yarn.lock']);

// Drop all changesets
const alreadyDeleted = new Set();
for (const { changesets } of allBumps) {
for (const changeset of changesets) {
if (alreadyDeleted.has(changeset)) {
continue;
}
alreadyDeleted.add(changeset);
await execFile('git', ['rm', `.changeset/${changeset}.md`]);
}
}

// Create another branch and commit on it
const branchName = `changelog-${Math.random().toString(16).substring(2)}`;
Expand All @@ -294,7 +299,7 @@ async function run() {

// Compute the list of all impacted changelogs
const changelogs = allBumps
.map((b) => b.cwd.substring(process.cwd().length + 1).replace(/\\/g, '/'))
.map((b) => b.packageLocation.substring(process.cwd().length + 1).replace(/\\/g, '/'))
.map(
(packageRelativePath) =>
`https://github.com/dubzzz/fast-check/blob/${branchName}/${packageRelativePath}/CHANGELOG.md`,
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.changeset/
.yarn/
packages/*/coverage/
packages/*/dist/
Expand Down
4 changes: 0 additions & 4 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@ enableGlobalCache: true
enableScripts: false
nodeLinker: pnp
enableHardenedMode: false

changesetIgnorePatterns:
- '**/*.spec.{js,ts}'

yarnPath: .yarn/releases/yarn-4.4.1.cjs
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
"lint": "eslint . --fix",
"lint:check": "eslint .",
"publint:all": "yarn workspaces foreach --all -pvi --no-private exec publint --strict",
"bump": "yarn version check --interactive",
"bump": "changeset",
"pack:all": "yarn workspaces foreach --all -pvi --no-private pack --out package.tgz",
"unpack:all": "yarn workspaces foreach --all -pvi --no-private exec tar -xf package.tgz --strip-components=1 --exclude='package/package.json'"
},
"devDependencies": {
"@changesets/cli": "^2.27.7",
"@eslint/js": "^9.9.0",
"@fast-check/packaged": "*",
"@typescript-eslint/utils": "^7.18.0",
Expand Down
Loading
Loading