From ca1f8c6b45092b857268cc0551f8eb6a59295fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Ta=CC=8Agerud?= Date: Thu, 28 Mar 2019 03:37:24 +0100 Subject: [PATCH 1/5] Always run postversion lifecycle method Runs postversion even if no git commit is made. --- src/cli/commands/version.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 5b2ef1a66a..c37d73d436 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -153,6 +153,8 @@ export async function setVersion( await runLifecycle('version'); + await runLifecycle('postversion'); + // check if committing the new version to git is overriden if (!flags.gitTagVersion || !config.getOption('version-git-tag')) { // Don't tag the version in Git @@ -192,8 +194,6 @@ export async function setVersion( // create git tag await spawnGit(['tag', `${prefix}${newVersion}`, flag, message], {cwd: gitRoot}); } - - await runLifecycle('postversion'); }; } From 4d3000ac0f9e7cfc7b39d41099ed2c6bceeb675f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Ta=CC=8Agerud?= Date: Thu, 28 Mar 2019 04:06:11 +0100 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c53a72c297..ab507a386c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa - Implements `yarn audit --level [severity]` flag to filter the audit command's output. -[#6716](https://github.com/yarnpkg/yarn/pull/6716) - [**Rogério Vicente**](https://twitter.com/rogeriopvl) + [#6716](https://github.com/yarnpkg/yarn/pull/6716) - [**Rogério Vicente**](https://twitter.com/rogeriopvl) - Implements `yarn audit --groups group_name [group_name ...]`. @@ -16,6 +16,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa [#7127](https://github.com/yarnpkg/yarn/pull/7127) - [**Eli Perelman**](https://github.com/eliperelman) +- Always run postversion lifecycle method. + + [#7154](https://github.com/yarnpkg/yarn/pull/7154) - [**Hampus Tågerud**](https://github.com/hampustagerud) + ## 1.15.2 The 1.15.1 doesn't exist due to a release hiccup. From bfc88eacac22bf63a281b1f4f006c8d1b6d30a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Ta=CC=8Agerud?= Date: Tue, 7 May 2019 15:11:19 +0200 Subject: [PATCH 3/5] Improve logic, add tests, update CHANGELOG.md --- CHANGELOG.md | 2 +- __tests__/commands/version.js | 102 ++++++++++++++++++ .../version/no-args-no-git-tags/.yarnrc | 1 + .../version/no-args-no-git-tags/package.json | 9 ++ src/cli/commands/version.js | 59 +++++----- 5 files changed, 141 insertions(+), 32 deletions(-) create mode 100644 __tests__/fixtures/version/no-args-no-git-tags/.yarnrc create mode 100644 __tests__/fixtures/version/no-args-no-git-tags/package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index ba02d86d20..ba1f20498a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa - Implements `yarn audit --level [severity]` flag to filter the audit command's output. - [#6716](https://github.com/yarnpkg/yarn/pull/6716) - [**Rogério Vicente**](https://twitter.com/rogeriopvl) +[#6716](https://github.com/yarnpkg/yarn/pull/6716) - [**Rogério Vicente**](https://twitter.com/rogeriopvl) - Implements `yarn audit --groups group_name [group_name ...]`. diff --git a/__tests__/commands/version.js b/__tests__/commands/version.js index 7b4e878f93..14eac9323d 100644 --- a/__tests__/commands/version.js +++ b/__tests__/commands/version.js @@ -162,6 +162,108 @@ test('run version and make sure commit hooks are disabled by config', async (): }); }); +test('run version with --no-git-tag-version and make sure git tags are disabled', async (): Promise => { + const fixture = 'no-args'; + await fs.mkdirp(path.join(fixturesLoc, fixture, '.git')); + + return runRun([], {newVersion, gitTagVersion: false}, fixture, async (config): ?Promise => { + const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); + expect(pkg.version).toBe(newVersion); + + expect(spawn.mock.calls.length).toBe(0); + }); +}); + +test('run version and make sure git tags are disabled by config', async (): Promise => { + const fixture = 'no-args-no-git-tags'; + await fs.mkdirp(path.join(fixturesLoc, fixture, '.git')); + + return runRun([], {newVersion, gitTagVersion}, fixture, async (config): ?Promise => { + const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); + expect(pkg.version).toBe(newVersion); + + expect(spawn.mock.calls.length).toBe(0); + }); +}); + +test('run version with --no-git-tag-version, make sure all lifecycle steps runs', async (): Promise => { + const fixture = 'no-args'; + await fs.mkdirp(path.join(fixturesLoc, fixture, '.git')); + + return runRun([], {newVersion, gitTagVersion: false}, fixture, async (config): ?Promise => { + expect(spawn.mock.calls.length).toBe(0); + + const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); + + const preversionLifecycle = { + stage: 'preversion', + config, + cmd: pkg.scripts.preversion, + cwd: config.cwd, + isInteractive: true, + }; + const versionLifecycle = { + stage: 'version', + config, + cmd: pkg.scripts.version, + cwd: config.cwd, + isInteractive: true, + }; + const postversionLifecycle = { + stage: 'postversion', + config, + cmd: pkg.scripts.postversion, + cwd: config.cwd, + isInteractive: true, + }; + + expect(execCommand.mock.calls.length).toBe(3); + + expect(execCommand.mock.calls[0]).toEqual([preversionLifecycle]); + expect(execCommand.mock.calls[1]).toEqual([versionLifecycle]); + expect(execCommand.mock.calls[2]).toEqual([postversionLifecycle]); + }); +}); + +test('run version with git tags disabled in config, make sure all lifecycle steps runs', async (): Promise => { + const fixture = 'no-args-no-git-tags'; + await fs.mkdirp(path.join(fixturesLoc, fixture, '.git')); + + return runRun([], {newVersion, gitTagVersion}, fixture, async (config): ?Promise => { + expect(spawn.mock.calls.length).toBe(0); + + const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); + + const preversionLifecycle = { + stage: 'preversion', + config, + cmd: pkg.scripts.preversion, + cwd: config.cwd, + isInteractive: true, + }; + const versionLifecycle = { + stage: 'version', + config, + cmd: pkg.scripts.version, + cwd: config.cwd, + isInteractive: true, + }; + const postversionLifecycle = { + stage: 'postversion', + config, + cmd: pkg.scripts.postversion, + cwd: config.cwd, + isInteractive: true, + }; + + expect(execCommand.mock.calls.length).toBe(3); + + expect(execCommand.mock.calls[0]).toEqual([preversionLifecycle]); + expect(execCommand.mock.calls[1]).toEqual([versionLifecycle]); + expect(execCommand.mock.calls[2]).toEqual([postversionLifecycle]); + }); +}); + test('run version with --major flag and make sure major version is incremented', (): Promise => { return runRun([], {gitTagVersion, major: true}, 'no-args', async (config): ?Promise => { const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); diff --git a/__tests__/fixtures/version/no-args-no-git-tags/.yarnrc b/__tests__/fixtures/version/no-args-no-git-tags/.yarnrc new file mode 100644 index 0000000000..5cb9a09b64 --- /dev/null +++ b/__tests__/fixtures/version/no-args-no-git-tags/.yarnrc @@ -0,0 +1 @@ +version-git-tag false diff --git a/__tests__/fixtures/version/no-args-no-git-tags/package.json b/__tests__/fixtures/version/no-args-no-git-tags/package.json new file mode 100644 index 0000000000..c8c699e438 --- /dev/null +++ b/__tests__/fixtures/version/no-args-no-git-tags/package.json @@ -0,0 +1,9 @@ +{ + "version": "1.0.0", + "license": "BSD-2-Clause", + "scripts": { + "preversion": "echo preversion", + "version": "echo version", + "postversion": "echo postversion" + } +} diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index c37d73d436..be72b20d9c 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -153,47 +153,44 @@ export async function setVersion( await runLifecycle('version'); - await runLifecycle('postversion'); - - // check if committing the new version to git is overriden - if (!flags.gitTagVersion || !config.getOption('version-git-tag')) { - // Don't tag the version in Git - return () => Promise.resolve(); - } - return async function(): Promise { invariant(newVersion, 'expected version'); - // add git commit and tag - let isGit = false; - const parts = config.cwd.split(path.sep); - while (parts.length) { - isGit = await fs.exists(path.join(parts.join(path.sep), '.git')); - if (isGit) { - break; - } else { - parts.pop(); + // check if a new git tag should be created + if (flags.gitTagVersion && config.getOption('version-git-tag')) { + // add git commit and tag + let isGit = false; + const parts = config.cwd.split(path.sep); + while (parts.length) { + isGit = await fs.exists(path.join(parts.join(path.sep), '.git')); + if (isGit) { + break; + } else { + parts.pop(); + } } - } - if (isGit) { - const message = (flags.message || String(config.getOption('version-git-message'))).replace(/%s/g, newVersion); - const sign: boolean = Boolean(config.getOption('version-sign-git-tag')); - const flag = sign ? '-sm' : '-am'; - const prefix: string = String(config.getOption('version-tag-prefix')); - const args: Array = ['commit', '-m', message, ...(isCommitHooksDisabled() ? ['-n'] : [])]; + if (isGit) { + const message = (flags.message || String(config.getOption('version-git-message'))).replace(/%s/g, newVersion); + const sign: boolean = Boolean(config.getOption('version-sign-git-tag')); + const flag = sign ? '-sm' : '-am'; + const prefix: string = String(config.getOption('version-tag-prefix')); + const args: Array = ['commit', '-m', message, ...(isCommitHooksDisabled() ? ['-n'] : [])]; - const gitRoot = (await spawnGit(['rev-parse', '--show-toplevel'], {cwd: config.cwd})).trim(); + const gitRoot = (await spawnGit(['rev-parse', '--show-toplevel'], {cwd: config.cwd})).trim(); - // add manifest - await spawnGit(['add', path.relative(gitRoot, pkgLoc)], {cwd: gitRoot}); + // add manifest + await spawnGit(['add', path.relative(gitRoot, pkgLoc)], {cwd: gitRoot}); - // create git commit - await spawnGit(args, {cwd: gitRoot}); + // create git commit + await spawnGit(args, {cwd: gitRoot}); - // create git tag - await spawnGit(['tag', `${prefix}${newVersion}`, flag, message], {cwd: gitRoot}); + // create git tag + await spawnGit(['tag', `${prefix}${newVersion}`, flag, message], {cwd: gitRoot}); + } } + + await runLifecycle('postversion'); }; } From 68f0daa7b8877cdcb067a122e95daa1c10f7a28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20T=C3=A5gerud?= Date: Wed, 8 May 2019 13:13:52 +0200 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1f20498a..b44c0078eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa ## Master +- Always run postversion lifecycle method. + + [#7154](https://github.com/yarnpkg/yarn/pull/7154) - [**Hampus Tågerud**](https://github.com/hampustagerud) + ## 1.16.0 - Retries downloading a package on `yarn install` when we get a ETIMEDOUT error. @@ -21,10 +25,6 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa - Exposes the script environment variables to `yarn create` spawned processes. [#7127](https://github.com/yarnpkg/yarn/pull/7127) - [**Eli Perelman**](https://github.com/eliperelman) - -- Always run postversion lifecycle method. - - [#7154](https://github.com/yarnpkg/yarn/pull/7154) - [**Hampus Tågerud**](https://github.com/hampustagerud) - Prevents EPIPE errors from being printed. From 98fd4ce68e4edfc4df08293be1d3b5c8e6d5107a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Wed, 24 Jul 2019 14:42:41 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 117c9fc42d..2f3ac7fa79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa ## Master -- Always run postversion lifecycle method. +- Fixes the `postversion` lifecycle method not being called when using `--no-git-tag-version`. [#7154](https://github.com/yarnpkg/yarn/pull/7154) - [**Hampus Tågerud**](https://github.com/hampustagerud)