1
1
const analyzeCommits = require ( '@semantic-release/commit-analyzer' )
2
+ const SemanticReleaseError = require ( '@semantic-release/error' )
3
+ const execSync = require ( 'child_process' ) . execSync ;
4
+
5
+ const until = f => array => {
6
+ const first = array [ 0 ] ;
7
+
8
+ if ( ! first || f ( first ) ) {
9
+ return [ ] ;
10
+ }
11
+
12
+ return [ first , ...until ( f ) ( array . slice ( 1 ) ) ] ;
13
+ } ;
14
+
15
+ const lastTaggedRelease = ( ) => execSync ( 'git rev-list -1 `git describe --tags --abbrev=0 --match "v[0-9]*"`' , { encoding : 'utf8' } ) . trim ( ) ;
2
16
3
17
module . exports = function ( pluginConfig , config , cb ) {
4
18
// run standard commit analysis
5
19
return analyzeCommits ( pluginConfig , config , function ( error , type ) {
6
20
const branch = config . env . TRAVIS_BRANCH || config . env . GIT_LOCAL_BRANCH ;
7
21
const branchTags = config . options . branchTags ;
8
22
const distTag = branchTags && branchTags [ branch ] ;
9
- let releaseType = type ;
10
23
11
- // if branch publishes a dist-tag
12
- if ( type && distTag ) {
24
+ // use default behavior if not publishing a custom dist-tag
25
+ if ( ! distTag ) {
26
+ return cb ( error , type ) ;
27
+ }
28
+
29
+ let releaseType = type ;
30
+ if ( type ) {
13
31
// map all types of releases to prereleases
14
32
releaseType = {
15
33
'major' : 'premajor' ,
@@ -20,7 +38,23 @@ module.exports = function (pluginConfig, config, cb) {
20
38
console . log ( "Publishing a " + releaseType + " release." ) ;
21
39
}
22
40
23
- cb ( error , releaseType ) ;
41
+ // suppress NPM releases of non-feature commits (chore/docs/etc)
42
+ const lastReleaseHash = lastTaggedRelease ( ) ;
43
+ const untilLastRelease = until ( commit => commit . hash === lastReleaseHash ) ;
44
+ const commits = untilLastRelease ( config . commits ) ;
45
+ const commitSubset = Object . assign ( { } , config , { commits } ) ;
46
+
47
+ analyzeCommits ( pluginConfig , commitSubset , function ( _ , type ) {
48
+ if ( ! type ) {
49
+ // commits since last dist-tag release are empty, suppress release
50
+ return cb ( new SemanticReleaseError (
51
+ 'There are no relevant changes, so no new version is released.' ,
52
+ 'ENOCHANGE'
53
+ ) ) ;
54
+ }
55
+
56
+ cb ( error , releaseType ) ;
57
+ } ) ;
24
58
} ) ;
25
59
} ;
26
60
0 commit comments