Skip to content

Commit

Permalink
Separate --no-increment from --github.update
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 8, 2021
1 parent 86425b7 commit 57a77c8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -210,11 +210,11 @@ pre-releases. An example pre-release version is `2.0.0-beta.0`.

## Update or re-run existing releases

Use `--no-increment` to not increment the lastest version and update an existing tag/version.
Use `--no-increment` to not increment the last version, but update the last existing tag/version.

This may be helpful in some cases where the version was already incremented. Here's a few example scenarios:
This may be helpful in cases where the version was already incremented. Here's a few example scenarios:

- To update or publish a draft GitHub Release for an existing Git tag.
- To update or publish a (draft) GitHub Release for an existing Git tag.
- Publishing to npm succeeded, but pushing the Git tag to the remote failed. Then use
`release-it --no-increment --no-npm` to skip the `npm publish` and try pushing the same Git tag again.

Expand Down
7 changes: 4 additions & 3 deletions docs/github-releases.md
Expand Up @@ -96,8 +96,9 @@ The latest GitHub release can be updated, e.g. to update the releases notes, add
status.

- Use `--no-increment` to skip updating the version.
- Use `--no-git` to skip Git actions.
- Use `--no-npm` to skip publishing to npm if there's a `package.json`.
- Use `--no-git` to skip Git commit, tag, push (when the tag is already there).
- Use `--no-npm` to skip publishing to npm (if there's a `package.json`).
- Use `--github.update` to update the GitHub release.

Use the other options to update the release, such as `--github.assets` to add assets. Note that the `draft` and
`preRelease` options are `false` by default, but can be set explicitly using e.g. `--no-github.draft` or
Expand All @@ -106,5 +107,5 @@ Use the other options to update the release, such as `--github.assets` to add as
Example command to add assets and explicitly toggle the draft status to "published":

```bash
release-it --no-increment --no-git --github.release --github.assets=*.zip --no-github.draft
release-it --no-increment --no-git --github.release --github.update --github.assets=*.zip --no-github.draft
```
5 changes: 2 additions & 3 deletions lib/config.js
Expand Up @@ -54,7 +54,6 @@ class Config {

expandPreReleaseShorthand(options) {
const { increment, preRelease, preReleaseId } = options;
options.isUpdate = increment === false;
options.version = {
increment,
isPreRelease: Boolean(preRelease),
Expand Down Expand Up @@ -97,8 +96,8 @@ class Config {
return Boolean(this.options['dry-run']);
}

get isUpdate() {
return this.options.increment === false;
get isIncrement() {
return this.options.increment !== false;
}

get isVerbose() {
Expand Down
6 changes: 3 additions & 3 deletions lib/plugin/GitBase.js
Expand Up @@ -11,7 +11,7 @@ class GitBase extends Plugin {
await this.fetch();
const repo = parseGitUrl(this.remoteUrl);
const latestTagName = await this.getLatestTagName(repo);
const secondLatestTagName = this.config.isUpdate ? await this.getSecondLatestTagName(latestTagName) : null;
const secondLatestTagName = !this.config.isIncrement ? await this.getSecondLatestTagName(latestTagName) : null;
const tagTemplate = this.options.tagName || ((latestTagName || '').match(/^v/) ? 'v${version}' : '${version}');
this.setContext({ repo, tagTemplate, latestTagName, secondLatestTagName });
this.config.setContext({ latestTag: latestTagName });
Expand All @@ -27,12 +27,12 @@ class GitBase extends Plugin {
}

async getChangelog() {
const { isUpdate, latestTagName, secondLatestTagName } = this.getContext();
const { latestTagName, secondLatestTagName } = this.getContext();
const context = { latestTag: latestTagName, from: latestTagName, to: 'HEAD' };
const { changelog } = this.options;
if (!changelog) return null;

if (latestTagName && isUpdate) {
if (latestTagName && !this.config.isIncrement) {
context.from = secondLatestTagName;
context.to = `${latestTagName}^1`;
}
Expand Down
5 changes: 2 additions & 3 deletions lib/plugin/github/GitHub.js
Expand Up @@ -36,8 +36,7 @@ class GitHub extends Release {
async init() {
await super.init();

const { skipChecks, tokenRef } = this.options;
const { isUpdate } = this.config;
const { skipChecks, tokenRef, update } = this.options;

if (!skipChecks) {
if (!this.token) {
Expand All @@ -61,7 +60,7 @@ class GitHub extends Release {
}
}

if (isUpdate) {
if (update) {
const { latestTagName } = this.getContext();
try {
const { id, upload_url, tag_name } = await this.getLatestRelease();
Expand Down
6 changes: 3 additions & 3 deletions lib/plugin/github/prompts.js
@@ -1,10 +1,10 @@
import { format } from '../../util.js';

const message = context => {
const { isPreRelease, isUpdate, github } = context;
const { releaseName } = github;
const { isPreRelease, github } = context;
const { releaseName, update } = github;
const name = format(releaseName, context);
return `${isUpdate ? 'Update' : 'Create a'} ${isPreRelease ? 'pre-' : ''}release on GitHub (${name})?`;
return `${update ? 'Update' : 'Create a'} ${isPreRelease ? 'pre-' : ''}release on GitHub (${name})?`;
};

export default {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/npm/npm.js
Expand Up @@ -80,7 +80,7 @@ class npm extends Plugin {
const tag = this.options.tag || (await this.resolveTag(version));
this.setContext({ version, tag });

if (this.config.isUpdate) return false;
if (!this.config.isIncrement) return false;

const task = () => this.exec(`npm version ${version} --no-git-tag-version`);
return this.spinner.show({ task, label: 'npm version' });
Expand Down
12 changes: 6 additions & 6 deletions lib/tasks.js
Expand Up @@ -70,11 +70,11 @@ const runTasks = async (opts, di) => {
const incrementBase = { latestVersion, increment, isPreRelease, preReleaseId };

let version;
if (config.isUpdate) {
version = latestVersion;
} else {
if (config.isIncrement) {
incrementBase.increment = await reduceUntil(plugins, plugin => plugin.getIncrement(incrementBase));
version = await reduceUntil(plugins, plugin => plugin.getIncrementedVersionCI(incrementBase));
} else {
version = latestVersion;
}

if (config.isReleaseVersion) {
Expand All @@ -84,14 +84,14 @@ const runTasks = async (opts, di) => {

config.setContext({ name, latestVersion, version, changelog });

const action = config.isUpdate ? 'update' : 'release';
const suffix = version && !config.isUpdate ? `${latestVersion}...${version}` : `currently at ${latestVersion}`;
const action = config.isIncrement ? 'release' : 'update';
const suffix = version && config.isIncrement ? `${latestVersion}...${version}` : `currently at ${latestVersion}`;

log.obtrusive(`🚀 Let's ${action} ${name} (${suffix})`);

log.preview({ title: 'changelog', text: changelog });

if (!config.isUpdate) {
if (config.isIncrement) {
version = version || (await reduceUntil(plugins, plugin => plugin.getIncrementedVersion(incrementBase)));
}

Expand Down
4 changes: 2 additions & 2 deletions test/github.js
Expand Up @@ -95,9 +95,9 @@ test('should update release and upload assets', async t => {
const asset = 'file1';
const options = {
increment: false,
isUpdate: true,
git,
github: {
update: true,
pushRepo,
tokenRef,
release: true,
Expand Down Expand Up @@ -129,9 +129,9 @@ test('should update release and upload assets', async t => {
test('should create new release for unreleased tag', async t => {
const options = {
increment: false,
isUpdate: true,
git,
github: {
update: true,
pushRepo,
tokenRef,
release: true,
Expand Down

0 comments on commit 57a77c8

Please sign in to comment.