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 |
|
22 | For example, in Travis CI's "Settings" tab for your project, you'll see:
|
23 | > ![tokens](tokens.png)
|
24 |
|
25 | For your `GH_TOKEN` [create one in Github](https://github.com/settings/tokens)
|
26 | with `repo` credentials.
|
27 |
|
28 | You can find `NPM_TOKEN` in your `~/.npmrc` file:
|
29 |
|
30 | ```
|
31 | //registry.npmjs.org/:_authToken=${NPM_TOKEN}
|
32 | ```
|
33 |
|
34 | Once these are in place, your new versions can be pushed back to Github & NPM
|
35 | without permissions & security issues.
|
36 |
|
37 | ### 3. Create labels
|
38 |
|
39 | From 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 |
|
45 | Add 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 |
|
69 | Sometimes a PR should not increment and publish a new version, for example, when updating dependencies, tests, or docs. To support
|
70 | this, 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 |
|
85 | Add one of your _custom defined labels_ to your open PRs:
|
86 |
|
87 | As these get merged, `github-semantic-version` will use this to determine
|
88 | how to bump the current version. _PRs merged without a label will be treated
|
89 | as `patch` releases._
|
90 |
|
91 | _If any un-tagged commits are pushed to `master` outside of a PR, they're
|
92 | automatically treated as `patch` releases._
|
93 |
|
94 | ### 5. Update `.travis.yml`
|
95 |
|
96 | ```yaml
|
97 | sudo: false
|
98 | language: node_js
|
99 | cache:
|
100 | directories:
|
101 | - node_modules
|
102 | notifications:
|
103 | email: false
|
104 | branches:
|
105 | except:
|
106 | - /^v[0-9]/
|
107 | deploy:
|
108 | provider: script
|
109 | script: npm run release
|
110 | skip_cleanup: true
|
111 | on:
|
112 | branch: master
|
113 | ```
|
114 |
|
115 | ### 6. Usage
|
116 |
|
117 | As 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 |
|
123 | Displays the usage information.
|
124 |
|
125 | `github-semantic-version --bump`
|
126 |
|
127 | Update 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 |
|
133 | Generates a fresh CHANGELOG based on labeled PRs and any commits to `master` outside
|
134 | of 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 |
|
138 | The expected workflow here is to ensure parity between the calculated version/changelog and your current repo version. Once that happens, you'll
|
139 | want to manually commit those changes (adding github-semantic-version as a dependency, the new npm scripts to run on CI success, the CHANGELOG,
|
140 | updated package.json, etc.) to master (or merge a labeled PR). Once CI builds successfully, these additions will be noted in the CHANGELOG (assuming
|
141 | that you specified the `--changelog` flag in your npm scripts).
|
142 |
|
143 | `github-semantic-version --changelog`
|
144 |
|
145 | Append the latest change to an
|
146 | existing CHANGELOG (must have already been generated by the `--init` flag above).
|
147 |
|
148 | You'll want to run `github-semantic-version --init` outside of CI to generate the initial CHANGELOG
|
149 | before enabling the `--changelog` flag.
|
150 |
|
151 | `github-semantic-version --bump --changelog`
|
152 |
|
153 | Bump the version and append the latest change to the CHANGELOG.
|
154 |
|
155 | `github-semantic-version --bump --changelog --push`
|
156 |
|
157 | Bump 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 |
|
161 | Bump the version, append the latest change to the CHANGELOG, push to Github, and publish to NPM.
|
162 |
|
163 | #### Other flags
|
164 |
|
165 | `--force`
|
166 |
|
167 | The 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 |
|
171 | Append this to see output of what _would_ happen without any writing to files, pushing to Github, or publishing to NPM.
|
172 |
|
173 | #### Debug
|
174 |
|
175 | Prepend `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 |
|
190 | You can add a `startVersion` to the `gsv` section of `package.json` (or to `gsv.json`) that will be used as the starting point to
|
191 | calculate 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 |
|
202 | If you're working on a private project, you can leave out `--publish`, which
|
203 | means you have no need for your `NPM_TOKEN` either.
|
204 |
|
205 | #### github
|
206 |
|
207 | You can add a `github` object to the `gsv` section of `package.json` (or to `gsv.json`),
|
208 | which 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 |
|
222 | By 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 |
|
234 | Define 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
|