@@ -25,6 +25,7 @@ const fs = require('fs')
2525const rimraf = require ( 'rimraf' )
2626const replaceLib = require ( './replaceLib' )
2727const stripCode = require ( 'gulp-strip-code' )
28+ const compareVersions = require ( 'compare-versions' )
2829
2930const cwd = process . cwd ( )
3031const libDir = path . join ( cwd , 'lib' )
@@ -173,7 +174,6 @@ function githubRelease () {
173174 const [ _ , owner , repo ] = execSync ( 'git remote get-url origin' ) // eslint-disable-line
174175 . toString ( )
175176 . match ( / g i t h u b .c o m [: / ] ( .+ ) \/ ( .+ ) \. g i t / )
176-
177177 github . repos . createRelease ( {
178178 owner,
179179 repo,
@@ -236,6 +236,9 @@ function pub (done) {
236236 }
237237 } )
238238}
239+ // gulp.task('test', () => {
240+ // githubRelease()
241+ // })
239242
240243gulp . task ( 'dist' , [ 'compile' ] , ( done ) => {
241244 dist ( done )
@@ -261,6 +264,43 @@ gulp.task('pub', ['check-git', 'compile'], (done) => {
261264 }
262265} )
263266
267+ gulp . task ( 'pub-with-ci' , ( done ) => {
268+ if ( process . env . NPM_TOKEN ) {
269+ console . log ( 'NPM token found, skip' )
270+ } else {
271+ const github = new GitHub ( )
272+ github . authenticate ( {
273+ type : 'oauth' ,
274+ token : process . env . GITHUB_TOKEN ,
275+ } )
276+ const [ _ , owner , repo ] = execSync ( 'git remote get-url origin' ) // eslint-disable-line
277+ . toString ( )
278+ . match ( / g i t h u b .c o m [: / ] ( .+ ) \/ ( .+ ) \. g i t / )
279+ const getLatestRelease = github . repos . getLatestRelease ( {
280+ owner,
281+ repo,
282+ } )
283+ const getCommits = github . repos . getCommits ( {
284+ owner,
285+ repo,
286+ per_page : 1 ,
287+ } )
288+ Promise . all ( [ getLatestRelease , getCommits ] ) . then ( ( [ latestRelease , commits ] ) => {
289+ const preVersion = latestRelease . data . tag_name
290+ const { version } = packageJson
291+ const [ _ , newVersion ] = commits . data [ 0 ] . commit . message . trim ( ) . match ( / b u m p ( .+ ) / ) || [ ]
292+ if ( compareVersions ( version , preVersion ) === 1 && newVersion && newVersion . trim ( ) === version ) {
293+ gulp . run ( 'pub' , ( err ) => {
294+ err && console . log ( 'err' , err )
295+ done ( )
296+ } )
297+ } else {
298+ console . log ( 'donot need publish' + version )
299+ }
300+ } )
301+ }
302+ } )
303+
264304function reportError ( ) {
265305 console . log ( chalk . bgRed ( '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' ) )
266306 console . log ( chalk . bgRed ( '!! `npm publish` is forbidden for this package. !!' ) )
0 commit comments