Skip to content

Commit

Permalink
Merge pull request #19 from Updater/semantic-release-12
Browse files Browse the repository at this point in the history
Compatibility with `semantic-release` >11.1.0
  • Loading branch information
pmowrer authored Jan 4, 2018
2 parents 99a00ad + 17dbdee commit 5592025
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 44 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
},
"license": "MIT",
"peerDependencies": {
"semantic-release": "~11.1.0"
"semantic-release": ">=11.1.0"
},
"dependencies": {
"debug": "^3.1.0",
"execa": "^0.8.0",
"pkg-up": "^2.0.0",
"ramda": "^0.25.0",
"read-pkg": "^3.0.0",
"semantic-release-plugin-decorators": "^1.2.0"
"semantic-release-plugin-decorators": "^1.2.1"
},
"devDependencies": {
"husky": "^0.14.3",
"jest": "^21.2.1",
"lint-staged": "^6.0.0",
"prettier": "^1.9.2",
"semantic-release": "~11.1.0",
"semantic-release-github-pr": "^2.0.0"
"semantic-release": "^11.1.0",
"semantic-release-github-pr": "^2.0.3"
},
"lint-staged": {
"*.js": [
Expand Down
34 changes: 30 additions & 4 deletions src/git-utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { pipeP, split } = require('ramda');
const execa = require('execa');
const debug = require('debug')('semantic-release-monorepo');

const git = async (...args) => {
const { stdout } = await execa('git', args);
const git = async (args, options = {}) => {
const { stdout } = await execa('git', args, options);
return stdout;
};

Expand All @@ -13,7 +14,7 @@ const git = async (...args) => {
* @return {Promise<Array>} List of modified files in a commit.
*/
const getCommitFiles = pipeP(
hash => git('diff-tree', '--no-commit-id', '--name-only', '-r', hash),
hash => git(['diff-tree', '--no-commit-id', '--name-only', '-r', hash]),
split('\n')
);

Expand All @@ -22,9 +23,34 @@ const getCommitFiles = pipeP(
* @async
* @return {Promise<String>} System path of the git repository.
*/
const getGitRoot = () => git('rev-parse', '--show-toplevel');
const getGitRoot = () => git(['rev-parse', '--show-toplevel']);

/**
* Get the commit sha for a given tag.
* https://github.com/semantic-release/semantic-release/blob/996305d69c36158f771bd20b6b416aa3461fb309/lib/git.js#L12
*
* @param {string} tagName Tag name for which to retrieve the commit sha.
* @return {string} The commit sha of the tag in parameter or `null`.
*/
async function gitTagHead(tagName) {
try {
return await git(['rev-list', '-1', tagName]);
} catch (err) {
debug(err);
return null;
}
}

/**
* Unshallow the git repository (retrieving every commit and tags).
* Adapted from: https://github.com/semantic-release/npm/blob/cf039fdafda1a5ce43c2a5f033160cd46487f102/lib/git.js
*/
const unshallow = () =>
git(['fetch', '--unshallow', '--tags'], { reject: false });

module.exports = {
getCommitFiles,
getGitRoot,
gitTagHead,
unshallow,
};
29 changes: 27 additions & 2 deletions src/with-version-head.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
const getVersionHead = require('semantic-release/lib/get-version-head');
const {
always,
curryN,
equals,
isNil,
pipeP,
tap,
unless,
when,
} = require('ramda');

const debug = require('debug')('semantic-release:monorepo');
const gitTag = require('./version-to-git-tag');
const { gitTagHead, unshallow } = require('./git-utils');

/**
* Attempt to find the git tag for the given tag name.
* Will "unshallow" the repo and try again if not successful.
* Adapted from: https://github.com/semantic-release/npm/blob/cf039fdafda1a5ce43c2a5f033160cd46487f102/lib/get-version-head.js
*/
const getTagHead = tagName =>
pipeP(
gitTagHead,
when(isNil, pipeP(unshallow, always(tagName))),
when(equals(tagName), gitTagHead),
unless(isNil, tap(curryN(2, debug)('Use tagHead: %s')))
)(tagName);

/**
* Multiple problems identifying the "version head" for a monorepo package:
Expand All @@ -17,7 +42,7 @@ const withVersionHead = plugin => async (pluginConfig, options) => {
if (release) {
return {
...release,
...(await getVersionHead(null, await gitTag(release.version))),
gitHead: await getTagHead(await gitTag(release.version)),
};
}
};
Expand Down
Loading

0 comments on commit 5592025

Please sign in to comment.