semantic-release 11.1.0 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  const gitLogParser = require('git-log-parser');
2
2
  const getStream = require('get-stream');
3
3
  const debug = require('debug')('semantic-release:get-commits');
4
- const {unshallow} = require('./git');
5
- const getVersionHead = require('./get-version-head');
4
+ const SemanticReleaseError = require('@semantic-release/error');
5
+ const {unshallow, gitCommitTag, gitTagHead, isCommitInHistory} = require('./git');
6
6
 
7
7
  /**
8
8
  * Commit message.
@@ -44,22 +44,28 @@ const getVersionHead = require('./get-version-head');
44
44
  * @return {Promise<Result>} The list of commits on the branch `branch` since the last release and the updated lastRelease with the gitHead used to retrieve the commits.
45
45
  *
46
46
  * @throws {SemanticReleaseError} with code `ENOTINHISTORY` if `lastRelease.gitHead` or the commit sha derived from `config.lastRelease.version` is not in the direct history of `branch`.
47
- * @throws {SemanticReleaseError} with code `ENOGITHEAD` if `lastRelease.gitHead` is undefined and no commit sha can be found for the `config.lastRelease.version`.
48
47
  */
49
48
  module.exports = async ({version, gitHead} = {}, branch, logger) => {
50
- let gitTag;
51
- if (gitHead || version) {
52
- try {
53
- ({gitHead, gitTag} = await getVersionHead(gitHead, version, branch));
54
- } catch (err) {
55
- if (err.code === 'ENOTINHISTORY') {
56
- logger.error(notInHistoryMessage(err.gitHead, branch, version));
57
- } else {
58
- logger.error(noGitHeadMessage(branch, version));
49
+ if (gitHead) {
50
+ // If gitHead doesn't exists in release branch
51
+ if (!await isCommitInHistory(gitHead)) {
52
+ // Unshallow the repository
53
+ await unshallow();
54
+ }
55
+ // If gitHead still doesn't exists in release branch
56
+ if (!await isCommitInHistory(gitHead)) {
57
+ // Try to find the commit corresponding to the version, using got tags
58
+ const tagHead = (await gitTagHead(`v${version}`)) || (await gitTagHead(version));
59
+
60
+ // If tagHead doesn't exists in release branch
61
+ if (!tagHead || !await isCommitInHistory(tagHead)) {
62
+ // Then the commit corresponding to the version cannot be found in the bracnh hsitory
63
+ logger.error(notInHistoryMessage(gitHead, branch, version));
64
+ throw new SemanticReleaseError('Commit not in history', 'ENOTINHISTORY');
59
65
  }
60
- throw err;
66
+ gitHead = tagHead;
61
67
  }
62
- logger.log('Retrieving commits since %s, corresponding to version %s', gitHead, version);
68
+ debug('Use gitHead: %s', gitHead);
63
69
  } else {
64
70
  logger.log('No previous release found, retrieving all commits');
65
71
  // If there is no gitHead nor a version, there is no previous release. Unshallow the repo in order to retrieve all commits
@@ -76,20 +82,9 @@ module.exports = async ({version, gitHead} = {}, branch, logger) => {
76
82
  );
77
83
  logger.log('Found %s commits since last release', commits.length);
78
84
  debug('Parsed commits: %o', commits);
79
- return {commits, lastRelease: {version, gitHead, gitTag}};
85
+ return {commits, lastRelease: {version, gitHead, gitTag: await gitCommitTag(gitHead)}};
80
86
  };
81
87
 
82
- function noGitHeadMessage(branch, version) {
83
- return `The commit the last release of this package was derived from cannot be determined from the release metadata nor from the repository tags.
84
- This means semantic-release can not extract the commits between now and then.
85
- This is usually caused by releasing from outside the repository directory or with innaccessible git metadata.
86
-
87
- You can recover from this error by creating a tag for the version "${version}" on the commit corresponding to this release:
88
- $ git tag -f v${version} <commit sha1 corresponding to last release>
89
- $ git push -f --tags origin ${branch}
90
- `;
91
- }
92
-
93
88
  function notInHistoryMessage(gitHead, branch, version) {
94
89
  return `The commit the last release of this package was derived from is not in the direct history of the "${branch}" branch.
95
90
  This means semantic-release can not extract the commits between now and then.
package/lib/git.js CHANGED
@@ -25,7 +25,7 @@ async function gitTagHead(tagName) {
25
25
  *
26
26
  * @param {string} gitHead The commit sha for which to retrieve the associated tag.
27
27
  *
28
- * @return {string} The tag associatedwith the sha in parameter or `null`.
28
+ * @return {string} The tag associatedwith the sha in parameter or `undefined`.
29
29
  */
30
30
  async function gitCommitTag(gitHead) {
31
31
  try {
@@ -34,7 +34,7 @@ async function gitCommitTag(gitHead) {
34
34
  return shell.stdout;
35
35
  } catch (err) {
36
36
  debug(err);
37
- return null;
37
+ return undefined;
38
38
  }
39
39
  }
40
40
 
@@ -24,9 +24,9 @@ module.exports = {
24
24
  validator: output =>
25
25
  !output ||
26
26
  (isObject(output) && !output.version) ||
27
- (isString(output.version) && Boolean(semver.valid(semver.clean(output.version)))),
27
+ (isString(output.version) && Boolean(semver.valid(semver.clean(output.version))) && Boolean(output.gitHead)),
28
28
  message:
29
- 'The "getLastRelease" plugin output if defined, must be an object with an optionnal valid semver version in the "version" property.',
29
+ 'The "getLastRelease" plugin output if defined, must be an object with a valid semver version in the "version" property and the corresponding git reference in "gitHead" property.',
30
30
  },
31
31
  },
32
32
  analyzeCommits: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "semantic-release",
3
3
  "description": "Automated semver compliant package publishing",
4
- "version": "11.1.0",
4
+ "version": "11.2.0",
5
5
  "author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
6
6
  "bin": {
7
7
  "semantic-release": "bin/semantic-release.js"
@@ -1,52 +0,0 @@
1
- const debug = require('debug')('semantic-release:get-version-head');
2
- const SemanticReleaseError = require('@semantic-release/error');
3
- const {gitTagHead, gitCommitTag, isCommitInHistory, unshallow} = require('./git');
4
-
5
- /**
6
- * Get the commit sha for a given version, if it's contained in the given branch.
7
- *
8
- * @param {string} gitHead The commit sha to look for.
9
- * @param {string} version The version corresponding to the commit sha to look for. Used to search in git tags.
10
- *
11
- * @return {Promise<Object>} A Promise that resolves to an object with the `gitHead` and `gitTag` for the the `version`.
12
- *
13
- * @throws {SemanticReleaseError} with code `ENOTINHISTORY` if `gitHead` or the commit sha dereived from `version` is not in the direct history of `branch`.
14
- * @throws {SemanticReleaseError} with code `ENOGITHEAD` if `gitHead` is undefined and no commit sha can be found for the `version`.
15
- */
16
- module.exports = async (gitHead, version) => {
17
- // Check if gitHead is defined and exists in release branch
18
- if (gitHead && (await isCommitInHistory(gitHead))) {
19
- debug('Use gitHead: %s', gitHead);
20
- return {gitHead, gitTag: await gitCommitTag(gitHead)};
21
- }
22
-
23
- await unshallow();
24
-
25
- // Check if gitHead is defined and exists in release branch again
26
- if (gitHead && (await isCommitInHistory(gitHead))) {
27
- debug('Use gitHead: %s', gitHead);
28
- return {gitHead, gitTag: await gitCommitTag(gitHead)};
29
- }
30
-
31
- let tagHead;
32
- if (version) {
33
- // If a version is defined search a corresponding tag
34
- tagHead = (await gitTagHead(`v${version}`)) || (await gitTagHead(version));
35
-
36
- // Check if tagHead is found and exists in release branch again
37
- if (tagHead && (await isCommitInHistory(tagHead))) {
38
- debug('Use tagHead: %s', tagHead);
39
- return {gitHead: tagHead, gitTag: await gitCommitTag(tagHead)};
40
- }
41
- }
42
-
43
- // Either gitHead is defined or a tagHead has been found but none is in the branch history
44
- if (gitHead || tagHead) {
45
- const error = new SemanticReleaseError('Commit not in history', 'ENOTINHISTORY');
46
- error.gitHead = gitHead || tagHead;
47
- throw error;
48
- }
49
-
50
- // There is no gitHead in the last release and there is no tags correponsing to the last release version
51
- throw new SemanticReleaseError('There is no commit associated with last release', 'ENOGITHEAD');
52
- };