Skip to content

Commit

Permalink
fix(version): shown repo info when Create Release is enabled in dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Mar 17, 2022
1 parent 81d3679 commit 5b0cf6d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -38,17 +38,17 @@ Lerna-Lite differs from the original [Lerna](https://github.com/lerna/lerna) in
Mainly for the following reasons:
1. the original Lerna is no longer maintained (dependencies are out of date)
2. create a lighter lib that still provide Lerna's approach of Versioning and Publishing by following the [Conventional Commits](https://www.conventionalcommits.org/) and also automatically create [Conventional-Changelog](https://github.com/conventional-changelog/conventional-changelog) for each package of the workspace. We don't need all packages of Lerna anymore since NPM Workspaces came out.
3. add some little extras
3. add some little extras while keeping the lib light.

### This lib will help you with
##### [Version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) & [Publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) commands
- Automate the rolling of new Versions (independent or fixed) for all your workspace packages
- it will automatically add Commit & Tag your new Version in Git & create new Release in GitHub when enabled
#### [Version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) & [Publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) commands
- Automate the rolling of new Versions (`independent` or `fixed`) for all your workspace packages
- it will automatically add Commit & Tag your new Version in Git & create new GitHub or GitLab Release when enabled
- Automate the creation of Changelogs for all your packages by reading all [Conventional Commits](https://www.conventionalcommits.org/)
- each package will get its own changelog and a combined changelog will also be created in the root
- Automate the repository Publish of your new versions for all your packages (NPM or other platform)

##### [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) command (optional)
#### [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) command (optional)
- [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) is an optional package that will help you run npm script in parallel and in topological order.

## Lerna-Lite Packages
Expand Down Expand Up @@ -94,7 +94,7 @@ Using Lerna-Lite? Add a README badge to show it off: [![lerna--lite](https://img
# Lerna CLI which includes publish/version commands
npm install @lerna-lite/cli # OR yard add @lerna-lite/cli

# optional run command
# install optional `run` command
npm install @lerna-lite/run # OR yarn add @lerna-lite/run
```

Expand All @@ -110,7 +110,7 @@ Add custom NPM Scripts or simply run the following NodeJS commands in a shell.
```

### Configuration
This lib requires a config file in order to do its job properly. It could come from a separate config file in the root (read [`lerna.json` - Wiki](https://github.com/ghiscoding/lerna-lite/wiki/lerna.json) OR a `"lerna": {}` property directly under your `package.json`.
You could configure Lerna via a `lerna.json` file, via a `"lerna": {}` property directly under your `package.json` or lastly by passing arguments directly when calling the shell commands. You can read the [`lerna.json` - Wiki](https://github.com/ghiscoding/lerna-lite/wiki/lerna.json) for more info.

### Migration for [Lerna](https://github.com/lerna/lerna) Users
If you are migrating from Lerna, it should be fairly easy to just replace Lerna with Lerna-Lite and that should be it, the CLI commands are the same, take a look at the quick steps below:
Expand All @@ -125,7 +125,7 @@ npm uninstall -g lerna # OR yarn global remove lerna
# Lerna CLI (`version`/`publish` commands)
npm install @lerna-lite/cli

# optionally install the `run` command
# install optional `run` command
npm install @lerna-lite/run
```

Expand Down
1 change: 1 addition & 0 deletions lerna.json
Expand Up @@ -9,6 +9,7 @@
},
"version": {
"conventionalCommits": true,
"createRelease": "github",
"gitDryRun": false,
"noPrivate": true,
"message": "chore(release): publish new version %v",
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/git-clients/__tests__/github-client.spec.ts
Expand Up @@ -62,8 +62,7 @@ describe('parseGitRepo', () => {
expect(childProcess.execSync).toHaveBeenCalledWith(
'git',
['config', '--get', 'remote.origin.url'],
undefined,
false
undefined
);

expect(repo).toEqual(
Expand All @@ -82,8 +81,7 @@ describe('parseGitRepo', () => {
expect(childProcess.execSync).toHaveBeenCalledWith(
'git',
['config', '--get', 'remote.upstream.url'],
undefined,
false
undefined
);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/git-clients/github-client.ts
Expand Up @@ -30,15 +30,15 @@ export function createGitHubClient() {
return new Octokit(options);
}

export function parseGitRepo(remote = 'origin', opts?: SyncOptions<string>, gitDryRun = false): parseGitUrl.GitUrl {
export function parseGitRepo(remote = 'origin', opts?: SyncOptions<string>): parseGitUrl.GitUrl {
log.silly('parseGitRepo', '');
const args = ['config', '--get', `remote.${remote}.url`];
log.verbose('git', args.join(' '));
const url = execSync('git', args, opts, gitDryRun);
const url = execSync('git', args, opts);

if (!url && !gitDryRun) {
if (!url) {
throw new Error(`Git remote URL could not be found using "${remote}".`);
}

return gitDryRun ? {} as parseGitUrl.GitUrl : parseGitUrl(url);
return parseGitUrl(url);
}
2 changes: 1 addition & 1 deletion packages/version/README.md
Expand Up @@ -286,7 +286,7 @@ When run with this flag, `lerna version` will force publish the specified packag

Displays the git command that would be performed without actually executing it, however please note that it will still create all the changelogs. This could be helpful for troubleshooting and also to see changelog changes without commiting them to Git.

**Note:** it will still create the changelogs (when enabled), so it could be useful to see what gets created (however, make sure to discard the changes and roll back your version in `lerna.json` once you're done)
**Note:** changelogs will still be created (when enabled) even in dry-run mode, so it could be useful to see what gets created without them being committed (however, make sure to discard the changes and roll back your version in `lerna.json` once you're done).

```sh
$ lerna run watch --git-dry-run
Expand Down
19 changes: 10 additions & 9 deletions packages/version/src/lib/create-release.ts
Expand Up @@ -31,7 +31,7 @@ export function createReleaseClient(type: 'github' | 'gitlab') {
* @param {{ gitRemote: string; execOpts: import('@lerna/child-process').ExecOpts }} opts
*/
export function createRelease(client, { tags, releaseNotes }: ReleaseCommandProps, { gitRemote, execOpts }: ReleaseOptions, gitDryRun = false) {
const repo = parseGitRepo(gitRemote, execOpts, gitDryRun);
const repo = parseGitRepo(gitRemote, execOpts);

return Promise.all(
releaseNotes.map(({ notes, name }) => {
Expand All @@ -43,21 +43,22 @@ export function createRelease(client, { tags, releaseNotes }: ReleaseCommandProp
}

const prereleaseParts = semver.prerelease(tag.replace(`${name}@`, '')) || [];

if (gitDryRun) {
log.info('dry-run>', `Release Created`);
return {};
}

return client.repos.createRelease({
const releaseOptions = {
owner: repo.owner,
repo: repo.name,
tag_name: tag,
name: tag,
body: notes,
draft: false,
prerelease: prereleaseParts.length > 0,
});
};

if (gitDryRun) {
log.info('dry-run>', `Create Release with repo options: `, JSON.stringify(releaseOptions));
return Promise.resolve();
}

return client.repos.createRelease(releaseOptions);
})
);
}

0 comments on commit 5b0cf6d

Please sign in to comment.