-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: revert to semantic-release-monorepo (#1536)
`@anolilab/multi-semantic-release` does not cause semantic release to check the commits of each package before working out if anything has changed so creates unecessary comments on long-closed github issues. `semantic-release-monorepo` did not do this and has been updated to be ESM-compatible recently so switch back to that. BREAKING CHANGE: if using `aegir release` in the scripts of a monorepo package, config must be updated: 1. Change `"release": "aegir release"` in the monorepo root to `"release": "aegir run release"` 2. Add `"release": "aegir release"` to each monorepo package 3. Add semantic release config to each monorepo package
- Loading branch information
1 parent
a020beb
commit 00bebd4
Showing
7 changed files
with
187 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import path from 'path' | ||
import { execa } from 'execa' | ||
import fs from 'fs-extra' | ||
import Listr from 'listr' | ||
import { calculateSiblingVersion } from './check-project/utils.js' | ||
import { isMonorepoRoot, getSubprojectDirectories, pkg } from './utils.js' | ||
|
||
/** | ||
* @typedef {import("./types.js").GlobalOptions} GlobalOptions | ||
* @typedef {import("./types.js").ReleaseOptions} ReleaseOptions | ||
* @typedef {import("listr").ListrTaskWrapper} Task | ||
*/ | ||
|
||
const tasks = new Listr([ | ||
{ | ||
title: 'align sibling dependency versions', | ||
enabled: () => isMonorepoRoot(), | ||
/** | ||
* @param {GlobalOptions & ReleaseOptions} ctx | ||
*/ | ||
task: async (ctx) => { | ||
const rootDir = process.cwd() | ||
const workspaces = pkg.workspaces | ||
|
||
if (!workspaces || !Array.isArray(workspaces)) { | ||
throw new Error('No monorepo workspaces found') | ||
} | ||
|
||
const { | ||
siblingVersions, | ||
packageDirs | ||
} = await calculateSiblingVersions(rootDir, workspaces) | ||
|
||
// check these dependency types for monorepo siblings | ||
const dependencyTypes = [ | ||
'dependencies', | ||
'devDependencies', | ||
'peerDependencies', | ||
'optionalDependencies' | ||
] | ||
|
||
// align the versions of siblings in each package | ||
for (const packageDir of packageDirs) { | ||
const manifestPath = path.join(packageDir, 'package.json') | ||
const manifest = fs.readJSONSync(path.join(packageDir, 'package.json')) | ||
|
||
for (const type of dependencyTypes) { | ||
for (const [dep, version] of Object.entries(siblingVersions)) { | ||
if (manifest[type] != null && manifest[type][dep] != null && manifest[type][dep] !== version) { | ||
console.info('Update', type, dep, manifest[type][dep], '->', version) // eslint-disable-line no-console | ||
manifest[type][dep] = version | ||
} | ||
} | ||
} | ||
|
||
fs.writeJSONSync(manifestPath, manifest, { | ||
spaces: 2 | ||
}) | ||
} | ||
|
||
// all done, commit changes and push to remote | ||
const status = await execa('git', ['status', '--porcelain'], { | ||
cwd: rootDir | ||
}) | ||
|
||
if (status.stdout === '') { | ||
// no changes, nothing to do | ||
return | ||
} | ||
|
||
if (!process.env.CI) { | ||
console.info('CI env var is not set, not pushing to git') // eslint-disable-line no-console | ||
return | ||
} | ||
|
||
// When running on CI, set the commits author and commiter info and prevent the `git` CLI to prompt for username/password. | ||
// Borrowed from `semantic-release` | ||
process.env.GIT_AUTHOR_NAME = ctx.siblingDepUpdateName | ||
process.env.GIT_AUTHOR_EMAIL = ctx.siblingDepUpdateEmail | ||
process.env.GIT_COMMITTER_NAME = ctx.siblingDepUpdateName | ||
process.env.GIT_COMMITTER_EMAIL = ctx.siblingDepUpdateEmail | ||
process.env.GIT_ASKPASS = 'echo' | ||
process.env.GIT_TERMINAL_PROMPT = '0' | ||
|
||
console.info(`Commit with message "${ctx.siblingDepUpdateMessage}"`) // eslint-disable-line no-console | ||
|
||
await execa('git', ['add', '-A'], { | ||
cwd: rootDir | ||
}) | ||
await execa('git', ['commit', '-m', ctx.siblingDepUpdateMessage], { | ||
cwd: rootDir | ||
}) | ||
console.info('Push to remote') // eslint-disable-line no-console | ||
await execa('git', ['push'], { | ||
cwd: rootDir | ||
}) | ||
} | ||
} | ||
], { renderer: 'verbose' }) | ||
|
||
/** | ||
* @param {string} rootDir | ||
* @param {string[]} workspaces | ||
*/ | ||
async function calculateSiblingVersions (rootDir, workspaces) { | ||
const packageDirs = [] | ||
|
||
/** @type {Record<string, string>} */ | ||
const siblingVersions = {} | ||
|
||
for (const subProjectDir of await getSubprojectDirectories(rootDir, workspaces)) { | ||
const pkg = JSON.parse(fs.readFileSync(path.join(subProjectDir, 'package.json'), { | ||
encoding: 'utf-8' | ||
})) | ||
|
||
siblingVersions[pkg.name] = calculateSiblingVersion(pkg.version) | ||
packageDirs.push(subProjectDir) | ||
} | ||
|
||
return { | ||
packageDirs, | ||
siblingVersions | ||
} | ||
} | ||
|
||
export default tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import alignVersions from '../align-versions.js' | ||
import { loadUserConfig } from '../config/user.js' | ||
|
||
/** | ||
* @typedef {import("yargs").Argv} Argv | ||
* @typedef {import("yargs").Arguments} Arguments | ||
* @typedef {import("yargs").CommandModule} CommandModule | ||
*/ | ||
|
||
/** @type {CommandModule} */ | ||
export default { | ||
command: 'align-versions', | ||
describe: 'Align monorepo sibling dependency versions', | ||
/** | ||
* @param {Argv} yargs | ||
*/ | ||
builder: async (yargs) => { | ||
const userConfig = await loadUserConfig() | ||
|
||
return yargs | ||
.options({ | ||
siblingDepUpdateMessage: { | ||
alias: 'm', | ||
type: 'string', | ||
describe: 'The commit message to use when updating sibling dependencies', | ||
default: userConfig.release.siblingDepUpdateMessage | ||
}, | ||
siblingDepUpdateName: { | ||
type: 'string', | ||
describe: 'The user name to use when updating sibling dependencies', | ||
default: userConfig.release.siblingDepUpdateName | ||
}, | ||
siblingDepUpdateEmail: { | ||
type: 'string', | ||
describe: 'The email to use when updating sibling dependencies', | ||
default: userConfig.release.siblingDepUpdateEmail | ||
} | ||
}) | ||
}, | ||
/** | ||
* @param {any} argv | ||
*/ | ||
async handler (argv) { | ||
await alignVersions.run(argv) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.