Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
feat: add full functionality
Browse files Browse the repository at this point in the history
Add all intended functionality:
	[x] Fully compatable with semantic-release 4.0.0 plugin API
	[x] Gets last version from git tag
	[x] Calls callback with an error or a proper release object

Fixes semantic-release/semantic-release#56
  • Loading branch information
ariporad committed Aug 20, 2015
1 parent 162a0c5 commit 3802cdb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
}
},
"dependencies": {
"@semantic-release/error": "^1.0.0",
"lodash": "^3.10.1"
},
"devDependencies": {
"babel": "^5.5.8",
Expand Down Expand Up @@ -53,4 +55,4 @@
"test:style": "standard",
"test:suite": "nyc tap --no-cov .test/{scenarios,specs}/*.js"
}
}
}
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { exec } = require('child_process')

module.exports = function (pluginConfig, config, cb) {
exec('git tag', (err, stdout, stderr) => {
if (err) return cb(err)

const versionRegex = /^v((?:[0-9]+\.){2}[0-9]+)$/

const tags = stdout
.trim()
.split('\n')
.map(tag => tag.trim())
.filter(tag => versionRegex.test(tag))

if (tags.length < 1) return cb(null, {})

const tag = tags.pop()
const version = tag.match(versionRegex)[1]

cb(null, {
version: version,
gitHead: tag
})
})
}
20 changes: 20 additions & 0 deletions tests/specs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { defaults } = require('lodash')
const test = require('tap').test

const lastRelease = require('../../dist')

test('last release from git tags', (t) => {
t.plan(1)

t.test('TODO', (tt) => {
lastRelease({}, {
pkg: {name: 'available'}
}, (err, release) => {
tt.error(err)
tt.is(release.version, '1.33.7', 'version')
tt.is(release.gitHead, 'HEAD', 'gitHead')

tt.end()
})
})
})

0 comments on commit 3802cdb

Please sign in to comment.