-
Notifications
You must be signed in to change notification settings - Fork 890
Add CLI for monorepo releases #8308
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
Merged
tkajtoch
merged 11 commits into
elastic:eui-theme/borealis
from
tkajtoch:build/monorepo-releases-setup
Feb 28, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1ca6589
build: add release cli
tkajtoch f6b6483
feat: clean up code, add safety checks and publishing logic
tkajtoch f9fbb27
fix: check if the changelog files are in git
tkajtoch a074928
build: commit changed `yarn.lock` file when updating package versions
tkajtoch f7f44ba
build: add @elastic/eui to @elastic/eui-docgen dependencies to fix to…
tkajtoch 49aee50
fix: accept `--workspaces` arg correctly
tkajtoch b787747
fix: update `yarn workspaces foreach` command to actually build works…
tkajtoch 1119329
build: detect and print out currently used npmjs registry
tkajtoch d4ff3b4
chore: add missed yarn.lock update
tkajtoch ec2b564
fix: exclude `@elastic/eui-monorepo`
tkajtoch 8c25efb
fix: remove accidentally committed .yarnrc changes
tkajtoch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| # Dependencies | ||
| /node_modules | ||
|
|
||
| # Production | ||
| /dist | ||
|
|
||
| yarn-debug.log* | ||
| yarn-error.log* |
This file contains hidden or 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,27 @@ | ||
| { | ||
| "name": "@elastic/eui-release-cli", | ||
| "private": true, | ||
| "version": "0.0.1", | ||
| "description": "", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "build": "tsc" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/tkajtoch/eui.git", | ||
| "directory": "packages/release-cli" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/prompts": "^2.4.9", | ||
| "typescript": "^5.7.3" | ||
| }, | ||
| "dependencies": { | ||
| "chalk": "^4", | ||
| "glob": "^11.0.1", | ||
| "prompts": "^2.4.2", | ||
| "rimraf": "^6.0.1", | ||
| "yargs": "^17.7.2" | ||
| } | ||
| } |
This file contains hidden or 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,98 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import yargs from 'yargs/yargs'; | ||
| import { hideBin } from 'yargs/helpers'; | ||
| import { release, type ReleaseType } from './release'; | ||
| import { Logger } from './logger'; | ||
| import { ValidationError } from './errors'; | ||
|
|
||
| export const cli = () => { | ||
| yargs(hideBin(process.argv)) | ||
| .command( | ||
| 'run <type> [--tag] [--workspaces] [--allowCustom] [--verbose | -v]', | ||
| 'Run the release process', | ||
| (yargs) => { | ||
| return yargs | ||
| .positional('type', { | ||
| type: 'string', | ||
| describe: | ||
| 'Type of release to perform. Releases of type `official` will be tagged as `latest` in npm and are meant for official, stable builds only!', | ||
| choices: ['official', 'snapshot'] satisfies ReleaseType[], | ||
| demandOption: true, | ||
| }) | ||
| .option('tag', { | ||
| type: 'string', | ||
| describe: | ||
| 'npm tag for the release. It is forced to `latest` for official releases and defaults to `snapshot` for snapshot releases.', | ||
| }) | ||
| .option('workspaces', { | ||
| type: 'string', | ||
| array: true, | ||
| describe: | ||
| 'An optional space-separated list of workspaces to release. Defaults to all workspaces changed since the last release.', | ||
| }) | ||
| .option('allowCustom', { | ||
| type: 'boolean', | ||
| default: false, | ||
| }) | ||
| .option('verbose', { | ||
| alias: 'v', | ||
| type: 'boolean', | ||
| description: 'Enable verbose logging', | ||
| default: false, | ||
| }) | ||
| .option('skipPrompts', { | ||
| type: 'boolean', | ||
| description: | ||
| 'Skip user prompts and proceed with recommended settings. Use in CI only!', | ||
| default: false, | ||
| }) | ||
| .option('useAuthToken', { | ||
| type: 'boolean', | ||
| description: | ||
| 'Use npm auth token instead of the regular npm user authentication and one-time passwords (OTP). Use in CI only!', | ||
| default: false, | ||
| }); | ||
| }, | ||
| async (argv) => { | ||
| const { | ||
| type, | ||
| tag, | ||
| workspaces, | ||
| allowCustom, | ||
| verbose, | ||
| skipPrompts, | ||
| useAuthToken, | ||
| } = argv; | ||
| const logger = new Logger(verbose); | ||
|
|
||
| try { | ||
| await release({ | ||
| type, | ||
| tag, | ||
| workspaces, | ||
| logger, | ||
| skipPrompts, | ||
| useAuthToken, | ||
| allowCustomReleases: allowCustom, | ||
| }); | ||
| } catch (err) { | ||
| if (err instanceof ValidationError) { | ||
| // ValidationErrors don't need the stacktrace printed out | ||
| logger.error(err.toString()); | ||
| } else { | ||
| logger.error(err); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| } | ||
| ) | ||
| .demandCommand(1) | ||
| .parse(); | ||
| }; |
This file contains hidden or 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,28 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| export class ValidationError extends Error { | ||
| public helpText: string | null = null; | ||
|
|
||
| constructor(message: string, helpText?: string) { | ||
| super(message); | ||
|
|
||
| if (helpText !== undefined) { | ||
| this.helpText = helpText; | ||
| } | ||
| } | ||
|
|
||
| toString() { | ||
| let finalHelpText = ''; | ||
| if (this.helpText) { | ||
| finalHelpText += '\n\n'; | ||
| finalHelpText += this.helpText; | ||
| } | ||
| return `${this.message}${finalHelpText}`; | ||
| } | ||
| } |
This file contains hidden or 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,65 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { promisify } from 'node:util'; | ||
| import { exec } from 'node:child_process'; | ||
|
|
||
| const execPromise = promisify(exec); | ||
|
|
||
| export const getCurrentBranch = async () => { | ||
| const result = await execPromise('git rev-parse --abbrev-ref HEAD'); | ||
|
|
||
| return result.stdout.trim(); | ||
| } | ||
|
|
||
| export const isWorkingTreeClean = async () => { | ||
| const gitStatusResult = await execPromise('git status --porcelain'); | ||
|
|
||
| return gitStatusResult.stdout === '' && gitStatusResult.stderr === ''; | ||
| } | ||
|
|
||
| export const getRemoteHeadCommitHash = async (branchName: string) => { | ||
| try { | ||
| const result = await execPromise(`git ls-remote --head --exit-code upstream refs/heads/${branchName}`); | ||
| return result.stdout.split('\t')[0]; | ||
| } catch (err) { | ||
| // https://git-scm.com/docs/git-ls-remote#Documentation/git-ls-remote.txt---exit-code | ||
| if ((err as any).code === 2) { | ||
| // Remote ref not found | ||
| return ''; | ||
| } | ||
|
|
||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| export const getLocalHeadCommitHash = async () => { | ||
| const result = await execPromise('git rev-parse HEAD'); | ||
|
|
||
| return result.stdout.trim(); | ||
| }; | ||
|
|
||
| export const getCommitMessage = async (commitHash: string) => { | ||
| // Well, technically this returns commit subject, but we don't care about the whole commit body | ||
| const result = await execPromise(`git log -1 --pretty=format:%s ${commitHash}`); | ||
| return result.stdout.trim(); | ||
| }; | ||
|
|
||
| export const stageFiles = async (files: string[]) => { | ||
| return execPromise(`git add ${files.join(' ')}`); | ||
| }; | ||
|
|
||
| export const commitFiles = async (message: string, files: string[]) => { | ||
| // This isn't the best at handling unusual formatting like messages with quotes | ||
| return execPromise(`git commit ${files.join(' ')} -m "${message}"`); | ||
| } | ||
|
|
||
| export const isFileAddedToGit = async (file: string) => { | ||
| const result = await execPromise(`git ls-files --exclude-standard "${file}"`); | ||
| return result.stdout.length > 0; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { cli } from './cli'; | ||
|
|
||
| cli(); |
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import chalk from 'chalk'; | ||
|
|
||
| export class Logger { | ||
| private readonly PREFIX_DEBUG = chalk.gray('[debug]'); | ||
| private readonly PREFIX_INFO = chalk.white('[info]'); | ||
| private readonly PREFIX_WARNING = chalk.yellow('[warning]'); | ||
| private readonly PREFIX_ERROR = chalk.red('[error]'); | ||
|
|
||
| constructor(private readonly verbose: boolean) {} | ||
|
|
||
| debug(message: any, ...args: any) { | ||
| if (!this.verbose) { | ||
| return; | ||
| } | ||
| console.debug(this.PREFIX_DEBUG, message, ...args); | ||
| } | ||
|
|
||
| info(message: any, ...args: any) { | ||
| console.info(this.PREFIX_INFO, message, ...args); | ||
| } | ||
|
|
||
| warning(message: any, ...args: any) { | ||
| console.warn(this.PREFIX_WARNING, message, ...args); | ||
| } | ||
|
|
||
| error(message: any, ...args: any) { | ||
| console.error(this.PREFIX_ERROR, message, ...args); | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { promisify } from 'node:util'; | ||
| import { exec } from 'node:child_process'; | ||
|
|
||
| const execPromise = promisify(exec); | ||
|
|
||
| export const getNpmPublishedVersions = async (packageName: string) => { | ||
| try { | ||
| const result = await execPromise(`npm view ${packageName} versions --json`); | ||
| return JSON.parse(result.stdout) as string[]; | ||
| } catch (err) { | ||
| console.error(err); | ||
| } | ||
|
|
||
| return []; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.