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

fix: update check-project to use semantic-release-monorepo again #1537

Merged
merged 1 commit into from
May 30, 2024
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
9 changes: 8 additions & 1 deletion src/align-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
* @param {GlobalOptions & ReleaseOptions} ctx
*/
task: async (ctx) => {
if (!process.env.CI) {
console.info('⚠ This run was not triggered in a known CI environment, running in dry-run mode.') // eslint-disable-line no-console
return
}

Check warning on line 28 in src/align-versions.js

View check run for this annotation

Codecov / codecov/patch

src/align-versions.js#L24-L28

Added lines #L24 - L28 were not covered by tests
const rootDir = process.cwd()
const workspaces = pkg.workspaces

Expand All @@ -46,6 +51,8 @@
const manifestPath = path.join(packageDir, 'package.json')
const manifest = fs.readJSONSync(path.join(packageDir, 'package.json'))

console.info('check project', manifest.name)

Check warning on line 55 in src/align-versions.js

View check run for this annotation

Codecov / codecov/patch

src/align-versions.js#L54-L55

Added lines #L54 - L55 were not covered by tests
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) {
Expand All @@ -71,7 +78,7 @@
}

if (!process.env.CI) {
console.info('CI env var is not set, not pushing to git') // eslint-disable-line no-console
// do not push to remote repo if in dry-run mode

Check warning on line 81 in src/align-versions.js

View check run for this annotation

Codecov / codecov/patch

src/align-versions.js#L81

Added line #L81 was not covered by tests
return
}

Expand Down
2 changes: 1 addition & 1 deletion src/check-project/check-monorepo-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
apiDocs = parseMarkdown(APIDOCS(pkg))
}

const structure = parseMarkdown(STRUCTURE(projectDir, projectDirs))
const structure = parseMarkdown(STRUCTURE(projectDir, projectDirs, webRoot))

Check warning on line 162 in src/check-project/check-monorepo-readme.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/check-monorepo-readme.js#L162

Added line #L162 was not covered by tests

readme.children = [
...header,
Expand Down
90 changes: 67 additions & 23 deletions src/check-project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@
const projectDirs = []
const webRoot = `${repoUrl}/tree/${branchName}`

const { releaseType } = await prompt.get({
properties: {
releaseType: {
description: 'Monorepo release type: semantic-release | release-please',
required: true,
conform: (value) => {
return ['semantic-release', 'release-please'].includes(value)
},
default: usesReleasePlease() ? 'release-please' : 'semantic-release'
}
}
})

if (releaseType !== 'release-please' && releaseType !== 'semantic-release') {
throw new Error('Invalid release type specified')
}

Check warning on line 134 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L118-L134

Added lines #L118 - L134 were not covered by tests
for (const subProjectDir of await getSubprojectDirectories(projectDir, workspaces)) {
const stat = await fs.stat(subProjectDir)

Expand All @@ -133,15 +150,30 @@

console.info('Found monorepo project', pkg.name)

await processModule(subProjectDir, pkg, branchName, repoUrl, homePage, ciFile, manifest)
await processModule({
projectDir: subProjectDir,
manifest: pkg,
branchName,
repoUrl,
homePage,
ciFile,
rootManifest: manifest,
releaseType
})

Check warning on line 162 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L153-L162

Added lines #L153 - L162 were not covered by tests

projectDirs.push(subProjectDir)
}

await alignMonorepoProjectDependencies(projectDirs)
await configureMonorepoProjectReferences(projectDirs)

let proposedManifest = await monorepoManifest(manifest, repoUrl, repoUrl, branchName)
let proposedManifest = await monorepoManifest({
manifest,
repoUrl,
homePage: repoUrl,
branchName,
releaseType
})

Check warning on line 176 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L170-L176

Added lines #L170 - L176 were not covered by tests
proposedManifest = sortManifest(proposedManifest)

await ensureFileHasContents(projectDir, 'package.json', JSON.stringify(proposedManifest, null, 2))
Expand Down Expand Up @@ -324,7 +356,9 @@
* @param {string} ciFile
*/
async function processProject (projectDir, manifest, branchName, repoUrl, ciFile) {
await processModule(projectDir, manifest, branchName, repoUrl, repoUrl, ciFile)
const releaseType = 'semantic-release'

await processModule({ projectDir, manifest, branchName, repoUrl, homePage: repoUrl, ciFile, releaseType })

Check warning on line 361 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L359-L361

Added lines #L359 - L361 were not covered by tests
await checkBuildFiles(projectDir, branchName, repoUrl)
}

Expand All @@ -336,16 +370,32 @@
}

/**
*
* @param {string} projectDir
* @param {any} manifest
* @param {string} branchName
* @param {string} repoUrl
* @param {string} homePage
* @param {string} ciFile
* @param {any} [rootManifest]
* @typedef {object} ProcessModuleContext
* @property {string} projectDir
* @property {any} manifest
* @property {string} branchName
* @property {string} repoUrl
* @property {string} homePage
* @property {string} ciFile
* @property {any} [rootManifest]
* @property {"semantic-release" | "release-please"} releaseType
*/

/**
* @typedef {object} ProcessManifestContext
* @property {any} manifest
* @property {string} branchName
* @property {string} repoUrl
* @property {string} homePage
* @property {"semantic-release" | "release-please"} releaseType
*/
async function processModule (projectDir, manifest, branchName, repoUrl, homePage = repoUrl, ciFile, rootManifest) {

/**
* @param {ProcessModuleContext} context
*/
async function processModule (context) {
const { projectDir, manifest, branchName, repoUrl, homePage = repoUrl, ciFile, rootManifest, releaseType } = context

Check warning on line 398 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L396-L398

Added lines #L396 - L398 were not covered by tests
if (!isAegirProject(manifest) && manifest.name !== 'aegir') {
throw new Error(`"${projectDir}" is not an aegir project`)
}
Expand Down Expand Up @@ -412,29 +462,23 @@

if (typescript) {
console.info('TypeScript project detected')
proposedManifest = await typescriptManifest(manifest, branchName, repoUrl, homePage)
proposedManifest = await typescriptManifest({ manifest, branchName, repoUrl, homePage, releaseType })

Check warning on line 465 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L465

Added line #L465 was not covered by tests
} else if (typedESM) {
console.info('Typed ESM project detected')
proposedManifest = await typedESMManifest(manifest, branchName, repoUrl, homePage)
proposedManifest = await typedESMManifest({ manifest, branchName, repoUrl, homePage, releaseType })

Check warning on line 468 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L468

Added line #L468 was not covered by tests
} else if (typedCJS) {
console.info('Typed CJS project detected')
proposedManifest = await typedCJSManifest(manifest, branchName, repoUrl, homePage)
proposedManifest = await typedCJSManifest({ manifest, branchName, repoUrl, homePage, releaseType })

Check warning on line 471 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L471

Added line #L471 was not covered by tests
} else if (untypedESM) {
console.info('Untyped ESM project detected')
proposedManifest = await untypedESMManifest(manifest, branchName, repoUrl, homePage)
proposedManifest = await untypedESMManifest({ manifest, branchName, repoUrl, homePage, releaseType })

Check warning on line 474 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L474

Added line #L474 was not covered by tests
} else if (untypedCJS) {
console.info('Untyped CJS project detected')
proposedManifest = await untypedCJSManifest(manifest, branchName, repoUrl, homePage)
proposedManifest = await untypedCJSManifest({ manifest, branchName, repoUrl, homePage, releaseType })

Check warning on line 477 in src/check-project/index.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/index.js#L477

Added line #L477 was not covered by tests
} else {
throw new Error('Cannot determine project type')
}

// remove release config from monorepo projects as multi-semantic-release
// wants it defined in the root manifest
if (rootManifest != null) {
proposedManifest.release = undefined
}

proposedManifest = sortManifest(proposedManifest)

await ensureFileHasContents(projectDir, 'package.json', JSON.stringify(proposedManifest, null, 2))
Expand Down
41 changes: 29 additions & 12 deletions src/check-project/manifests/monorepo.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
import { semanticReleaseConfig } from '../semantic-release-config.js'
import {
sortFields,
constructManifest
} from '../utils.js'

/**
* @param {any} manifest
* @param {string} repoUrl
* @param {string} homePage
* @param {string} branchName
* @param {import('../index.js').ProcessManifestContext} context
*/
export async function monorepoManifest (manifest, repoUrl, homePage, branchName) {
export async function monorepoManifest (context) {
const { manifest, repoUrl, homePage } = context

const scripts = {
...manifest.scripts
}

const devDependencies = manifest.devDependencies ?? {}

if (context.releaseType === 'semantic-release') {
scripts.release = 'run-s build npm:release docs'
scripts['npm:release'] = 'aegir run release'
scripts.docs = 'aegir docs'

delete manifest.release
devDependencies['npm-run-all'] = '^4.1.5'
}

if (context.releaseType === 'release-please') {
scripts.release = 'run-s build npm:release docs'
scripts['npm:release'] = 'aegir exec --bail false npm -- publish'
scripts['release:rc'] = 'aegir release-rc'
scripts.docs = 'aegir docs'

devDependencies['npm-run-all'] = '^4.1.5'
}

Check warning on line 35 in src/check-project/manifests/monorepo.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/monorepo.js#L10-L35

Added lines #L10 - L35 were not covered by tests
let proposedManifest = constructManifest(manifest, {
private: true,
release: (
Object.values(manifest.scripts ?? {})
.some(script => script.includes('semantic-release') || script.includes('aegir release'))
)
? semanticReleaseConfig(branchName)
: undefined
scripts

Check warning on line 38 in src/check-project/manifests/monorepo.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/monorepo.js#L38

Added line #L38 was not covered by tests
}, repoUrl, homePage)

const rest = {
Expand Down
25 changes: 19 additions & 6 deletions src/check-project/manifests/typed-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
const merge = mergeOptions.bind({ ignoreUndefined: true })

/**
* @param {any} manifest
* @param {string} branchName
* @param {string} repoUrl
* @param {string} [homePage]
* @param {import('../index.js').ProcessManifestContext} context
*/
export async function typedCJSManifest (manifest, branchName, repoUrl, homePage = repoUrl) {
export async function typedCJSManifest (context) {
const { manifest, branchName, repoUrl, homePage } = context
let release
const scripts = {
...manifest.scripts
}

if (context.releaseType === 'semantic-release') {
scripts.release = 'aegir release'
release = semanticReleaseConfig(branchName)
}

if (context.releaseType === 'release-please') {
delete scripts.release
}

Check warning on line 28 in src/check-project/manifests/typed-cjs.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/typed-cjs.js#L14-L28

Added lines #L14 - L28 were not covered by tests
let proposedManifest = constructManifest(manifest, {
main: 'src/index.js',
types: 'dist/src/index.d.ts',
Expand Down Expand Up @@ -41,7 +53,8 @@
project: true
}
}, manifest.eslintConfig),
release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined
scripts,
release

Check warning on line 57 in src/check-project/manifests/typed-cjs.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/typed-cjs.js#L56-L57

Added lines #L56 - L57 were not covered by tests
}, repoUrl, homePage)

const rest = {
Expand Down
25 changes: 19 additions & 6 deletions src/check-project/manifests/typed-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
const merge = mergeOptions.bind({ ignoreUndefined: true })

/**
* @param {any} manifest
* @param {string} branchName
* @param {string} repoUrl
* @param {string} [homePage]
* @param {import('../index.js').ProcessManifestContext} context
*/
export async function typedESMManifest (manifest, branchName, repoUrl, homePage = repoUrl) {
export async function typedESMManifest (context) {
const { manifest, branchName, repoUrl, homePage } = context
let release
const scripts = {
...manifest.scripts
}

if (context.releaseType === 'semantic-release') {
scripts.release = 'aegir release'
release = semanticReleaseConfig(branchName)
}

if (context.releaseType === 'release-please') {
delete scripts.release
}

Check warning on line 29 in src/check-project/manifests/typed-esm.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/typed-esm.js#L15-L29

Added lines #L15 - L29 were not covered by tests
let proposedManifest = constructManifest(manifest, {
type: 'module',
types: './dist/src/index.d.ts',
Expand Down Expand Up @@ -55,7 +67,8 @@
sourceType: 'module'
}
}, manifest.eslintConfig),
release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined
release,
scripts

Check warning on line 71 in src/check-project/manifests/typed-esm.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/typed-esm.js#L70-L71

Added lines #L70 - L71 were not covered by tests
}, repoUrl, homePage)

const rest = {
Expand Down
21 changes: 15 additions & 6 deletions src/check-project/manifests/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@
const merge = mergeOptions.bind({ ignoreUndefined: true })

/**
* @param {any} manifest
* @param {string} branchName
* @param {string} repoUrl
* @param {string} [homePage]
* @param {import('../index.js').ProcessManifestContext} context
*/
export async function typescriptManifest (manifest, branchName, repoUrl, homePage = repoUrl) {
export async function typescriptManifest (context) {
const { manifest, branchName, repoUrl, homePage } = context
let release

if (context.releaseType === 'semantic-release') {
manifest.scripts.release = 'aegir release'
release = semanticReleaseConfig(branchName)
}

if (context.releaseType === 'release-please') {
delete manifest.scripts.release
}

Check warning on line 28 in src/check-project/manifests/typescript.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/typescript.js#L17-L28

Added lines #L17 - L28 were not covered by tests
let proposedManifest = constructManifest(manifest, {
type: 'module',
types: './dist/src/index.d.ts',
Expand All @@ -42,7 +51,7 @@
sourceType: 'module'
}
}, manifest.eslintConfig),
release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined
release

Check warning on line 54 in src/check-project/manifests/typescript.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/typescript.js#L54

Added line #L54 was not covered by tests
}, repoUrl, homePage)

if (proposedManifest.exports != null && Object.keys(proposedManifest.exports).length > 1) {
Expand Down
25 changes: 19 additions & 6 deletions src/check-project/manifests/untyped-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
const merge = mergeOptions.bind({ ignoreUndefined: true })

/**
* @param {any} manifest
* @param {string} branchName
* @param {string} repoUrl
* @param {string} [homePage]
* @param {import('../index.js').ProcessManifestContext} context
*/
export async function untypedCJSManifest (manifest, branchName, repoUrl, homePage = repoUrl) {
export async function untypedCJSManifest (context) {
const { manifest, branchName, repoUrl, homePage } = context
let release
const scripts = {
...manifest.scripts
}

if (context.releaseType === 'semantic-release') {
scripts.release = 'aegir release'
release = semanticReleaseConfig(branchName)
}

if (context.releaseType === 'release-please') {
delete scripts.release
}

Check warning on line 28 in src/check-project/manifests/untyped-cjs.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/untyped-cjs.js#L14-L28

Added lines #L14 - L28 were not covered by tests
let proposedManifest = constructManifest(manifest, {
main: 'src/index.js',
files: [
Expand All @@ -26,7 +38,8 @@
project: true
}
}, manifest.eslintConfig),
release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined
release,
scripts

Check warning on line 42 in src/check-project/manifests/untyped-cjs.js

View check run for this annotation

Codecov / codecov/patch

src/check-project/manifests/untyped-cjs.js#L41-L42

Added lines #L41 - L42 were not covered by tests
}, repoUrl, homePage)

const rest = {
Expand Down
Loading
Loading