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
7 changes: 6 additions & 1 deletion .github/scripts/release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ if (!version) {
// An entry that several packages list goes under the first of these areas that lists it.
const areaOfPackage = {app: 'App', store: 'Store', theme: 'Theme'}
const areas = ['App', 'Store', 'Theme', 'CLI']
// Only the packages that release together share the release's version. A package outside the
// fixed group can have an old changelog section with the same version number.
const releasedPackages = new Set(JSON.parse(readFileSync('.changeset/config.json', 'utf8')).fixed.flat())
// Stable lines keep changesets' default formatter, which starts each entry with a commit hash.
const commitPrefix = /^[0-9a-f]{7}: /

Expand Down Expand Up @@ -51,7 +54,9 @@ const entriesByArea = new Map(areas.map((area) => [area, []]))
const seen = new Set()
for (const directory of packageDirectories) {
const changelogPath = join('packages', directory, 'CHANGELOG.md')
if (!existsSync(changelogPath)) continue
const manifestPath = join('packages', directory, 'package.json')
if (!existsSync(changelogPath) || !existsSync(manifestPath)) continue
if (!releasedPackages.has(JSON.parse(readFileSync(manifestPath, 'utf8')).name)) continue
for (const entry of changelogEntries(readFileSync(changelogPath, 'utf8'))) {
if (seen.has(entry)) continue
seen.add(entry)
Expand Down
88 changes: 88 additions & 0 deletions .github/scripts/release-notes.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Tests for release-notes.js. Run from the CLI's root with:
// node --test .github/scripts/release-notes.test.mjs
import assert from 'node:assert/strict'
import {execFileSync} from 'node:child_process'
import {mkdirSync, mkdtempSync, rmSync, writeFileSync} from 'node:fs'
import {tmpdir} from 'node:os'
import {dirname, join} from 'node:path'
import {fileURLToPath} from 'node:url'
import {afterEach, test} from 'node:test'

const script = join(dirname(fileURLToPath(import.meta.url)), 'release-notes.js')
const scratchDirs = []
afterEach(() => {
for (const dir of scratchDirs.splice(0)) rmSync(dir, {recursive: true, force: true})
})

// A repository root with `.changeset/config.json` and one directory per package under `packages`.
function repo({fixed, packages}) {
const root = mkdtempSync(join(tmpdir(), 'release-notes-'))
scratchDirs.push(root)
mkdirSync(join(root, '.changeset'))
writeFileSync(join(root, '.changeset/config.json'), JSON.stringify({fixed: [fixed]}))
for (const [directory, {name, changelog}] of Object.entries(packages)) {
mkdirSync(join(root, 'packages', directory), {recursive: true})
writeFileSync(join(root, 'packages', directory, 'package.json'), JSON.stringify({name}))
writeFileSync(join(root, 'packages', directory, 'CHANGELOG.md'), changelog)
}
return root
}

const releaseNotes = (root, version) => execFileSync('node', [script, version], {cwd: root, encoding: 'utf8'})

test('groups each entry once by area and leaves out dependency updates', () => {
const root = repo({
fixed: ['@shopify/cli', '@shopify/app', '@shopify/cli-kit'],
packages: {
app: {
name: '@shopify/app',
changelog:
'# @shopify/app\n\n## 5.2.0\n\n### Minor Changes\n\n- Add `shopify app logs`.\n- Shared entry.\n\n### Patch Changes\n\n- Updated dependencies\n - @shopify/cli-kit@5.2.0\n\n## 5.1.0\n\n- Older entry.\n',
},
cli: {
name: '@shopify/cli',
changelog: '# @shopify/cli\n\n## 5.2.0\n\n### Minor Changes\n\n- Shared entry.\n',
},
'cli-kit': {
name: '@shopify/cli-kit',
changelog: '# @shopify/cli-kit\n\n## 5.2.0\n\n### Patch Changes\n\n- abc1234: Revoke tokens on logout.\n',
},
},
})

assert.equal(
releaseNotes(root, '5.2.0'),
"## What's Changed\n\n### App\n* Add `shopify app logs`.\n* Shared entry.\n\n### CLI\n* Revoke tokens on logout.\n",
)
})

test('leaves out packages outside the fixed group, whose changelog can have the same version from long ago', () => {
const root = repo({
fixed: ['@shopify/cli'],
packages: {
cli: {
name: '@shopify/cli',
changelog: '# @shopify/cli\n\n## 5.2.0\n\n### Patch Changes\n\n- Revoke tokens on logout.\n',
},
'ui-extensions-server-kit': {
name: '@shopify/ui-extensions-server-kit',
changelog:
'# @shopify/ui-extensions-server-kit\n\n## 5.5.1\n\n- Newer entry.\n\n## 5.2.0\n\n### Minor Changes\n\n- 1d6fe3475: Increase minimum Node version to 18\n',
},
},
})

assert.equal(releaseNotes(root, '5.2.0'), "## What's Changed\n\n### CLI\n* Revoke tokens on logout.\n")
})

test('fails instead of printing partial notes when the fixed group is unknown', () => {
const packages = {cli: {name: '@shopify/cli', changelog: '# @shopify/cli\n\n## 5.2.0\n\n- An entry.\n'}}
const withoutFixed = repo({fixed: [], packages})
writeFileSync(join(withoutFixed, '.changeset/config.json'), '{}')
const withoutConfig = repo({fixed: [], packages})
rmSync(join(withoutConfig, '.changeset'), {recursive: true})

for (const root of [withoutFixed, withoutConfig]) {
assert.throws(() => execFileSync('node', [script, '5.2.0'], {cwd: root, stdio: 'pipe'}))
}
})
Loading