Skip to content

Commit

Permalink
docs: update global changelog with changesets files (#2518)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Mar 21, 2024
1 parent 57648ba commit 1f952c3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 2.0.0

Release date: Thu Mar 21 2024

---

## Version 2.0.0-next.18

Release date: Thu Mar 21 2024
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/changelog.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 2.0.0

Release date: Thu Mar 21 2024

---

## Version 2.0.0-next.18

Release date: Thu Mar 21 2024
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"prettier:check": "prettier --check '**/*.{ts,tsx,css,md,mdx,sol}'",
"release:check": "changeset status --verbose --since=origin/main",
"release:publish": "pnpm install && pnpm build && changeset publish",
"release:version": "changeset version && pnpm install --lockfile-only",
"release:version": "changeset version && pnpm install --lockfile-only && pnpm run changelog:generate",
"sort-package-json": "npx sort-package-json package.json 'packages/*/package.json' 'templates/*/package.json' 'templates/*/packages/*/package.json' 'examples/*/package.json' 'examples/*/packages/*/package.json' 'e2e/*/package.json' 'e2e/*/packages/*/package.json' 'docs/package.json'",
"test": "pnpm run --recursive --filter=!@latticexyz/services test",
"test:ci": "pnpm run --recursive --parallel --filter=!@latticexyz/services test:ci",
Expand All @@ -39,13 +39,15 @@
"devDependencies": {
"@arktype/attest": "0.6.4",
"@changesets/cli": "^2.26.1",
"@types/glob": "^7.2.0",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
"bun": "^1.0.11",
"chalk": "^5.2.0",
"eslint": "8.57.0",
"execa": "^7.0.0",
"glob": "^8.0.3",
"husky": ">=6",
"lint-staged": ">=10",
"prettier": "3.2.5",
Expand Down
22 changes: 6 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions scripts/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import { execa } from "execa";
import { readFileSync, writeFileSync } from "node:fs";
import path from "path";
import glob from "glob";

//--------- CONSTANTS

const REPO_URL = process.env.REPO_URL ?? "https://github.com/latticexyz/mud";
const CHANGELOG_PATH = process.env.CHANGELOG_PATH ?? "CHANGELOG.md";
const CHANGELOG_DOCS_PATH = process.env.CHANGELOG_DOCS_PATH ?? "docs/pages/changelog.mdx";
const VERSION_PATH = process.env.VERSION_PATH ?? path.join(process.cwd(), "packages/world/package.json");
const INCLUDE_CHANGESETS = (process.env.INCLUDE_CHANGESETS as "diff" | "all") ?? "diff"; // "diff" to only include new changesets, "all" to use all changesets in pre.json
const INCLUDE_CHANGESETS = (process.env.INCLUDE_CHANGESETS as "diff" | "all") ?? "diff"; // "diff" to only include new changesets, "all" to use all changesets

enum ChangeType {
PATCH,
Expand Down Expand Up @@ -95,24 +96,24 @@ async function getVersion() {
}

async function getChanges(include: "diff" | "all") {
const changesetsToInclude: string[] = [];
let changesetsToInclude: string[] = [];

if (include === "diff") {
// Get the diff of the current branch to main
const changesetDiff = (await execa("git", ["diff", "main", ".changeset/pre.json"])).stdout;

// Get the list of changesets
const addedLinesRegex = /\+\s+"(?!.*:)([^"]+)"/g;
changesetsToInclude.push(...[...changesetDiff.matchAll(addedLinesRegex)].map((match) => match[1]));
// --diff-filter=d excludes deleted files from diff (changesets deletes these files after release)
changesetsToInclude = (await execa("git", ["diff", "--name-only", "--diff-filter=d", "main", ".changeset"])).stdout
.trim()
.split(/\s+/)
.map((filename) => filename.trim())
.filter((filename) => /.md$/.test(filename));
} else if (include === "all") {
// Load all current changesets from the .changeset/pre.json file
changesetsToInclude.push(...(await import(path.join(process.cwd(), ".changeset/pre.json"))).default.changesets);
// Load all current changesets from the .changeset dir
changesetsToInclude = glob.sync(".changeset/*.md");
}

// Load the contents of each changeset and metadata from git
const changesetContents = await Promise.all(
changesetsToInclude.map(async (addedChangeset) => {
const changesetPath = `.changeset/${addedChangeset}.md`;
changesetsToInclude.map(async (changesetPath) => {
const changeset = readFileSync(changesetPath).toString();
const gitLog = (await execa("git", ["log", changesetPath])).stdout;
return { ...parseChangeset(changeset), ...parseGitLog(gitLog) };
Expand Down

0 comments on commit 1f952c3

Please sign in to comment.