UNPKG

6.85 kBMarkdownView Raw
1# github-semantic-version
2
3> Automated semantic version releases powered by Github Issues.
4
5[![travis build](https://img.shields.io/travis/ericclemmons/github-semantic-version.svg)](https://travis-ci.org/ericclemmons/github-semantic-version)
6[![version](https://img.shields.io/npm/v/github-semantic-version.svg)](http://npm.im/github-semantic-version)
7[![downloads](https://img.shields.io/npm/dm/github-semantic-version.svg)](http://npm-stat.com/charts.html?package=github-semantic-version)
8[![MIT License](https://img.shields.io/npm/l/github-semantic-version.svg)](http://opensource.org/licenses/MIT)
9
10- - -
11
12## Getting Started
13
14### 1. Install
15
16```shell
17$ npm install --save-dev github-semantic-version
18```
19
20### 2. Add `GH_TOKEN` & `NPM_TOKEN` to CI
21
22For example, in Travis CI's "Settings" tab for your project, you'll see:
23> ![tokens](tokens.png)
24
25For your `GH_TOKEN` [create one in Github](https://github.com/settings/tokens)
26with `repo` credentials.
27
28You can find `NPM_TOKEN` in your `~/.npmrc` file:
29
30```
31//registry.npmjs.org/:_authToken=${NPM_TOKEN}
32```
33
34Once these are in place, your new versions can be pushed back to Github & NPM
35without permissions & security issues.
36
37### 3. Create labels
38
39From your repo's `Issues > Labels` section, add three labels representing the major, minor, and patch level changes in your repo. Ex:
40
41- "Version: Major"
42- "Version: Minor"
43- "Version: Patch"
44
45Add your label definitions to a `gsv` section of `package.json`, to a `gsv.json` file, or a `.gsvrc` file in the base directory of your project.
46
47##### package.json example
48```json
49{
50 "gsv": {
51 "majorLabel": "Version: Major",
52 "minorLabel": "Version: Minor",
53 "patchLabel": "Version: Patch"
54 }
55}
56```
57
58##### gsv.json or .gsvrc example
59```json
60{
61 "majorLabel": "Version: Major",
62 "minorLabel": "Version: Minor",
63 "patchLabel": "Version: Patch"
64}
65```
66
67#### Non-version Labels
68
69Sometimes a PR should not increment and publish a new version, for example, when updating dependencies, tests, or docs. To support
70this, a 4th label named `internalLabel` can be used. When this label is found on a PR, it will be skipped.
71
72```json
73{
74 "gsv": {
75 "majorLabel": "Version: Major",
76 "minorLabel": "Version: Minor",
77 "patchLabel": "Version: Patch",
78 "internalLabel": "No version: Internal"
79 }
80}
81```
82
83### 4. Add labels to issues
84
85Add one of your _custom defined labels_ to your open PRs:
86
87As these get merged, `github-semantic-version` will use this to determine
88how to bump the current version. _PRs merged without a label will be treated
89as `patch` releases._
90
91_If any un-tagged commits are pushed to `master` outside of a PR, they're
92automatically treated as `patch` releases._
93
94### 5. Update `.travis.yml`
95
96```yaml
97sudo: false
98language: node_js
99cache:
100 directories:
101 - node_modules
102notifications:
103 email: false
104branches:
105 except:
106 - /^v[0-9]/
107deploy:
108 provider: script
109 script: npm run release
110 skip_cleanup: true
111 on:
112 branch: master
113```
114
115### 6. Usage
116
117As automation related to your code and publishing to the world can sometimes be scary, `github-semantic-version` operates with an _additive functionality_ philosophy.
118
119#### Options
120
121`github-semantic-version`
122
123Displays the usage information.
124
125`github-semantic-version --bump`
126
127Update the package version, no CHANGELOG, don't push to Github, don't publish to NPM.
128
129_Meant to be used in a CI environment._
130
131`github-semantic-version --init`
132
133Generates a fresh CHANGELOG based on labeled PRs and any commits to `master` outside
134of any PR. Also calculates the package version based on those PRs and commits. Won't push to Github or publish to NPM.
135
136_Meant to be used outside of a CI environment to generate the initial CHANGELOG._
137
138The expected workflow here is to ensure parity between the calculated version/changelog and your current repo version. Once that happens, you'll
139want to manually commit those changes (adding github-semantic-version as a dependency, the new npm scripts to run on CI success, the CHANGELOG,
140updated package.json, etc.) to master (or merge a labeled PR). Once CI builds successfully, these additions will be noted in the CHANGELOG (assuming
141that you specified the `--changelog` flag in your npm scripts).
142
143`github-semantic-version --changelog`
144
145Append the latest change to an
146existing CHANGELOG (must have already been generated by the `--init` flag above).
147
148You'll want to run `github-semantic-version --init` outside of CI to generate the initial CHANGELOG
149before enabling the `--changelog` flag.
150
151`github-semantic-version --bump --changelog`
152
153Bump the version and append the latest change to the CHANGELOG.
154
155`github-semantic-version --bump --changelog --push`
156
157Bump the version, append the latest change to the CHANGELOG, and push the changes to Github.
158
159`github-semantic-version --bump --changelog --push --publish`
160
161Bump the version, append the latest change to the CHANGELOG, push to Github, and publish to NPM.
162
163#### Other flags
164
165`--force`
166
167The flags `--bump` and `--changelog` are meant to be used in a CI environment. _Override this if you know what you're doing._
168
169`--dry-run`
170
171Append this to see output of what _would_ happen without any writing to files, pushing to Github, or publishing to NPM.
172
173#### Debug
174
175Prepend `DEBUG=github-semantic-version:*` to the `github-semantic-version` command to show all debug output when running.
176
177### 7. Update `package.json`
178
179```json
180{
181 "scripts": {
182 "prerelease": "npm run build",
183 "release": "github-semantic-version --bump --changelog --push --publish"
184 }
185}
186```
187
188#### startVersion
189
190You can add a `startVersion` to the `gsv` section of `package.json` (or to `gsv.json`) that will be used as the starting point to
191calculate the package version of a repo. Ex:
192
193```json
194{
195 "gsv": {
196 "startVersion": "2.5.0",
197 "majorLabel": "Version: Major"
198 }
199}
200```
201
202If you're working on a private project, you can leave out `--publish`, which
203means you have no need for your `NPM_TOKEN` either.
204
205#### github
206
207You can add a `github` object to the `gsv` section of `package.json` (or to `gsv.json`),
208which are options that will be passed to the [Github API](https://www.npmjs.com/package/github).
209
210```json
211{
212 "gsv": {
213 "github": {
214 "host": "github.my-GHE-enabled-company.com"
215 }
216 }
217}
218```
219
220#### abortOnMissingLabel
221
222By default, all PRs without a label will default to "patch". If you'd prefer to skip the PR instead of releasing, use the `abortOnMissingLabel` option.
223
224```json
225{
226 "gsv": {
227 "abortOnMissingLabel": true
228 }
229}
230```
231
232#### addReleasedLabelOnSuccess
233
234Define the `addReleasedLabelOnSuccess` and `releasedLabel` options to add a label to a PR once it has been successfully published.
235
236```json
237{
238 "gsv": {
239 "releasedLabel": "Released",
240 "addReleasedLabelOnSuccess": true
241 }
242}
243```
244
245> The `releasedLabel` defaults to "Released".
246
247### License
248
249> MIT License 2016 © Eric Clemmons