├── .babelrc ├── .travis.yml ├── .eslintrc.json ├── .gitignore ├── src.js ├── LICENSE ├── package.json └── README.md /.babelrc: -------------------------------------------------------------------------------- 1 | { "presets": ["latest"] } 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | after_success: 6 | if ([ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]); then 7 | eval 'npm run semantic-release'; 8 | fi 9 | branches: 10 | except: 11 | - /^v\d+\.\d+\.\d+$/ 12 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "airbnb" 4 | ], 5 | "rules": { 6 | "indent": ["error", 4], 7 | "no-var": "error", 8 | "comma-dangle": ["error", "never"], 9 | "no-plusplus": 0 10 | }, 11 | "env": { 12 | "node": true 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | index.js 40 | -------------------------------------------------------------------------------- /src.js: -------------------------------------------------------------------------------- 1 | const { execSync } = require('child_process'); 2 | const { clean, lt } = require('semver'); 3 | 4 | module.exports = (config, pluginConfig, callback) => { 5 | const refs = execSync('git show-ref --tags').toString('utf-8').trim().split('\n'); 6 | let latestVersion; 7 | let latestVersionCommitHash; 8 | 9 | for (let i = 0; i < refs.length; i++) { 10 | const ref = refs[i]; 11 | const [commitHash, refName] = ref.split(' '); 12 | const version = clean(refName.split('/')[2]); 13 | 14 | // version is null if not valid 15 | if (version && (!latestVersion || lt(latestVersion, version))) { 16 | latestVersion = version; 17 | latestVersionCommitHash = commitHash; 18 | } 19 | } 20 | 21 | if (!latestVersion) { 22 | throw Error('There is no valid semver git tag. Create the first valid tag via "git tag v0.0.0" and then push it via "git push --tags".'); 23 | } 24 | 25 | callback(null, { 26 | version: latestVersion, 27 | gitHead: latestVersionCommitHash 28 | }); 29 | }; 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Andrey Gubanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "last-release-git", 3 | "version": "0.0.0-auto", 4 | "description": "semantic-release plugin: get latest release version based on git tags", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "eslint src.js", 8 | "prepublish": "babel src.js --out-file index.js", 9 | "semantic-release": "semantic-release pre && npm publish && semantic-release post", 10 | "upgrade": "ncu -a && npm install" 11 | }, 12 | "config": { 13 | "validate-commit-msg": { 14 | "types": [ 15 | "feat", 16 | "fix", 17 | "refactor", 18 | "perf", 19 | "test", 20 | "chore", 21 | "revert" 22 | ] 23 | }, 24 | "ghooks": { 25 | "commit-msg": "validate-commit-msg" 26 | } 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/finom/last-release-git.git" 31 | }, 32 | "author": "Andrey Gubanov", 33 | "license": "MIT", 34 | "bugs": { 35 | "url": "https://github.com/finom/last-release-git/issues" 36 | }, 37 | "homepage": "https://github.com/finom/last-release-git#readme", 38 | "dependencies": { 39 | "semver": "^5.4.1" 40 | }, 41 | "devDependencies": { 42 | "babel-cli": "^6.26.0", 43 | "babel-preset-latest": "^6.24.1", 44 | "eslint": "^4.8.0", 45 | "eslint-config-airbnb": "^15.1.0", 46 | "eslint-plugin-import": "^2.7.0", 47 | "eslint-plugin-jsx-a11y": "^5.1.1", 48 | "eslint-plugin-react": "^7.4.0", 49 | "ghooks": "^2.0.0", 50 | "npm-check-updates": "^2.12.1", 51 | "semantic-release": "^8.0.3", 52 | "validate-commit-msg": "^2.14.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # last-release-git [![npm version](https://badge.fury.io/js/last-release-git.svg)](https://badge.fury.io/js/last-release-git) [![Build Status](https://travis-ci.org/finom/last-release-git.svg?branch=master)](https://travis-ci.org/finom/last-release-git) 2 | 3 | This is [getLastRelease](https://github.com/semantic-release/semantic-release#getlastrelease) plugin for older versions of [semantic-release](https://github.com/semantic-release/semantic-release). It's made for projects which must not be published at NPM. 4 | 5 | By default **semantic-release** extracts latest version from NPM registry but **last-release-git** extracts it from git tags. 6 | 7 | ## Getting started 8 | 9 | Install the plugin: 10 | 11 | ```sh 12 | npm install last-release-git --save-dev 13 | ``` 14 | 15 | Add **release** field to your **package.json** as described at [plugins documentation](https://github.com/semantic-release/semantic-release#plugins): 16 | 17 | ```json 18 | "release": { 19 | "getLastRelease": "last-release-git" 20 | } 21 | ``` 22 | 23 | Make sure your travis build fetches your git tags before running `semantic-release`. If you have no special `git` commands in your `.travis.yml` file, make sure to fetch all tags in your `after_success` section like this: 24 | ```yaml 25 | after_success: 26 | - git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/* 27 | - git fetch --tags 28 | - npm run semantic-release 29 | ``` 30 | 31 | Create the first git tag manually and push it: 32 | ```sh 33 | git tag v0.0.0 34 | git push --tags 35 | ``` 36 | 37 | That's it. 38 | 39 | The last thing you may want to do is to set dummy ``NPM_TOKEN`` environment variable at CI (**semantic-release** throws an error if it doesn't exist) like this one: ``00000000-0000-0000-0000-000000000000``. 40 | --------------------------------------------------------------------------------