Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a4334fbfd | ||
|
|
41d9b7e984 | ||
|
|
9951cf7e00 | ||
|
|
2d14c53b11 | ||
|
|
277d9ab4e2 | ||
|
|
4612a056a3 | ||
|
|
8c44c3176a | ||
|
|
dd60b461a6 | ||
|
|
88b5895f80 | ||
|
|
1ceae83ad9 | ||
|
|
12b35396d8 | ||
|
|
33dfcffe2c | ||
|
|
f534c57215 | ||
|
|
9c5288460d | ||
|
|
0c79a9b4bf | ||
|
|
3f8559731f | ||
|
|
f148a61339 | ||
|
|
5b3bdd226f | ||
|
|
64d84a0e84 | ||
|
|
1fa6d50264 | ||
|
|
6145bc9ba5 | ||
|
|
609b46f1cf | ||
|
|
76cd99c3a5 | ||
|
|
22dc640117 | ||
|
|
af90de989e | ||
|
|
aa012b3023 | ||
|
|
5724b19e23 | ||
|
|
97a8e73b01 | ||
|
|
51e12a3a4b | ||
|
|
afd6ab754d | ||
|
|
f80e056e13 | ||
|
|
b10c8910fb | ||
|
|
3295f9570c | ||
|
|
6a172e1720 | ||
|
|
68f975382d | ||
|
|
462c51dc2a | ||
|
|
cdf705cb8a | ||
|
|
9a51b0271d | ||
|
|
14618c81c9 | ||
|
|
35da08d074 | ||
|
|
73138f8a8f | ||
|
|
d7f5d19073 | ||
|
|
f239f2f402 | ||
|
|
2be6e5d34a | ||
|
|
a5cb9ea7f7 | ||
|
|
15e6daf7cc | ||
|
|
2326cda3f0 | ||
|
|
4afb280bee | ||
|
|
7da7695ba1 | ||
|
|
41125ee8aa | ||
|
|
cca50ef154 | ||
|
|
4807dee1e2 | ||
|
|
f89792e25b | ||
|
|
4078638ce9 | ||
|
|
89ded2d79c | ||
|
|
0a89265ae7 | ||
|
|
ad2a61586e | ||
|
|
45e04be49a | ||
|
|
d9b95940db | ||
|
|
2e18266023 | ||
|
|
9aef361da9 | ||
|
|
d57cb70c56 | ||
|
|
4b64afefe4 | ||
|
|
bca89a5274 | ||
|
|
f579d76596 | ||
|
|
07eb9f845c | ||
|
|
08b97e9a5f | ||
|
|
4b22426873 | ||
|
|
c7686752ab | ||
|
|
342064f198 | ||
|
|
5b387657a7 | ||
|
|
3141a7616b | ||
|
|
eec7c94b21 | ||
|
|
24f131adb4 | ||
|
|
95d9142d27 | ||
|
|
79b737e868 | ||
|
|
adc65e4950 | ||
|
|
2644badeec | ||
|
|
6492693489 | ||
|
|
045909e7e5 | ||
|
|
66454e7e46 | ||
|
|
5e73831e6e | ||
|
|
8491deb5c6 | ||
|
|
e03ecfe0b4 | ||
|
|
a1ab8ee34e | ||
|
|
b1130efc5a | ||
|
|
3ee0945995 | ||
|
|
c76a8c8f2d | ||
|
|
7bd9e74aa7 | ||
|
|
6f5c9f0890 | ||
|
|
bb63f9de41 | ||
|
|
032b493696 | ||
|
|
5cdc732b68 | ||
|
|
c8ec292e39 | ||
|
|
88334523e4 | ||
|
|
224c8048ac | ||
|
|
c5dd9121f7 | ||
|
|
07d2a1907a | ||
|
|
006213b9ca | ||
|
|
9baeddf712 | ||
|
|
ace79e745a | ||
|
|
877514799b | ||
|
|
8d7b787e4a | ||
|
|
3648cd21e1 | ||
|
|
de4bd7750e | ||
|
|
143987d070 | ||
|
|
02c4992440 | ||
|
|
abe4da1aa3 | ||
|
|
f2a94e50f1 | ||
|
|
3c14c5747f | ||
|
|
8cc6e0ced9 | ||
|
|
2613d5df91 | ||
|
|
ce04093b12 | ||
|
|
fea11ef155 | ||
|
|
6702531770 | ||
|
|
3f64ee625e | ||
|
|
1b8a01472e | ||
|
|
c1c3848d0b | ||
|
|
1a0b702002 | ||
|
|
066e1dd4d1 | ||
|
|
e900d5eae7 | ||
|
|
f4f783ba6f | ||
|
|
9eba8bf7c7 | ||
|
|
754ef3b12b | ||
|
|
a1eb9a25bb | ||
|
|
268d5f37bf | ||
|
|
269fb519bf | ||
|
|
172718df54 | ||
|
|
19150d84fb | ||
|
|
26e2afc152 | ||
|
|
927e930bb9 | ||
|
|
785140f80c | ||
|
|
e19b1952d1 | ||
|
|
ef872e38fb | ||
|
|
ba40ffe70d | ||
|
|
c614fe4a74 | ||
|
|
81de8ae19b | ||
|
|
df5f8337e8 | ||
|
|
cb3992595e | ||
|
|
a3f561d1d1 | ||
|
|
143457e03d | ||
|
|
2c17773c75 | ||
|
|
0a17e8e780 | ||
|
|
a7270bb84c | ||
|
|
0e013c2dea | ||
|
|
e1baf1892a | ||
|
|
ef1623210b | ||
|
|
ad9501540e | ||
|
|
7af30f0ad4 | ||
|
|
4aa908804c | ||
|
|
451378117d | ||
|
|
23221cc044 | ||
|
|
7a4c89f131 | ||
|
|
2405453f2d | ||
|
|
a16c36ed4d | ||
|
|
5cc7da6035 | ||
|
|
a2d6db2ce5 | ||
|
|
700ec9d4ca | ||
|
|
7b8f632396 | ||
|
|
b47311d565 | ||
|
|
810b3533dd | ||
|
|
b397ffe91f | ||
|
|
471a67fc31 | ||
|
|
557c46b8dd | ||
|
|
7ceac76689 | ||
|
|
77349fcdf1 | ||
|
|
aae79cab72 | ||
|
|
55364ded40 | ||
|
|
3a7be436e9 | ||
|
|
2b284fcc90 | ||
|
|
fb1aa80f26 | ||
|
|
05490fe229 | ||
|
|
76d9e3d2be | ||
|
|
776ffd1256 | ||
|
|
494f851ee7 | ||
|
|
3bdeff3468 | ||
|
|
8dd79565d0 | ||
|
|
a344f32e36 | ||
|
|
e1c1b7419b | ||
|
|
3eb842c297 | ||
|
|
ddaec4f2bf | ||
|
|
22a283a027 | ||
|
|
d9eeb3fcae | ||
|
|
8892ec7f7a | ||
|
|
cf27cd16cc | ||
|
|
152d1f6874 | ||
|
|
626315e9fe | ||
|
|
f5573f7494 | ||
|
|
2d3506cda1 | ||
|
|
72f9f8ea7c | ||
|
|
59d852d6fb | ||
|
|
ed05101a61 | ||
|
|
431babb42e | ||
|
|
dbea5cc1b1 | ||
|
|
6cf1711151 | ||
|
|
ba5222af52 | ||
|
|
b1d9985ba3 | ||
|
|
13e2f5ce78 | ||
|
|
af15fb4c61 | ||
|
|
caf09c9be0 | ||
|
|
0316babf7a | ||
|
|
43c8df0bfe | ||
|
|
150273c8fe | ||
|
|
f247ed8741 | ||
|
|
2eff4a4467 | ||
|
|
e1d5da5864 | ||
|
|
a0190b7ad3 | ||
|
|
c6f95e4870 | ||
|
|
6d84b66c05 | ||
|
|
4d58af7145 | ||
|
|
9a3d9a9280 | ||
|
|
32c1dcf75b | ||
|
|
4093bb2dbe | ||
|
|
c59b5cac9c | ||
|
|
44a18fd5cf | ||
|
|
e24c7c3833 | ||
|
|
057e8e9759 | ||
|
|
da23c15ea5 | ||
|
|
b63a43fa53 | ||
|
|
c47ff97ab3 | ||
|
|
689f37ae2e | ||
|
|
a4fe18cade | ||
|
|
7412401d55 | ||
|
|
6df67828fe | ||
|
|
66bf8ff710 | ||
|
|
a405021d08 | ||
|
|
f79e26dcd6 | ||
|
|
861debb85e | ||
|
|
d6172b8767 | ||
|
|
f62525ad7e | ||
|
|
cce860ec03 | ||
|
|
56238887d3 | ||
|
|
ac7037d948 |
@@ -0,0 +1,11 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
+5
-6
@@ -1,10 +1,9 @@
|
||||
# common
|
||||
coverage
|
||||
node_modules
|
||||
test/registry/couch
|
||||
test/registry/data
|
||||
test/tmp
|
||||
*.log
|
||||
*.dump
|
||||
.DS_Store
|
||||
.nyc_output
|
||||
.tests
|
||||
.tmp
|
||||
|
||||
# build-artifacts
|
||||
dist
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
# common
|
||||
coverage
|
||||
node_modules
|
||||
*.log
|
||||
.nyc_output
|
||||
.tests
|
||||
.tmp
|
||||
|
||||
# source/config
|
||||
src
|
||||
*.yml
|
||||
.gitignore
|
||||
+10
-31
@@ -1,38 +1,17 @@
|
||||
sudo: false
|
||||
dist: trusty
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
- $HOME/.npm
|
||||
notifications:
|
||||
email: false
|
||||
node_js:
|
||||
- iojs-v2
|
||||
- iojs-v1
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
before_install:
|
||||
- npm i -g npm@^2.0.0
|
||||
before_script:
|
||||
- npm prune
|
||||
- curl -Lo travis_after_all.py https://raw.github.com/dmakhno/travis_after_all/master/travis_after_all.py
|
||||
- 8
|
||||
after_success:
|
||||
- python travis_after_all.py
|
||||
- export $(cat .to_export_back)
|
||||
- if [[ $BUILD_LEADER = YES ]]; then npm run coveralls; fi
|
||||
after_failure:
|
||||
- python travis_after_all.py
|
||||
- export $(cat .to_export_back)
|
||||
before_deploy:
|
||||
- rm -f travis_after_all.py .to_export_back
|
||||
after_script:
|
||||
- echo leader=$BUILD_LEADER status=$BUILD_AGGREGATE_STATUS
|
||||
deploy:
|
||||
provider: npm
|
||||
email: stephan@boennemann.me
|
||||
skip_cleanup: true
|
||||
api_key:
|
||||
secure: Lq1FZweaNr/Ah8M7h3oWQ59HTswzvcksTUfzWb/dpqNn5FECN9I+4gi79EQPD62ZbJDCuDHY0EEEDLdnaB1z8N7kOj1RtmvC1k0teTEXFsGBPS4evXakRj+AfoBAGsTaXHqBYBOvYBxJT2Md/UoOgPSQjtAdZSNsmoFb1xkngQ0=
|
||||
on:
|
||||
branch: master
|
||||
repo: boennemann/semantic-release
|
||||
condition: "$BUILD_LEADER$BUILD_AGGREGATE_STATUS = YESothers_succeeded"
|
||||
- npm run coverage:upload
|
||||
- npm run semantic-release
|
||||
services:
|
||||
- couchdb
|
||||
branches:
|
||||
except:
|
||||
- /^v\d+\.\d+\.\d+$/
|
||||
|
||||
@@ -1,185 +1,300 @@
|
||||
# semantic-release
|
||||
[](https://travis-ci.org/boennemann/semantic-release)
|
||||
[](https://coveralls.io/r/boennemann/semantic-release)
|
||||
[](https://david-dm.org/boennemann/semantic-release)
|
||||
[](https://david-dm.org/boennemann/semantic-release#info=devDependencies)
|
||||
# :package::rocket: semantic-release
|
||||
|
||||
[](https://nodei.co/npm/semantic-release/)
|
||||
**fully automated package publishing**
|
||||
|
||||
## What is `semantic-release` about?
|
||||
> **Trust us, this will change your workflow for the better.**
|
||||
|
||||
At its core `semantic-release` is a set of conventions that gives you entirely automated, semver-compliant package publishing. Luckily these conventions make sense on their own, like having meaningful commit messages.
|
||||
> – [egghead.io](https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-automating-releases-with-semantic-release)
|
||||
|
||||
[](https://www.youtube.com/watch?v=tc2UgG5L7WM&index=6&list=PLFZ5NyC0xHDaaTy6tY9p0C0jd_rRRl5Zm)
|
||||
[](https://gitter.im/semantic-release/semantic-release?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
[](https://github.com/feross/standard)
|
||||
[](http://commitizen.github.io/cz-cli/)
|
||||
|
||||
> This talk gives you a complete introduction to the underlying concepts plus a live demo at the end.
|
||||
[](https://david-dm.org/semantic-release/semantic-release/caribou)
|
||||
[](https://david-dm.org/semantic-release/semantic-release/caribou#info=devDependencies)
|
||||
|
||||
It is fully integrated into the `npm` lifecycle, so all you need to do is to configure your CI to regularly `npm publish` (i.e. for every commit).
|
||||
[](https://travis-ci.org/semantic-release/semantic-release)
|
||||
[](https://coveralls.io/github/semantic-release/semantic-release?branch=caribou)
|
||||
|
||||
It removes human decisions and emotions from version numbers and releases – suddenly, strictly following the [SemVer](http://semver.org/) spec isn't a problem anymore.
|
||||
Out of the box this is just about _commit-messages_, but you can do so much more.
|
||||
|
||||
* **Detect breaking changes** using the test suite of your last release: [cracks](https://github.com/semantic-release/cracks)
|
||||
* Detect breaking changes using your dependents’ test suites: [Help out! Implement the **dont-break** plugin](https://github.com/semantic-release/semantic-release/issues/65)
|
||||
* Detect breaking changes diffing your JSDoc interface: [Help out! Implement the **india** plugin](https://github.com/semantic-release/semantic-release/issues/66)
|
||||
* Abort releases with **insufficient test coverage**: [Help out! Implement the **istanbul** plugin](https://github.com/semantic-release/semantic-release/issues/68)
|
||||
* Abort releases with **vulnerable dependencies** in the tree: [Help out! Implement the **nsp** plugin](https://github.com/semantic-release/semantic-release/issues/67)
|
||||
* Everything you can imagine: [Build Plugins!](https://github.com/semantic-release/semantic-release#plugins)
|
||||
|
||||
| Commands | Comment
|
||||
--- | --- | ---
|
||||
| **manual/before** | <pre><code><div>npm version major</div><div>git push origin master --tags</div><div>npm publish</div></code></pre> | You **manually decide** what the **next version** is. You have to remember what major, minor and patch means. You have to remember to push both commits and tags. You have to wait for the CI to pass. |
|
||||
| **semantic-release/after** | <pre><code><div>git commit -m "fix: <message>"</div><div>git push</div></code></pre> | You **describe the changes** you’ve made. A new version is automatically published with the correct version number.
|
||||
|
||||
This removes the immediate connection between human emotions and version numbers, so strictly following the [SemVer](http://semver.org/) spec is not a problem anymore – and that’s ultimately `semantic-release`’s goal.
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th colspan="2">
|
||||
“How to Write a JavaScript Library - Automating Releases with semantic-release” – egghead.io
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<a href="https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-automating-releases-with-semantic-release"><img src="https://cloud.githubusercontent.com/assets/908178/9730739/7b1da5d8-5610-11e5-88b6-5c75fdda7ee2.png" alt="egghead.io session"></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
A free egghead.io tutorial series on how to write an open source library featuring semantic-release.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
“We fail to follow SemVer – and why it needn’t matter”
|
||||
</th>
|
||||
<th>
|
||||
“semantic-release Q&A with Kent C. Dodds”
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://www.youtube.com/watch?v=tc2UgG5L7WM&index=6&list=PLFZ5NyC0xHDaaTy6tY9p0C0jd_rRRl5Zm"><img alt="JSConfBP Talk" src="https://cloud.githubusercontent.com/assets/908178/9428178/c337ed26-49a2-11e5-8ad0-a602500a65bf.png"></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://www.youtube.com/watch?v=g6y3DnhkjrI"><img alt="Hangout on Air with Kent C. Dodds" src="https://cloud.githubusercontent.com/assets/908178/9428179/c3387318-49a2-11e5-9f5f-dccd3fbb0c1d.png"></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
This talk gives you a complete introduction to the underlying concepts of this module. 38:30
|
||||
</td>
|
||||
<td>
|
||||
A “Hangouts on Air” conversation with hands on questions and answers about how to use semantic-release. 53:52
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## How does it work?
|
||||
|
||||
Instead of dumping [lols](http://whatthecommit.com/) into our commit messages, we can take some time to think about what we changed in the codebase and write it down. Following formalized conventions it this then possible to not only generate a helpful changelog, but to determine whether a new version should be released.
|
||||
Instead of writing [meaningless commit messages](http://whatthecommit.com/), we can take our time to think about the changes in the codebase and write them down. Following formalized conventions it is then possible to generate a helpful changelog and to derive the next semantic version number from them.
|
||||
|
||||
This module ships with the [AngularJS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit), but you can [define your own](https://github.com/boennemann/semantic-release/wiki/commit-analysis).
|
||||
When `semantic-release` is set up it will do that after every successful continuous integration build of your master branch (or any other branch you specify) and publish the new version for you. This way no human is directly involved in the release process and your releases are guaranteed to be [unromantic and unsentimental](http://sentimentalversioning.org/).
|
||||
|
||||
### The `prepublish` step
|
||||
If you fear the loss of control over timing and marketing implications of software releases you should know that `semantic-release` supports [release channels](https://github.com/npm/npm/issues/2718) using `npm`’s [dist-tags](https://docs.npmjs.com/cli/dist-tag). This way you can keep control over what your users end up using by default, you can decide when to promote an automatically released version to the stable channel, and you can choose which versions to write blogposts and tweets about. You can use the same mechanism to [support older versions of your software](https://gist.github.com/boennemann/54042374e49c7ade8910), for example with important security fixes.
|
||||
|
||||
Before `npm` actually gets to publish a new version `semantic-release`'s `prepublish` step does the following:
|
||||
This is what happens in series:
|
||||
|
||||
- Extract all commits since the last version was published
|
||||
- Determine the release type (`major`|`minor`|`patch`) or abort if nothing relevant changed
|
||||
- Increase the version number accordingly
|
||||
| 1. `git push` | 2. `semantic-release pre` | 3. `npm publish` | 4. `semantic-release post` |
|
||||
| :--- | :--- | :--- | :---- |
|
||||
| New code is pushed and triggers a CI build. | Based on all commits that happened since the last release, the new version number gets written to the `package.json`. | The new version gets published to `npm`. | A changelog gets generated and a [release](https://help.github.com/articles/about-releases/) (including a git tag) on GitHub gets created. |
|
||||
|
||||
### The `publish` step
|
||||
_Note:_ The current release/tag implementation is tied to GitHub, but could be opened up to Bitbucket, GitLab, et al. Feel free to send PRs for these services.
|
||||
|
||||
`npm` does its thing.
|
||||
## Default Commit Message Format
|
||||
|
||||
### The `postpublish` step
|
||||
This module ships with the [AngularJS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit) and changelog generator, but you can [define your own](#plugins) style.
|
||||
|
||||
After `npm` published the new version the `postpublish` step does this:
|
||||
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
|
||||
format that includes a **type**, a **scope** and a **subject** ([full explanation](https://github.com/stevemao/conventional-changelog-angular/blob/master/convention.md)):
|
||||
|
||||
- Generate release notes
|
||||
- Create a new [GitHub Release](https://help.github.com/articles/about-releases/) (including a git tag) with the release notes
|
||||
|
||||
Note: The default release notes are a [changelog](https://github.com/ajoslin/conventional-changelog) that is generated from git metadata, using the AngularJS commit conventions. You can [specify your own release note generator](https://github.com/boennemann/semantic-release/wiki/release-note-generation).
|
||||
|
||||
Note: This is tied to GitHub, feel free to send PRs for other services.
|
||||
|
||||
Note: `semantic-release` works around a limitation in `npm`'s `prepublish` step. Once a version is published it prints a "Could not pack" error that you can *safely ignore* [npm/npm#7118](https://github.com/npm/npm/issues/7118).
|
||||
|
||||
## How you can set it up
|
||||
|
||||
### Installation
|
||||
|
||||
First of all you need to install `semantic-release` and save it as a `devDependency`.
|
||||
|
||||
```bash
|
||||
npm install --save-dev semantic-release
|
||||
# Btw, if you're feeling lazy you can just type this – it's the same thing.
|
||||
npm i -D semantic-release
|
||||
```
|
||||
<type>(<scope>): <subject>
|
||||
<BLANK LINE>
|
||||
<body>
|
||||
<BLANK LINE>
|
||||
<footer>
|
||||
```
|
||||
|
||||
### Package
|
||||
You can simplify using this convention for yourself and contributors by using [commitizen](https://github.com/commitizen/cz-cli) and [commitlint](https://github.com/marionebl/commitlint) or [semantic-git-commit-cli](https://github.com/JPeer264/node-semantic-git-commit-cli).
|
||||
|
||||
```bash
|
||||
./node_modules/.bin/semantic-release setup
|
||||
### Patch Release
|
||||
|
||||
```
|
||||
fix(pencil): stop graphite breaking when too much pressure applied
|
||||
```
|
||||
|
||||
What this does:
|
||||
### ~~Minor~~ Feature Release
|
||||
|
||||
#### Scripts
|
||||
```
|
||||
feat(pencil): add 'graphiteWidth' option
|
||||
```
|
||||
|
||||
The setup command configures `scripts` inside the `package.json`:
|
||||
### ~~Major~~ Breaking Release
|
||||
|
||||
```
|
||||
perf(pencil): remove graphiteWidth option
|
||||
|
||||
BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reasons.
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
[](https://nodei.co/npm/semantic-release/)
|
||||
|
||||
```bash
|
||||
npm install -g semantic-release-cli
|
||||
|
||||
cd your-module
|
||||
semantic-release-cli setup
|
||||
```
|
||||
|
||||

|
||||
|
||||
_[This is what happens under the hood.](https://github.com/semantic-release/cli#what-it-does)_
|
||||
|
||||
## Options
|
||||
|
||||
You can pass options either via command line (in [kebab-case](https://lodash.com/docs#kebabCase)) or in the `release` field of your `package.json` (in [camelCase](https://lodash.com/docs#camelCase)). The following two examples are the same, but CLI arguments take precedence.
|
||||
|
||||
| CLI | package.json |
|
||||
| --- | --- |
|
||||
| <pre><code>semantic-release pre --no-debug</code><pre> | <pre><code><div>//package.json</div><div>"release": {</div><div> "debug": false</div><div>}</div></code></pre><pre><code>semantic-release pre</code></pre> |
|
||||
|
||||
|
||||
These options are currently available:
|
||||
- `branch`: The branch on which releases should happen. Default: `'master'`
|
||||
- `debug`: If true doesn’t actually publish to npm or write things to file. Default: `!process.env.CI`
|
||||
- `githubToken`: The token used to authenticate with GitHub. Default: `process.env.GH_TOKEN`
|
||||
- `githubUrl`: Optional. Pass your GitHub Enterprise endpoint.
|
||||
- `githubApiPathPrefix`: Optional. The path prefix for your GitHub Enterprise API.
|
||||
|
||||
_A few notes on `npm` config_:
|
||||
1. The `npm` token can only be defined in the environment as `NPM_TOKEN`, because that’s where `npm` itself is going to read it from.
|
||||
|
||||
2. In order to publish to a different `npm` registry you can specify that inside the `package.json`’s [`publishConfig`](https://docs.npmjs.com/files/package.json#publishconfig) field.
|
||||
|
||||
3. If you want to use another dist-tag for your publishes than `'latest'` you can specify that inside the `package.json`’s [`publishConfig`](https://docs.npmjs.com/files/package.json#publishconfig) field.
|
||||
|
||||
4. `semantic-release` generally tries to orientate itself towards `npm` – it inherits the loglevel for example.
|
||||
|
||||
## Plugins
|
||||
|
||||
There are numerous steps where you can customize `semantic-release`’s behaviour using plugins. A plugin is a regular [option](#options), but passed inside the `release` block of `package.json`:
|
||||
|
||||
```json
|
||||
"scripts": {
|
||||
"prepublish": "semantic-release pre",
|
||||
"postpublish": "semantic-release post"
|
||||
{
|
||||
"release": {
|
||||
"analyzeCommits": "npm-module-name",
|
||||
"generateNotes": "./path/to/a/local/module",
|
||||
"verifyConditions": {
|
||||
"path": "./path/to/a/module",
|
||||
"additional": "config"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note: If you have already configured `scripts` for `prepublish` or `postpublish` they're just executed one after another. For example: `"npm run babelify && semantic-release pre"`.
|
||||
|
||||
#### Version
|
||||
|
||||
It would be preferable not to have a version field in the `package.json` at all, but due to an `npm` limitation it is required to have a _not yet published_ version in there [npm/npm#7118](https://github.com/npm/npm/issues/7118). Because of this the version gets changed to `"0.0.0-semantically-released"` until `npm` _hopefully_ removes its limitations.
|
||||
|
||||
#### Repository
|
||||
|
||||
If you haven't defined your GitHub repository in the `package.json`s [repository field](https://docs.npmjs.com/files/package.json#repository) the remote `origin`'s repository is used.
|
||||
|
||||
### CI Server
|
||||
|
||||
Inside your `.travis.yml`:
|
||||
|
||||
```yml
|
||||
language: node_js
|
||||
node_js:
|
||||
- iojs-v1
|
||||
# If you have a more sophisticated build with multiple jobs you should have a look at
|
||||
# https://github.com/dmakhno/travis_after_all which is also configured for this
|
||||
# package. (Check the .travis.yml)
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
notifications:
|
||||
email: false
|
||||
# See https://github.com/boennemann/semantic-release/issues/18
|
||||
before_deploy:
|
||||
- npm config set spin false --global
|
||||
env:
|
||||
# Get your token here: https://github.com/settings/tokens/new
|
||||
# Grant the token repo/public_repo scope (all others can be deselected)
|
||||
# You should encrypt this:
|
||||
# `travis encrypt GH_TOKEN=<token> --add`
|
||||
global: GH_TOKEN=<github-access-token-with-access-to-your-repo>
|
||||
deploy:
|
||||
provider: npm
|
||||
email: <your-npm-mail@example.com>
|
||||
# Very important. Don't forget this one.
|
||||
skip_cleanup: true
|
||||
# Travis currently only supports the old auth key format.
|
||||
# Do `echo -n "<username>:<password>" | base64` to get it.
|
||||
# You should encrypt this:
|
||||
# `travis encrypt $(echo -n "<username>:<password>" | base64) --add deploy.api_key`
|
||||
api_key: <npm-api-key>
|
||||
on:
|
||||
branch: master
|
||||
repo: <user>/<repo>
|
||||
```
|
||||
semantic-release pre --analyze-commits="npm-module-name"
|
||||
```
|
||||
|
||||
Note: This isn't tied to a specific service, but example configuration is provided for [Travis CI](https://travis-ci.org/). Feel free to contribute configuration for other servers or services.
|
||||
A plugin itself is an async function that always receives three arguments.
|
||||
|
||||
Note: You should [encrypt](http://docs.travis-ci.com/user/environment-variables/#sts=Secure Variables) your api keys and tokens. If this is a new repository, don't forget to [enable it on Travis](https://travis-ci.org/profile) to make encrypt work.
|
||||
```js
|
||||
module.exports = function (pluginConfig, config, callback) {}
|
||||
```
|
||||
|
||||
Note: Your CI environment has to export `CI=true` in order for `semantic-release` not to automatically perform a dry run. Travis CI does this by default.
|
||||
- `pluginConfig`: If the user of your plugin specifies additional plugin config in the `package.json` (see the `verifyConditions` example above) then it’s this object.
|
||||
- `config`: A config object containing a lot of information to act upon.
|
||||
- `env`: All environment variables
|
||||
- `npm`: Select npm configuration bits like `registry`, `tag` and `auth`
|
||||
- `options`: `semantic-release` options like `debug`, or `branch`
|
||||
- `pkg`: Parsed `package.json`
|
||||
- For certain plugins the `config` object contains even more information. See below.
|
||||
- `callback`: If an error occurs pass it as first argument. Otherwise pass your result as second argument.
|
||||
|
||||
Note: It is crucial that your CI server also fetches all tags when checking out your repository. Travis CI does this by default.
|
||||
|
||||
### `analyzeCommits`
|
||||
|
||||
This plugin is responsible for determining the type of the next release. It additionally receives a `commits` array inside `config`. One commit is an object with a `message` and `hash` property. Call the callback with `'major'`, `'premajor'`, `'minor'`, `'preminor'`, `'patch'`, `'prepatch'`, `'prerelease'`, or `null` if nothing changed.
|
||||
|
||||
While it may be tempting to use `'prepatch'`, `'preminor'` & `'prerelease'` as part of a release process, this is strongly discouraged. A better approach is to use [dist-tags](https://docs.npmjs.com/cli/dist-tag) to create release channels (such as 'latest', 'next', 'stable') and to return only `'major'`, `'premajor'` and `'minor'` from the commit analyzer.
|
||||
|
||||
Have a look at the [default implementation](https://github.com/semantic-release/commit-analyzer/).
|
||||
|
||||
### `generateNotes`
|
||||
|
||||
This plugin is responsible for generating release notes. Call the callback with the notes as a string. Have a look at the [default implementation](https://github.com/semantic-release/release-notes-generator/).
|
||||
|
||||
### `verifyConditions`
|
||||
|
||||
This plugins is responsible for verifying that a release should happen in the first place. For example, the [default implementation](https://github.com/semantic-release/condition-travis/) verifies that the publish is happening on Travis, that it’s the right branch, and that all other build jobs succeeded. There are more use cases for this, e.g. verifying that test coverage is above a certain threshold or that there are no [vulnerabilities](https://nodesecurity.io/) in your dependencies. Be creative.
|
||||
|
||||
Passing an array of plugins will run them in series.
|
||||
|
||||
### `verifyRelease`
|
||||
|
||||
This plugin is responsible for verifying a release that was determined before and is about to be published. There is no default implementation. It additionally receives `nextRelease`, `lastRelease` and `commits` inside `config`. While `commits` is the same as with analyzeCommits, `nextRelease` contains a `type` (e.g. `'major'`) and the new version (e.g. `'1.0.0'`) and `lastRelease` contains the old `version`, the `gitHead` at the time of the release and the npm dist-`tag` (e.g. `'latest'`). Using this information you could [detect breaking changes](https://github.com/semantic-release/cracks) or hold back certain types of releases. Again: Be creative.
|
||||
|
||||
Passing an array of plugins will run them in series.
|
||||
|
||||
### `getLastRelease`
|
||||
|
||||
This plugin is responsible for determining a package’s last release version. The [default implementation](https://github.com/semantic-release/last-release-npm) uses the last published version on a npm registry.
|
||||
|
||||
## ITYM*FAQ*LT
|
||||
> I think you might frequently ask questions like these
|
||||
|
||||
### Why is the `package.json`'s version not updated in my repository?
|
||||
### Why is the `package.json`’s version not updated in my repository?
|
||||
|
||||
The `npm` docs even state:
|
||||
|
||||
> The most important things in your package.json are the name and version fields. Those are actually required, and your package won't install without them.
|
||||
> -- [npm docs](https://docs.npmjs.com/files/package.json#version)
|
||||
> The most important things in your package.json are the name and version fields. Those are actually required, and your package won’t install without them.
|
||||
> – [npm docs](https://docs.npmjs.com/files/package.json#version)
|
||||
|
||||
While this entirely true the version number doesn't have to be checked into source control. `semantic-release` takes care of the version field right before `npm publish` uses it – and this is the only point where it _really_ is required.
|
||||
While this entirely true the version number doesn’t have to be checked into source control. `semantic-release` takes care of the version field right before `npm publish` uses it – and this is the only point where it _really_ is required.
|
||||
|
||||
### Is there a way to preview which version would currently get published?
|
||||
|
||||
If you're running `npm publish` locally `semantic-release` automatically performs a dry run. This does log the version that would currently get published, but only if you `git fetch --tags` before.
|
||||
If you run `npm run semantic-release` locally a dry run gets performed, which logs the version that would currently get published.
|
||||
|
||||
### Can I run this on my own machine rather than on a CI server?
|
||||
|
||||
Of course you can, but this doesn't necessarly mean you should. Running your tests on an independent machine before releasing software is a crucial part of this workflow. Also it is a pain to set this up locally, with GitHub tokens lying around and everything. That said, you can either set the environment variable `CI=true`, or run the scripts with `--debug=false` explicitly. Don't forget to export `GH_TOKEN=your_token` as well.
|
||||
Of course you can, but this doesn’t necessarily mean you should. Running your tests on an independent machine before releasing software is a crucial part of this workflow. Also it is a pain to set this up locally, with tokens lying around and everything. That said, you can run the scripts with `--debug=false` explicitly. You have to export `GH_TOKEN=<your_token>` and `NPM_TOKEN=<your_other_token>`.
|
||||
|
||||
### Can I manually trigger the release of a specific version?
|
||||
|
||||
You can trigger a release by pushing to your repository. You deliberately can not trigger a _specific_ version release, because this is the whole point of `semantic-release`. Start your packages with `1.0.0` and semver on.
|
||||
|
||||
Note: The default commit message conventions do not support pre-release flags, but you can build this in yourself using [custom analyzers](https://github.com/boennemann/semantic-release/wiki/commit-analysis).
|
||||
|
||||
### How do I get back to good ol' `npm publish`?
|
||||
|
||||
`npm` offers the `--ignore-scripts` flag. Doing `npm publish --ignore-scripts` doesn't execute the `prepublish` and `postpublish` scripts.
|
||||
You can trigger a release by pushing to your GitHub repository. You deliberately cannot trigger a _specific_ version release, because this is the whole point of `semantic-release`. Start your packages with `1.0.0` and semver on.
|
||||
|
||||
### Is it _really_ a good idea to release on every push?
|
||||
|
||||
It is indeed a great idea because it _forces_ you to follow best practices. If you don't feel comfortable making every passing feature or fix on your master branch addressable via `npm` you might not treat your master right. Have a look at [branch workflows](https://guides.github.com/introduction/flow/index.html). If you still think you should have control over the exact point in time of your release, e.g. because you are following a release schedule, configure your CI server to release only on the `production`/`deploy`/`release` branch and push your code there in certain intervals.
|
||||
It is indeed a great idea because it _forces_ you to follow best practices. If you don’t feel comfortable making every passing feature or fix on your master branch addressable via `npm` you might not treat your master right. Have a look at [branch workflows](https://guides.github.com/introduction/flow/index.html). If you still think you should have control over the exact point in time of your release, e.g. because you are following a release schedule, you can release only on the `production`/`deploy`/`release` branch and push your code there in certain intervals, or better yet use [dist-tags](https://docs.npmjs.com/cli/dist-tag).
|
||||
|
||||
### Why should I trust `semantic-release` with my releases? What if it breaks?
|
||||
### Why should I trust `semantic-release` with my releases?
|
||||
|
||||
`semantic-release` has a full integration-test suite that tests _actual_ `npm` publishes and _actual_ GitHub Releases (with private registry/API) on node.js `^0.10`, `^0.12` and io.js `^1`, `^2`. A new version won't get published if it doesn't pass on all these engines.
|
||||
`semantic-release` has a full unit- and integration-test-suite that tests _actual_ `npm` publishes against the [npm-registry-couchapp](https://github.com/npm/npm-registry-couchapp/). A new version won’t get published if it doesn’t pass on all these engines.
|
||||
|
||||
### Why does `semantic-release` require node version >= 8
|
||||
|
||||
Being able to write code for just the most recent node versions greatly simplifies development. More language features are available, no transpilation is required, less test builds are to be run, awaited and debugged.
|
||||
|
||||
For a special purpose tool like `semantic-release`, that's only meant to be used in controlled CI environments, we think it's okay to have such a high version requirement. As `semantic-release` handles package publishing we expect almost every project to have at least one build job running node 8 already – and that's all it takes. Even if that's not that case `semantic-release` can still be executed with the help of [npx](https://www.npmjs.com/package/npx) (`npx -p node@8 npm run semantic-release`).
|
||||
|
||||
## Badge
|
||||
|
||||
Use this in one of your projects? Include one of these badges in your README.md to let people know that your package is published using `semantic-release`.
|
||||
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
|
||||
```md
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
```
|
||||
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
|
||||
```md
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
```
|
||||
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
|
||||
```md
|
||||
[](https://github.com/semantic-release/semantic-release)
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
2015 © Stephan Bönnemann and [contributors](https://github.com/boennemann/semantic-release/graphs/contributors)
|
||||
2015 © Stephan Bönnemann and [contributors](https://github.com/semantic-release/semantic-release/graphs/contributors)
|
||||
|
||||

|
||||
[](https://twitter.com/trodrigues/status/509301317467373571)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Troubleshooting semantic-release
|
||||
|
||||
### ENOTINHISTORY Commit not in history
|
||||
|
||||
```
|
||||
semantic-release ERR! commits The commit the last release of this package was derived from is not in the direct history of the "master" branch.
|
||||
semantic-release ERR! commits This means semantic-release can not extract the commits between now and then.
|
||||
semantic-release ERR! commits This is usually caused by force pushing, releasing from an unrelated branch, or using an already existing package name.
|
||||
semantic-release ERR! commits You can recover from this error by publishing manually or restoring the commit "123".
|
||||
semantic-release ERR! pre Failed to determine new version.
|
||||
semantic-release ERR! pre ENOTINHISTORY Commit not in history
|
||||
```
|
||||
|
||||
To restore semantic-release, follow these steps:
|
||||
|
||||
```
|
||||
git pull
|
||||
git reset --hard origin/master
|
||||
npm version x.y.z # check your current version and set this based on semver rules manually
|
||||
|
||||
# if you have a PR workflow, create a new branch, otherwise commit to master
|
||||
|
||||
git checkout -B chore/release
|
||||
git commit -am 'chore: release'
|
||||
git push
|
||||
|
||||
# merge (not squash-merge) on github (this is important before running git push). This is only required when you work with branches
|
||||
git checkout master
|
||||
|
||||
# definitely required
|
||||
git pull
|
||||
git push --tags
|
||||
npm publish
|
||||
```
|
||||
+15
-34
@@ -1,44 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var readFile = require('fs').readFileSync
|
||||
// Bad news: We have to write plain ES5 in this file
|
||||
// Good news: It's the only file of the entire project
|
||||
|
||||
var minimist = require('minimist')
|
||||
var semver = require('semver')
|
||||
|
||||
var argv = minimist(process.argv.slice(2), {
|
||||
alias: {
|
||||
d: 'debug',
|
||||
dry: 'debug',
|
||||
t: 'token',
|
||||
g: 'github-url'
|
||||
},
|
||||
booleans: ['debug'],
|
||||
default: {
|
||||
debug: !process.env.CI,
|
||||
token: process.env.GH_TOKEN || process.env.TOKEN || process.env.GITHUB_TOKEN,
|
||||
'github-url': process.env.GH_URL
|
||||
}
|
||||
})
|
||||
if (semver.lt(process.version, '8.0.0')) {
|
||||
console.error(
|
||||
`semantic-release: node version >= 8 is required. Found ${process.version}.
|
||||
|
||||
var npmArgv = process.env.npm_config_argv ?
|
||||
minimist(JSON.parse(process.env.npm_config_argv).cooked) :
|
||||
{_: []}
|
||||
If there is another job running on node version >= 8, it will be picked as
|
||||
the build leader and you can safely ignore this message.
|
||||
|
||||
var plugins = JSON.parse(readFile('./package.json')).release || {}
|
||||
If you don't have node 8 in your build matrix you can use "npx" to restore
|
||||
compatibility with minimal overhead:
|
||||
|
||||
var main
|
||||
$ npx -p node@8 npm run semantic-release
|
||||
|
||||
/* istanbul ignore next */
|
||||
try {
|
||||
main = require('../dist/main')
|
||||
} catch (e) {
|
||||
require('babel/register')
|
||||
main = require('../src/main')
|
||||
npx is bundled with npm >= 5.4, or available via npm. More info: npm.im/npx`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (~argv._.indexOf('pre')) {
|
||||
main.pre(argv, npmArgv, plugins)
|
||||
} else if (~argv._.indexOf('post')) {
|
||||
main.post(argv, npmArgv, plugins)
|
||||
} else if (~argv._.indexOf('setup')) {
|
||||
main.setup(argv, npmArgv, plugins)
|
||||
}
|
||||
// node 8+ from this point on
|
||||
require('../src')
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
npm run test:style
|
||||
|
||||
function cleanup {
|
||||
set +e
|
||||
|
||||
cp .tmp/.npmrc ~/.npmrc
|
||||
|
||||
cat .tmp/sinopia.pid | xargs kill
|
||||
|
||||
cat .tmp/ghrs.pid | xargs kill
|
||||
|
||||
rm -rf .tmp
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
mkdir -p .tmp/modules
|
||||
|
||||
export DEBUG=ghrs:cli
|
||||
|
||||
./node_modules/.bin/sinopia ./tests/config.yml & echo $! >> .tmp/sinopia.pid
|
||||
./node_modules/.bin/github-release-fake-server -p 4343 & echo $! >> .tmp/ghrs.pid
|
||||
|
||||
sleep 0.5
|
||||
|
||||
cp ~/.npmrc .tmp/.npmrc
|
||||
|
||||
cp tests/.npmrc ~/.npmrc
|
||||
|
||||
npm run test:integration
|
||||
Generated
+7490
File diff suppressed because it is too large
Load Diff
+56
-48
@@ -1,54 +1,62 @@
|
||||
{
|
||||
"name": "semantic-release",
|
||||
"description": "automated semver compliant package publishing",
|
||||
"version": "0.0.0-semantically-released",
|
||||
"author": "Stephan Bönnemann <stephan@boennemann.me>",
|
||||
"bin": "./bin/semantic-release.js",
|
||||
"version": "0.0.0-placeholder",
|
||||
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
|
||||
"bin": {
|
||||
"semantic-release": "bin/semantic-release.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/boennemann/semantic-release/issues"
|
||||
"url": "https://github.com/semantic-release/semantic-release/issues"
|
||||
},
|
||||
"config": {
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
".tests",
|
||||
"node_modules"
|
||||
]
|
||||
"commitizen": {
|
||||
"path": "cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"abbrev": "^1.0.5",
|
||||
"async": "^1.0.0",
|
||||
"conventional-changelog": "0.0.17",
|
||||
"error-first-handler": "^1.0.1",
|
||||
"@semantic-release/commit-analyzer": "^3.0.1",
|
||||
"@semantic-release/condition-travis": "^6.0.0",
|
||||
"@semantic-release/error": "^2.0.0",
|
||||
"@semantic-release/last-release-npm": "^2.0.0",
|
||||
"@semantic-release/release-notes-generator": "^4.0.0",
|
||||
"git-head": "^1.2.1",
|
||||
"github": "0.2.4",
|
||||
"github-url-from-git": "^1.4.0",
|
||||
"ini": "^1.3.2",
|
||||
"minimist": "^1.1.0",
|
||||
"github": "^8.0.0",
|
||||
"lodash": "^4.0.0",
|
||||
"nerf-dart": "^1.0.0",
|
||||
"nopt": "^4.0.0",
|
||||
"normalize-package-data": "^2.3.4",
|
||||
"npmconf": "^2.1.2",
|
||||
"parse-github-repo-url": "^1.0.0",
|
||||
"request": "^2.53.0",
|
||||
"semver": "^4.3.3"
|
||||
"npmlog": "^4.0.0",
|
||||
"parse-github-repo-url": "^1.3.0",
|
||||
"require-relative": "^0.8.7",
|
||||
"run-auto": "^2.0.0",
|
||||
"run-series": "^1.1.3",
|
||||
"semver": "^5.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.2",
|
||||
"cracks": "^2.0.1",
|
||||
"github-release-fake-server": "^1.3.0",
|
||||
"lodash.defaults": "^3.0.0",
|
||||
"nano-uid": "^0.2.0",
|
||||
"nixt": "^0.4.1",
|
||||
"nock": "^2.2.0",
|
||||
"nyc": "^2.3.0",
|
||||
"sinopia": "^1.0.0",
|
||||
"standard": "^4.0.1",
|
||||
"tap": "^1.2.0"
|
||||
"coveralls": "^2.11.4",
|
||||
"cz-conventional-changelog": "^2.0.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mock-spawn": "^0.2.6",
|
||||
"nixt": "^0.5.0",
|
||||
"nock": "^9.0.2",
|
||||
"npm-registry-couchapp": "^2.6.12",
|
||||
"nyc": "^10.0.0",
|
||||
"proxyquire": "^1.7.3",
|
||||
"rimraf": "^2.5.0",
|
||||
"standard": "^9.0.0",
|
||||
"tap": "^10.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"iojs": "^1",
|
||||
"node": "^0.10",
|
||||
"npm": "^2"
|
||||
"node": ">=4",
|
||||
"npm": ">=2"
|
||||
},
|
||||
"homepage": "https://github.com/boennemann/semantic-release",
|
||||
"files": [
|
||||
"bin",
|
||||
"src"
|
||||
],
|
||||
"homepage": "https://github.com/semantic-release/semantic-release#readme",
|
||||
"keywords": [
|
||||
"author",
|
||||
"automation",
|
||||
@@ -61,24 +69,24 @@
|
||||
"version"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/main.js",
|
||||
"optionalDependencies": {
|
||||
"babel": "^5.5.6"
|
||||
"main": "bin/semantic-release.js",
|
||||
"publishConfig": {
|
||||
"tag": "next"
|
||||
},
|
||||
"release": {
|
||||
"branch": "caribou"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/boennemann/semantic-release.git"
|
||||
"url": "git+https://github.com/semantic-release/semantic-release.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && mkdir -p dist && babel src --out-dir dist",
|
||||
"build:tests": "rm -rf .tests && mkdir -p .tests && babel tests --out-dir .tests",
|
||||
"coverage": "nyc report",
|
||||
"coveralls": "npm run coverage -- --reporter=lcovonly && cat coverage/lcov.info | coveralls",
|
||||
"postpublish": "./bin/semantic-release.js post",
|
||||
"prepublish": "npm run build && ./bin/semantic-release.js pre",
|
||||
"pretest:integration": "npm run build && npm run build:tests",
|
||||
"test": "./bin/test",
|
||||
"test:integration": "nyc tap --no-cov .tests/{scenarios,tap}/*.js",
|
||||
"test:style": "standard"
|
||||
"coverage:upload": "npm run coverage -s -- --reporter=text-lcov | coveralls",
|
||||
"pretest": "standard",
|
||||
"semantic-release": "./bin/semantic-release.js pre && npm publish && ./bin/semantic-release.js post",
|
||||
"test": "npm run test:unit && npm run test:integration",
|
||||
"test:integration": "tap --no-cov test/scenarios/*.js",
|
||||
"test:unit": "nyc tap --no-cov test/specs/*.js"
|
||||
}
|
||||
}
|
||||
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var url = require('url')
|
||||
|
||||
var _ = require('lodash')
|
||||
var log = require('npmlog')
|
||||
var nopt = require('nopt')
|
||||
var npmconf = require('npmconf')
|
||||
var normalizeData = require('normalize-package-data')
|
||||
|
||||
log.heading = 'semantic-release'
|
||||
var env = process.env
|
||||
var pkg = JSON.parse(fs.readFileSync('./package.json'))
|
||||
var originalPkg = _.cloneDeep(pkg)
|
||||
normalizeData(pkg)
|
||||
var knownOptions = {
|
||||
branch: String,
|
||||
debug: Boolean,
|
||||
'github-token': String,
|
||||
'github-url': String,
|
||||
'analyze-commits': [path, String],
|
||||
'generate-notes': [path, String],
|
||||
'verify-conditions': [path, String],
|
||||
'verify-release': [path, String]
|
||||
}
|
||||
var options = _.defaults(
|
||||
_.mapKeys(nopt(knownOptions), function (value, key) {
|
||||
return _.camelCase(key)
|
||||
}),
|
||||
pkg.release,
|
||||
{
|
||||
branch: 'master',
|
||||
fallbackTags: {
|
||||
next: 'latest'
|
||||
},
|
||||
debug: !env.CI,
|
||||
githubToken: env.GH_TOKEN || env.GITHUB_TOKEN,
|
||||
githubUrl: env.GH_URL
|
||||
}
|
||||
)
|
||||
var plugins = require('../src/lib/plugins')(options)
|
||||
|
||||
npmconf.load({}, function (err, conf) {
|
||||
if (err) {
|
||||
log.error('init', 'Failed to load npm config.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var npm = {
|
||||
auth: {
|
||||
token: env.NPM_TOKEN
|
||||
},
|
||||
cafile: conf.get('cafile'),
|
||||
loglevel: conf.get('loglevel'),
|
||||
registry: require('../src/lib/get-registry')(pkg, conf),
|
||||
tag: (pkg.publishConfig || {}).tag || conf.get('tag') || 'latest'
|
||||
}
|
||||
|
||||
// normalize trailing slash
|
||||
npm.registry = url.format(url.parse(npm.registry))
|
||||
|
||||
log.level = npm.loglevel
|
||||
|
||||
var config = {
|
||||
env: env,
|
||||
pkg: pkg,
|
||||
options: options,
|
||||
plugins: plugins,
|
||||
npm: npm
|
||||
}
|
||||
|
||||
var hide = {}
|
||||
if (options.githubToken) hide.githubToken = '***'
|
||||
|
||||
log.verbose('init', 'options:', _.assign({}, options, hide))
|
||||
log.verbose('init', 'Verifying config.')
|
||||
|
||||
var errors = require('../src/lib/verify')(config)
|
||||
errors.forEach(function (err) {
|
||||
log.error('init', err.message + ' ' + err.code)
|
||||
})
|
||||
if (errors.length) process.exit(1)
|
||||
|
||||
if (options.argv.remain[0] === 'pre') {
|
||||
log.verbose('pre', 'Running pre-script.')
|
||||
log.verbose('pre', 'Veriying conditions.')
|
||||
|
||||
plugins.verifyConditions(config, function (err) {
|
||||
if (err) {
|
||||
log[options.debug ? 'warn' : 'error']('pre', err.message)
|
||||
if (!options.debug) process.exit(1)
|
||||
}
|
||||
|
||||
var nerfDart = require('nerf-dart')(npm.registry)
|
||||
var wroteNpmRc = false
|
||||
|
||||
if (env.NPM_OLD_TOKEN && env.NPM_EMAIL) {
|
||||
// Using the old auth token format is not considered part of the public API
|
||||
// This might go away anytime (i.e. once we have a better testing strategy)
|
||||
conf.set('_auth', '${NPM_OLD_TOKEN}', 'project') // eslint-disable-line no-template-curly-in-string
|
||||
conf.set('email', '${NPM_EMAIL}', 'project') // eslint-disable-line no-template-curly-in-string
|
||||
wroteNpmRc = true
|
||||
} else if (env.NPM_TOKEN) {
|
||||
conf.set(nerfDart + ':_authToken', '${NPM_TOKEN}', 'project') // eslint-disable-line no-template-curly-in-string
|
||||
wroteNpmRc = true
|
||||
}
|
||||
|
||||
conf.save('project', function (err) {
|
||||
if (err) return log.error('pre', 'Failed to save npm config.', err)
|
||||
|
||||
if (wroteNpmRc) log.verbose('pre', 'Wrote authToken to .npmrc.')
|
||||
|
||||
require('../src/pre')(config, function (err, release) {
|
||||
if (err) {
|
||||
log.error('pre', 'Failed to determine new version.')
|
||||
|
||||
var args = ['pre', (err.code ? err.code + ' ' : '') + err.message]
|
||||
if (err.stack) args.push(err.stack)
|
||||
log.error.apply(log, args)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var message = 'Determined version ' + release.version + ' as "' + npm.tag + '".'
|
||||
|
||||
log.verbose('pre', message)
|
||||
|
||||
if (options.debug) {
|
||||
log.error('pre', message + ' Not publishing in debug mode.', release)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
try {
|
||||
var shrinkwrap = JSON.parse(fs.readFileSync('./npm-shrinkwrap.json'))
|
||||
shrinkwrap.version = release.version
|
||||
fs.writeFileSync('./npm-shrinkwrap.json', JSON.stringify(shrinkwrap, null, 2))
|
||||
log.verbose('pre', 'Wrote version ' + release.version + 'to npm-shrinkwrap.json.')
|
||||
} catch (e) {
|
||||
log.silly('pre', 'Couldn\'t find npm-shrinkwrap.json.')
|
||||
}
|
||||
|
||||
fs.writeFileSync('./package.json', JSON.stringify(_.assign(originalPkg, {
|
||||
version: release.version
|
||||
}), null, 2))
|
||||
|
||||
log.verbose('pre', 'Wrote version ' + release.version + ' to package.json.')
|
||||
})
|
||||
})
|
||||
})
|
||||
} else if (options.argv.remain[0] === 'post') {
|
||||
log.verbose('post', 'Running post-script.')
|
||||
|
||||
require('../src/post')(config, function (err, published, release) {
|
||||
if (err) {
|
||||
log.error('post', 'Failed to publish release notes.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
log.verbose('post', (published ? 'Published' : 'Generated') + ' release notes.', release)
|
||||
})
|
||||
} else {
|
||||
log.error('post', 'Command "' + options.argv.remain[0] + '" not recognized. Use either "pre" or "post"')
|
||||
}
|
||||
})
|
||||
@@ -1,26 +0,0 @@
|
||||
const { parseRawCommit } = require('conventional-changelog/lib/git')
|
||||
|
||||
module.exports = function (commits) {
|
||||
let type = null
|
||||
|
||||
commits
|
||||
|
||||
.map((commit) => parseRawCommit(`${commit.hash}\n${commit.message}`))
|
||||
|
||||
.filter((commit) => !!commit)
|
||||
|
||||
.every((commit) => {
|
||||
if (commit.breaks.length) {
|
||||
type = 'major'
|
||||
return false
|
||||
}
|
||||
|
||||
if (commit.type === 'feat') type = 'minor'
|
||||
|
||||
if (!type && commit.type === 'fix') type = 'patch'
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
return type
|
||||
}
|
||||
+72
-16
@@ -1,23 +1,79 @@
|
||||
const { exec } = require('child_process')
|
||||
var childProcess = require('child_process')
|
||||
|
||||
const { efh } = require('./error')
|
||||
var log = require('npmlog')
|
||||
|
||||
module.exports = function (from, cb) {
|
||||
const range = (from ? from + '..' : '') + 'HEAD'
|
||||
exec(
|
||||
`git log -E --format=%H==SPLIT==%B==END== ${range}`,
|
||||
efh(cb)((stdout) => {
|
||||
cb(null, String(stdout).split('==END==\n')
|
||||
var SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
.filter((raw) => !!raw.trim())
|
||||
module.exports = function (config, cb) {
|
||||
var lastRelease = config.lastRelease
|
||||
var options = config.options
|
||||
var branch = options.branch
|
||||
var from = lastRelease.gitHead
|
||||
var range = (from ? from + '..' : '') + 'HEAD'
|
||||
|
||||
.map((raw) => {
|
||||
const data = raw.split('==SPLIT==')
|
||||
return {
|
||||
hash: data[0],
|
||||
message: data[1]
|
||||
if (!from) return extract()
|
||||
|
||||
childProcess.exec('git branch --no-color --contains ' + from, function (err, stdout) {
|
||||
var inHistory = false
|
||||
var branches
|
||||
|
||||
if (!err && stdout) {
|
||||
branches = stdout.split('\n')
|
||||
.map(function (result) {
|
||||
if (branch === result.replace('*', '').trim()) {
|
||||
inHistory = true
|
||||
return null
|
||||
}
|
||||
}))
|
||||
return result.trim()
|
||||
})
|
||||
.filter(function (branch) {
|
||||
return !!branch
|
||||
})
|
||||
}
|
||||
|
||||
if (!inHistory) {
|
||||
log.error('commits',
|
||||
'The commit the last release of this package was derived from is not in the direct history of the "' + branch + '" branch.\n' +
|
||||
'This means semantic-release can not extract the commits between now and then.\n' +
|
||||
'This is usually caused by force pushing, releasing from an unrelated branch, or using an already existing package name.\n' +
|
||||
'You can recover from this error by publishing manually or restoring the commit "' + from + '".' + (branches && branches.length
|
||||
? '\nHere is a list of branches that still contain the commit in question: \n * ' + branches.join('\n * ')
|
||||
: ''
|
||||
))
|
||||
return cb(new SemanticReleaseError('Commit not in history', 'ENOTINHISTORY'))
|
||||
}
|
||||
|
||||
extract()
|
||||
})
|
||||
|
||||
function extract () {
|
||||
var child = childProcess.spawn('git', ['log', '-E', '--format=%H==SPLIT==%B==END==', range])
|
||||
var stdout = ''
|
||||
var err = ''
|
||||
|
||||
child.stdout.on('data', function (data) {
|
||||
stdout += data
|
||||
})
|
||||
)
|
||||
|
||||
child.stderr.on('data', function (data) {
|
||||
err += data
|
||||
})
|
||||
|
||||
child.on('close', function (code) {
|
||||
if (err || code) return cb(err)
|
||||
|
||||
cb(null, String(stdout).split('==END==\n')
|
||||
.filter(function (raw) {
|
||||
return !!raw.trim()
|
||||
})
|
||||
.map(function (raw) {
|
||||
var data = raw.split('==SPLIT==')
|
||||
return {
|
||||
hash: data[0],
|
||||
message: data[1]
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
exports.efh = require('error-first-handler')
|
||||
exports.standard = exports.efh((err) => {
|
||||
console.log('Something went wrong:')
|
||||
if (typeof err === 'string') console.log(err)
|
||||
else if (err instanceof Error) console.log(err.message, err.stack)
|
||||
else if (err.message) console.log(err.message)
|
||||
else console.log(err)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
module.exports = function (pkg, conf) {
|
||||
if (pkg.publishConfig && pkg.publishConfig.registry) return pkg.publishConfig.registry
|
||||
|
||||
if (pkg.name[0] !== '@') return conf.get('registry') || 'https://registry.npmjs.org/'
|
||||
|
||||
var scope = pkg.name.split('/')[0]
|
||||
var scopedRegistry = conf.get(scope + '/registry')
|
||||
|
||||
if (scopedRegistry) return scopedRegistry
|
||||
|
||||
return conf.get('registry') || 'https://registry.npmjs.org/'
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
const async = require('async')
|
||||
const npmconf = require('npmconf')
|
||||
const request = require('request')
|
||||
|
||||
module.exports = function (pkgName, cb) {
|
||||
const registry = process.env.npm_config_registry
|
||||
|
||||
async.waterfall([
|
||||
npmconf.load,
|
||||
(conf, callback) => {
|
||||
const cred = conf.getCredentialsByURI(registry)
|
||||
const reqopts = {
|
||||
url: registry + pkgName.replace(/\//g, '%2F'),
|
||||
headers: {}
|
||||
}
|
||||
|
||||
if (cred.token) {
|
||||
reqopts.headers.Authorization = `Bearer ${cred.token}`
|
||||
} else if (cred.auth) {
|
||||
reqopts.headers.Authorization = `Basic ${cred.auth}`
|
||||
}
|
||||
|
||||
callback(null, reqopts)
|
||||
},
|
||||
request,
|
||||
(response, body, callback) => {
|
||||
let res = {
|
||||
version: null,
|
||||
gitHead: null,
|
||||
pkg: null
|
||||
}
|
||||
|
||||
if (response.statusCode === 404 || !body) return callback(null, res)
|
||||
|
||||
const pkg = JSON.parse(body)
|
||||
|
||||
if (pkg.error) return callback(pkg.error)
|
||||
|
||||
res.version = pkg['dist-tags'].latest
|
||||
res.gitHead = pkg.versions[res.version].gitHead
|
||||
res.pkg = pkg
|
||||
|
||||
callback(null, res)
|
||||
}
|
||||
], cb)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/* istanbul ignore next */
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
var relative = require('require-relative')
|
||||
var series = require('run-series')
|
||||
|
||||
var exports = module.exports = function (options) {
|
||||
var plugins = {
|
||||
analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'),
|
||||
generateNotes: exports.normalize(options.generateNotes, '@semantic-release/release-notes-generator'),
|
||||
getLastRelease: exports.normalize(options.getLastRelease, '@semantic-release/last-release-npm')
|
||||
}
|
||||
|
||||
;['verifyConditions', 'verifyRelease'].forEach(function (plugin) {
|
||||
if (!Array.isArray(options[plugin])) {
|
||||
plugins[plugin] = exports.normalize(
|
||||
options[plugin],
|
||||
plugin === 'verifyConditions'
|
||||
? '@semantic-release/condition-travis'
|
||||
: './plugin-noop'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
plugins[plugin] = function (pluginOptions, cb) {
|
||||
var tasks = options[plugin].map(function (step) {
|
||||
return exports.normalize(step, './plugin-noop').bind(null, pluginOptions)
|
||||
})
|
||||
|
||||
series(tasks, cb)
|
||||
}
|
||||
})
|
||||
|
||||
return plugins
|
||||
}
|
||||
|
||||
exports.normalize = function (pluginConfig, fallback) {
|
||||
if (typeof pluginConfig === 'string') return relative(pluginConfig).bind(null, {})
|
||||
|
||||
if (pluginConfig && (typeof pluginConfig.path === 'string')) {
|
||||
return relative(pluginConfig.path).bind(null, pluginConfig)
|
||||
}
|
||||
|
||||
return require(fallback).bind(null, pluginConfig)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
const changelog = require('conventional-changelog')
|
||||
const parseUrl = require('github-url-from-git')
|
||||
|
||||
module.exports = function (cb) {
|
||||
const pkg = JSON.parse(readFileSync('./package.json'))
|
||||
const repository = pkg.repository ? parseUrl(pkg.repository.url) : null
|
||||
|
||||
changelog({
|
||||
version: pkg.version,
|
||||
repository: repository,
|
||||
file: false
|
||||
}, cb)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
var SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
module.exports = function (config, cb) {
|
||||
var plugins = config.plugins
|
||||
var lastRelease = config.lastRelease
|
||||
|
||||
plugins.analyzeCommits(config, function (err, type) {
|
||||
if (err) return cb(err)
|
||||
|
||||
if (!type) {
|
||||
return cb(new SemanticReleaseError(
|
||||
'There are no relevant changes, so no new version is released.',
|
||||
'ENOCHANGE'
|
||||
))
|
||||
}
|
||||
|
||||
if (!lastRelease.version) return cb(null, 'initial')
|
||||
|
||||
cb(null, type)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
var SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
module.exports = function (config) {
|
||||
var pkg = config.pkg
|
||||
var options = config.options
|
||||
var env = config.env
|
||||
var errors = []
|
||||
|
||||
if (!pkg.name) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No "name" found in package.json.',
|
||||
'ENOPKGNAME'
|
||||
))
|
||||
}
|
||||
|
||||
if (!pkg.repository || !pkg.repository.url) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No "repository" found in package.json.',
|
||||
'ENOPKGREPO'
|
||||
))
|
||||
}
|
||||
|
||||
if (options.debug) return errors
|
||||
|
||||
if (!options.githubToken) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No github token specified.',
|
||||
'ENOGHTOKEN'
|
||||
))
|
||||
}
|
||||
|
||||
if (!(env.NPM_TOKEN || (env.NPM_OLD_TOKEN && env.NPM_EMAIL))) {
|
||||
errors.push(new SemanticReleaseError(
|
||||
'No npm token specified.',
|
||||
'ENONPMTOKEN'
|
||||
))
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
const abbrev = require('abbrev')
|
||||
const efh = require('./lib/error').standard
|
||||
|
||||
exports.pre = function (argv, npmArgv, plugins) {
|
||||
// see src/restart.js
|
||||
if (npmArgv['semantic-release-rerun']) {
|
||||
if (!/semantically-released/.test(process.env.npm_package_version)) process.exit(0)
|
||||
|
||||
console.log(
|
||||
`There is something wrong with your setup, as a placeholder version is about to be released.
|
||||
Please verify that your setup is correct.
|
||||
If you think this is a problem with semantic-release please open an issue.`
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
// the `prepublish` hook is also executed when the package is installed
|
||||
// in this case we abort the command and do nothing.
|
||||
if (
|
||||
isAbbrev(npmArgv, 'install') ||
|
||||
isAbbrev(npmArgv, 'link') ||
|
||||
isAbbrev(npmArgv, 'pack')
|
||||
) process.exit(0)
|
||||
|
||||
if (argv.debug) console.log('This is a dry run')
|
||||
|
||||
console.log('Determining new version')
|
||||
|
||||
const publish = isAbbrev(npmArgv, 'publish')
|
||||
|
||||
// require a correct setup during publish
|
||||
if (publish && !argv.debug && !require('./verify')(argv)) process.exit(1)
|
||||
|
||||
require('./pre')(argv, plugins, efh((result) => {
|
||||
if (!result) {
|
||||
console.log('Nothing changed. Not publishing.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('Publishing v' + result)
|
||||
if (!publish) process.exit(0)
|
||||
|
||||
if (argv.debug) process.exit(1)
|
||||
|
||||
require('./restart')(efh(() => process.exit(1)))
|
||||
}))
|
||||
}
|
||||
|
||||
exports.post = function (argv, npmArgv, plugins) {
|
||||
require('./post')(argv, plugins, efh(function () {
|
||||
// see src/restart.js
|
||||
if (npmArgv['semantic-release-rerun']) {
|
||||
console.log('Everything is alright :) npm will now print an error message that you can safely ignore.')
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
exports.setup = function () {
|
||||
require('./setup')()
|
||||
console.log('"package.json" is set up properly. Now configure your CI server.')
|
||||
console.log('https://github.com/boennemann/semantic-release#ci-server')
|
||||
}
|
||||
|
||||
function isAbbrev (argv, command) {
|
||||
return argv._.some(Object.prototype.hasOwnProperty.bind(abbrev(command)))
|
||||
}
|
||||
+57
-33
@@ -1,47 +1,71 @@
|
||||
const { readFileSync } = require('fs')
|
||||
const url = require('url')
|
||||
var url = require('url')
|
||||
|
||||
const gitHead = require('git-head')
|
||||
const GitHubApi = require('github')
|
||||
const parseSlug = require('parse-github-repo-url')
|
||||
var gitHead = require('git-head')
|
||||
var GitHubApi = require('github')
|
||||
var parseSlug = require('parse-github-repo-url')
|
||||
|
||||
const efh = require('./lib/error').efh
|
||||
module.exports = function (config, cb) {
|
||||
var pkg = config.pkg
|
||||
var options = config.options
|
||||
var plugins = config.plugins
|
||||
var ghConfig = options.githubUrl ? url.parse(options.githubUrl) : {}
|
||||
|
||||
module.exports = function (options, plugins, cb) {
|
||||
const pkg = JSON.parse(readFileSync('./package.json'))
|
||||
const repository = pkg.repository ? pkg.repository.url : null
|
||||
|
||||
if (!repository) return cb(new Error('Package must have a repository'))
|
||||
|
||||
const notesGenerator = require(plugins.notes || './lib/release-notes')
|
||||
|
||||
const config = options['github-url'] ? url.parse(options['github-url']) : {}
|
||||
|
||||
const github = new GitHubApi({
|
||||
version: '3.0.0',
|
||||
port: config.port,
|
||||
protocol: (config.protocol || '').split(':')[0] || null,
|
||||
host: config.hostname
|
||||
var github = new GitHubApi({
|
||||
port: ghConfig.port,
|
||||
protocol: (ghConfig.protocol || '').split(':')[0] || null,
|
||||
host: ghConfig.hostname,
|
||||
pathPrefix: options.githubApiPathPrefix || null
|
||||
})
|
||||
|
||||
notesGenerator(efh(cb)((log) => {
|
||||
gitHead(efh(cb)((hash) => {
|
||||
const ghRepo = parseSlug(repository)
|
||||
const release = {
|
||||
plugins.generateNotes(config, function (err, log) {
|
||||
if (err) return cb(err)
|
||||
|
||||
gitHead(function (err, hash) {
|
||||
if (err) return cb(err)
|
||||
|
||||
var ghRepo = parseSlug(pkg.repository.url)
|
||||
var tag = {
|
||||
owner: ghRepo[0],
|
||||
repo: ghRepo[1],
|
||||
tag_name: `v${pkg.version}`,
|
||||
target_commitish: hash,
|
||||
draft: options.debug,
|
||||
ref: 'refs/tags/v' + pkg.version,
|
||||
sha: hash
|
||||
}
|
||||
var release = {
|
||||
owner: ghRepo[0],
|
||||
repo: ghRepo[1],
|
||||
tag_name: 'v' + pkg.version,
|
||||
name: 'v' + pkg.version,
|
||||
target_commitish: options.branch,
|
||||
draft: !!options.debug,
|
||||
body: log
|
||||
}
|
||||
|
||||
if (options.debug && !options.githubToken) {
|
||||
return cb(null, false, release)
|
||||
}
|
||||
|
||||
github.authenticate({
|
||||
type: 'oauth',
|
||||
token: options.token
|
||||
type: 'token',
|
||||
token: options.githubToken
|
||||
})
|
||||
|
||||
github.releases.createRelease(release, efh(cb)(() => cb(null, true)))
|
||||
}))
|
||||
}))
|
||||
if (options.debug) {
|
||||
return github.repos.createRelease(release, function (err) {
|
||||
if (err) return cb(err)
|
||||
|
||||
cb(null, true, release)
|
||||
})
|
||||
}
|
||||
|
||||
github.gitdata.createReference(tag, function (err) {
|
||||
if (err) return cb(err)
|
||||
|
||||
github.repos.createRelease(release, function (err) {
|
||||
if (err) return cb(err)
|
||||
|
||||
cb(null, true, release)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
+39
-56
@@ -1,62 +1,45 @@
|
||||
const fs = require('fs')
|
||||
var _ = require('lodash')
|
||||
var auto = require('run-auto')
|
||||
var semver = require('semver')
|
||||
|
||||
const semver = require('semver')
|
||||
var getCommits = require('./lib/commits')
|
||||
var getType = require('./lib/type')
|
||||
|
||||
const getCommits = require('./lib/commits')
|
||||
const npmInfo = require('./lib/npm-info')
|
||||
const { efh } = require('./lib/error')
|
||||
module.exports = function (config, cb) {
|
||||
var plugins = config.plugins
|
||||
|
||||
module.exports = function (options, plugins, cb) {
|
||||
const path = './package.json'
|
||||
let pkg = JSON.parse(fs.readFileSync(path))
|
||||
auto({
|
||||
lastRelease: plugins.getLastRelease.bind(null, config),
|
||||
commits: ['lastRelease', function (results, cb) {
|
||||
getCommits(_.assign({
|
||||
lastRelease: results.lastRelease
|
||||
}, config),
|
||||
cb)
|
||||
}],
|
||||
type: ['commits', 'lastRelease', function (results, cb) {
|
||||
getType(_.assign({
|
||||
commits: results.commits,
|
||||
lastRelease: results.lastRelease
|
||||
}, config),
|
||||
cb)
|
||||
}]
|
||||
}, function (err, results) {
|
||||
if (err) return cb(err)
|
||||
|
||||
if (!pkg.name) return cb(new Error('Package must have a name'))
|
||||
var nextRelease = {
|
||||
type: results.type,
|
||||
version: results.type === 'initial'
|
||||
? '1.0.0'
|
||||
: semver.inc(results.lastRelease.version, results.type)
|
||||
}
|
||||
|
||||
npmInfo(pkg.name, efh(cb)((res) => {
|
||||
getCommits(res.gitHead, efh(cb)((commits) => {
|
||||
const analyzer = require(plugins.analyzer || './lib/analyzer')
|
||||
let type = analyzer(commits)
|
||||
|
||||
if (!type) return cb(null, null)
|
||||
|
||||
if (res.version) {
|
||||
pkg.version = semver.inc(res.version, type)
|
||||
} else {
|
||||
type = 'major'
|
||||
pkg.version = '1.0.0'
|
||||
}
|
||||
|
||||
function writePkg () {
|
||||
if (!options.debug) fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`)
|
||||
cb(null, pkg.version)
|
||||
}
|
||||
|
||||
if (!plugins.verification) return writePkg()
|
||||
|
||||
let opts = {}
|
||||
|
||||
if (typeof plugins.verification === 'string') {
|
||||
opts.path = plugins.verification
|
||||
}
|
||||
if (typeof plugins.verification === 'object') {
|
||||
opts = plugins.verification
|
||||
opts.path = opts.path || opts.name
|
||||
}
|
||||
|
||||
opts.type = type
|
||||
opts.commits = commits
|
||||
opts.version = res.version
|
||||
opts.nextVersion = pkg.version
|
||||
|
||||
const verification = require(opts.path)
|
||||
|
||||
console.log('Running verification hook...')
|
||||
|
||||
verification(opts, (error, ok) => {
|
||||
if (!error && ok) return writePkg()
|
||||
console.log('Verification failed' + (error ? ': ' + error : ''))
|
||||
process.exit(1)
|
||||
})
|
||||
}))
|
||||
}))
|
||||
plugins.verifyRelease(_.assign({
|
||||
commits: results.commits,
|
||||
lastRelease: results.lastRelease,
|
||||
nextRelease: nextRelease
|
||||
}, config), function (err) {
|
||||
if (err) return cb(err)
|
||||
cb(null, nextRelease)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
const { spawn } = require('child_process')
|
||||
|
||||
let exports = module.exports = function (cb) {
|
||||
// npm loads package.json data before running the `prepublish` hook
|
||||
// changing the version on `prepublish` has no effect
|
||||
// see https://github.com/npm/npm/issues/7118
|
||||
// to circumvent this behavior we are calling `npm publish` inside `prepublish`
|
||||
// the package.json is then loaded again and the correct version will be published
|
||||
|
||||
const child = spawn('npm', ['publish', '--semantic-release-rerun'])
|
||||
const handler = exports.handleCloseAndExit.bind(null, cb)
|
||||
|
||||
child.stdout.pipe(process.stdout)
|
||||
child.stderr.pipe(process.stderr)
|
||||
|
||||
child.on('close', handler)
|
||||
child.on('exit', handler)
|
||||
child.on('error', cb)
|
||||
}
|
||||
|
||||
exports.handleCloseAndExit = function (cb, code, signal) {
|
||||
if (code === 0) return cb(null)
|
||||
cb({
|
||||
code,
|
||||
signal,
|
||||
message: 'npm publish failed'
|
||||
})
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
const {
|
||||
readFileSync,
|
||||
writeFileSync
|
||||
} = require('fs')
|
||||
|
||||
const ini = require('ini')
|
||||
const ghUrl = require('github-url-from-git')
|
||||
|
||||
module.exports = function () {
|
||||
let pkg = JSON.parse(String(readFileSync('./package.json')))
|
||||
|
||||
// ensure a yet unpublished version
|
||||
pkg.version = '0.0.0-semantically-released'
|
||||
|
||||
// set up scripts
|
||||
const pre = 'semantic-release pre'
|
||||
const post = 'semantic-release post'
|
||||
|
||||
if (!pkg.scripts) pkg.scripts = {}
|
||||
|
||||
if (!pkg.scripts.prepublish) pkg.scripts.prepublish = pre
|
||||
else if (!(new RegExp(pre).test(pkg.scripts.prepublish))) pkg.scripts.prepublish += ` && ${pre}`
|
||||
|
||||
if (!pkg.scripts.postpublish) pkg.scripts.postpublish = post
|
||||
else if (!(new RegExp(post).test(pkg.scripts.postpublish))) pkg.scripts.postpublish += ` && ${post}`
|
||||
|
||||
// set up repository
|
||||
if (!pkg.repository || !pkg.repository.url) {
|
||||
const config = ini.decode(String(readFileSync('./.git/config')))
|
||||
const repo = config['remote "origin"'].url
|
||||
|
||||
if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) }
|
||||
}
|
||||
|
||||
// set up devDependency
|
||||
if (!pkg.devDependencies) pkg.devDependencies = {}
|
||||
|
||||
if (!pkg.devDependencies['semantic-release']) {
|
||||
pkg.devDependencies['semantic-release'] = `^${require('../package.json').version}`
|
||||
}
|
||||
|
||||
writeFileSync('./package.json', `${JSON.stringify(pkg, null, 2)}\n`)
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
let exports = module.exports = function (input) {
|
||||
const options = exports.verifyOptions(input)
|
||||
const pkg = exports.verifyPackage()
|
||||
const travis = exports.verifyTravis()
|
||||
return options && pkg && travis
|
||||
}
|
||||
|
||||
exports.verifyTravis = function () {
|
||||
let travis
|
||||
try {
|
||||
travis = String(readFileSync('.travis.yml'))
|
||||
} catch (e) {
|
||||
return true
|
||||
}
|
||||
|
||||
let passed = true
|
||||
|
||||
if (!/\sdeploy:/m.test(travis)) {
|
||||
console.error('You should configure deployments inside the ".travis.yml".')
|
||||
passed = false
|
||||
}
|
||||
|
||||
if (!/skip_cleanup:/m.test(travis)) {
|
||||
console.error('You must set "skip_cleanup" to "true" inside the ".travis.yml".')
|
||||
passed = false
|
||||
}
|
||||
|
||||
return passed
|
||||
}
|
||||
|
||||
exports.verifyPackage = function () {
|
||||
let passed = true
|
||||
|
||||
let pkg
|
||||
try {
|
||||
pkg = String(readFileSync('./package.json'))
|
||||
} catch (e) {
|
||||
console.error('You must have a "package.json" present.')
|
||||
passed = false
|
||||
pkg = '{}'
|
||||
}
|
||||
|
||||
try {
|
||||
pkg = JSON.parse(pkg)
|
||||
} catch (e) {
|
||||
console.error('You must have a "package.json" that is valid JSON.')
|
||||
return false
|
||||
}
|
||||
|
||||
if (!pkg.repository || !pkg.repository.url) {
|
||||
console.error('You must define your GitHub "repository" inside the "package.json".')
|
||||
passed = false
|
||||
}
|
||||
|
||||
if (!pkg.scripts || !pkg.scripts.prepublish || !pkg.scripts.postpublish) {
|
||||
console.error('You must define your "scripts" inside the "package.json".')
|
||||
passed = false
|
||||
}
|
||||
|
||||
return passed
|
||||
}
|
||||
|
||||
exports.verifyOptions = function (options) {
|
||||
if (!options) return true
|
||||
if (options.token) return true
|
||||
|
||||
console.error('You must define a GitHub token.')
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
var nixt = require('nixt')
|
||||
|
||||
module.exports = function (cwd, uri) {
|
||||
return nixt()
|
||||
.cwd(cwd)
|
||||
.env('NPM_OLD_TOKEN', 'aW50ZWdyYXRpb246c3VjaHNlY3VyZQ==')
|
||||
.env('NPM_EMAIL', 'integration@test.com')
|
||||
.env('GH_TOKEN', 'ghtoken')
|
||||
.env('CI', 'true')
|
||||
.env('npm_config_registry', uri)
|
||||
.clone()
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
var exec = require('child_process').exec
|
||||
var join = require('path').join
|
||||
var writeFileSync = require('fs').writeFileSync
|
||||
|
||||
var mkdirp = require('mkdirp')
|
||||
|
||||
module.exports = function (name, registry, cb) {
|
||||
var cwd = join(__dirname, '../tmp', name)
|
||||
|
||||
mkdirp.sync(cwd)
|
||||
|
||||
writeFileSync(join(cwd, 'package.json'), JSON.stringify({
|
||||
name: name,
|
||||
repository: {
|
||||
url: 'git+https://github.com/semantic-release/test'
|
||||
},
|
||||
release: {
|
||||
verifyConditions: '../../../src/lib/plugin-noop'
|
||||
}
|
||||
}, null, 2))
|
||||
|
||||
exec(
|
||||
'git init && ' +
|
||||
'git config user.email "integration@test" && ' +
|
||||
'git config user.name "Integration Test" && ' +
|
||||
'git add . && ' +
|
||||
'git commit -m "chore: root"'
|
||||
, {cwd: cwd}, function (err, stdout, stderr) {
|
||||
if (err) {
|
||||
console.log(stdout, stderr)
|
||||
return cb(err)
|
||||
}
|
||||
|
||||
cb(null, cwd)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
var mockSpawn = require('mock-spawn')()
|
||||
mockSpawn.setStrategy(function (command, args, opts) {
|
||||
return function (cb) {
|
||||
this.stdout.write(
|
||||
/\.\.HEAD/.test(args.join(' '))
|
||||
? rawCommits[0]
|
||||
: rawCommits.join()
|
||||
)
|
||||
cb(0)
|
||||
}
|
||||
})
|
||||
|
||||
const rawCommits = [
|
||||
'hash-one==SPLIT==commit-one==END==\n',
|
||||
'hash-two==SPLIT==commit-two==END==\n'
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
exec: function (command, options, cb) {
|
||||
if (typeof cb === 'undefined' && typeof options === 'function') {
|
||||
cb = options
|
||||
}
|
||||
if (/contains/.test(command)) {
|
||||
if (/notinhistory/.test(command)) return cb(new Error())
|
||||
return cb(null, 'whatever\nmaster\n')
|
||||
}
|
||||
},
|
||||
spawn: mockSpawn,
|
||||
'@noCallThru': true
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
module.exports = function (cb) {
|
||||
cb(null, 'custom log')
|
||||
cb(null, 'bar')
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
module.exports = function () {
|
||||
return {
|
||||
authenticate: function () {
|
||||
return true
|
||||
},
|
||||
gitdata: {
|
||||
createReference: function (release, cb) {
|
||||
cb(null)
|
||||
}
|
||||
},
|
||||
repos: {
|
||||
createRelease: function (release, cb) {
|
||||
cb(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(new Error('a'))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(new Error('b'))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null, 'a')
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null, 'b')
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
const nock = require('nock')
|
||||
|
||||
const availableModule = {
|
||||
'dist-tags': {
|
||||
latest: '1.33.7',
|
||||
foo: '0.8.15'
|
||||
},
|
||||
versions: {
|
||||
'0.8.15': {
|
||||
gitHead: 'bar'
|
||||
},
|
||||
'1.33.7': {
|
||||
gitHead: 'HEAD'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = nock('http://registry.npmjs.org')
|
||||
.get('/available')
|
||||
.reply(200, availableModule)
|
||||
.get('/tagged')
|
||||
.reply(200, availableModule)
|
||||
.get('/untagged')
|
||||
.reply(200, availableModule)
|
||||
.get('/@scoped%2Favailable')
|
||||
.reply(200, availableModule)
|
||||
.get('/unavailable')
|
||||
.reply(404, {})
|
||||
@@ -0,0 +1,11 @@
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var opts = {
|
||||
cwd: __dirname
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
start: exec.bind(null, './start.sh', opts),
|
||||
stop: exec.bind(null, './stop.sh', opts),
|
||||
uri: 'http://localhost:' + (process.env.TRAVIS === 'true' ? 5984 : 15986) + '/registry/_design/app/_rewrite/'
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
[couchdb]
|
||||
database_dir = data
|
||||
view_index_dir = data
|
||||
delayed_commits = false
|
||||
|
||||
[couch_httpd_auth]
|
||||
public_fields = appdotnet, avatar, avatarMedium, avatarLarge, date, email, fields, freenode, fullname, github, homepage, name, roles, twitter, type, _id, _rev
|
||||
users_db_public = true
|
||||
|
||||
[httpd]
|
||||
port = 15986
|
||||
bind_address = 127.0.0.1
|
||||
secure_rewrites = false
|
||||
|
||||
[log]
|
||||
file = couch/couch.log
|
||||
|
||||
[admins]
|
||||
admin = -pbkdf2-89582b49cd2e8443e29a841f5a76d367956a8e58,1afa2f1531a17ac97f2ac9e334293753,10
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
# exit if an error occurs
|
||||
set -e
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
mkdir -p couch
|
||||
|
||||
if [[ $TRAVIS = true ]]
|
||||
then
|
||||
COUCH=http://admin:password@127.0.0.1:5984
|
||||
|
||||
curl -X PUT http://127.0.0.1:5984/_config/admins/admin -d '"password"'
|
||||
|
||||
curl -X PUT $COUCH/_config/couchdb/delayed_commits -d '"false"'
|
||||
curl -X PUT $COUCH/_config/couch_httpd_auth/users_db_public -d '"true"'
|
||||
curl -X PUT $COUCH/_config/couch_httpd_auth/public_fields -d '"appdotnet, avatar, avatarMedium, avatarLarge, date, email, fields, freenode, fullname, github, homepage, name, roles, twitter, type, _id, _rev"'
|
||||
curl -X PUT $COUCH/_config/httpd/secure_rewrites -d '"false"'
|
||||
|
||||
else
|
||||
COUCH=http://admin:password@127.0.0.1:15986
|
||||
couchdb -b -a local.ini -p couch/pid -o couch/stdout.log -e couch/stderr.log
|
||||
# wait for couch to start
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
# create "registry" database
|
||||
curl -X PUT $COUCH/registry
|
||||
|
||||
# create sample npm user
|
||||
curl -X PUT $COUCH/_users/org.couchdb.user:integration -H Content-Type:application/json --data-binary '{"_id": "org.couchdb.user:integration", "name": "integration", "roles": [], "type": "user", "password": "suchsecure", "email": "integration@test.com"}'
|
||||
|
||||
# npm-registry-couchpp needs this variable set to run
|
||||
export DEPLOY_VERSION=nope
|
||||
|
||||
# setup npm-registry-couchapp
|
||||
npm explore npm-registry-couchapp -- npm start --npm-registry-couchapp:couch=$COUCH/registry
|
||||
npm explore npm-registry-couchapp -- npm run load --npm-registry-couchapp:couch=$COUCH/registry
|
||||
export NO_PROMPT=yes
|
||||
npm explore npm-registry-couchapp -- npm run copy --npm-registry-couchapp:couch=$COUCH/registry
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# close couchdb background process
|
||||
couchdb -d
|
||||
|
||||
# delete data and logs
|
||||
cd $(dirname $0)
|
||||
|
||||
cat couch/{couch,stdout,stderr}.log
|
||||
|
||||
cat couch/pid | xargs kill
|
||||
rm -rf couch
|
||||
rm -rf data
|
||||
@@ -0,0 +1,96 @@
|
||||
var join = require('path').join
|
||||
|
||||
var tap = require('tap')
|
||||
var rimraf = require('rimraf')
|
||||
|
||||
var registry = require('../registry')
|
||||
var testModule = require('../lib/test-module')
|
||||
var baseScenario = require('../lib/base-scenario')
|
||||
|
||||
var tearDown = tap.tearDown
|
||||
var test = tap.test
|
||||
|
||||
test('change version', {bail: process.env.TRAVIS === 'true'}, function (t) {
|
||||
t.plan(7)
|
||||
|
||||
registry.start(function (err, stdout, stderr) {
|
||||
t.error(err, 'registry started')
|
||||
if (err) return t.end()
|
||||
|
||||
testModule('change-version', registry.uri, function (err, cwd) {
|
||||
t.error(err, 'test-module created')
|
||||
if (err) return t.end()
|
||||
|
||||
t.test('no version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.env('npm_config_loglevel', 'info')
|
||||
.run('node ../../../bin/semantic-release.js pre')
|
||||
.stderr(/ENOCHANGE/)
|
||||
.code(1)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('initial version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "feat: initial" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.stdout(/1\.0\.0/)
|
||||
.code(0)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('patch version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "fix: foo" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.stdout(/1\.0\.1/)
|
||||
.code(0)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('feature version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "feat: foo" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.code(0)
|
||||
.stdout(/1\.1\.0/)
|
||||
.end(tt.error)
|
||||
})
|
||||
|
||||
t.test('breaking version', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
baseScenario(cwd, registry.uri)
|
||||
.exec('git commit -m "feat: foo\n\n BREAKING CHANGE: bar" --allow-empty')
|
||||
.exec('node ../../../bin/semantic-release.js pre')
|
||||
.run('npm publish')
|
||||
.code(0)
|
||||
.stdout(/2\.0\.0/)
|
||||
.end(tt.error)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
tearDown(function () {
|
||||
if (process.env.TRAVIS === 'true') return
|
||||
|
||||
function cb (err, stdout, stderr) {
|
||||
if (err) console.log(err)
|
||||
if (stderr) console.log(stderr)
|
||||
}
|
||||
|
||||
rimraf(join(__dirname, '../tmp'), cb)
|
||||
registry.stop(cb)
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
var test = require('tap').test
|
||||
var proxyquire = require('proxyquire')
|
||||
|
||||
var commits = proxyquire('../../src/lib/commits', {
|
||||
'npmlog': {
|
||||
error: function () {}
|
||||
},
|
||||
'child_process': require('../mocks/child-process')
|
||||
})
|
||||
|
||||
test('commits since last release', function (t) {
|
||||
t.test('get all commits', function (tt) {
|
||||
commits({lastRelease: {}, options: {branch: 'master'}}, function (err, commits) {
|
||||
tt.error(err)
|
||||
tt.is(commits.length, 2, 'all commits')
|
||||
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
|
||||
tt.is(commits[1].message, 'commit-two', 'parsed message')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get commits since hash', function (tt) {
|
||||
commits({lastRelease: {gitHead: 'hash'}, options: {branch: 'master'}}, function (err, commits) {
|
||||
tt.error(err)
|
||||
tt.is(commits.length, 1, 'specified commits')
|
||||
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
|
||||
tt.is(commits[0].message, 'commit-one', 'parsed message')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get commits since hash', function (tt) {
|
||||
commits({lastRelease: {gitHead: 'notinhistory'}, options: {branch: 'notmaster'}}, function (err, commits) {
|
||||
tt.ok(err)
|
||||
tt.is(err.code, 'ENOTINHISTORY')
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
const test = require('tap').test
|
||||
|
||||
const getRegistry = require('../../src/lib/get-registry')
|
||||
|
||||
test('get correct registry', function (t) {
|
||||
t.is(getRegistry({
|
||||
name: 'publish-config',
|
||||
publishConfig: {
|
||||
registry: 'a'
|
||||
}},
|
||||
{}), 'a')
|
||||
|
||||
t.is(getRegistry({name: 'normal'}, {
|
||||
get: function () {
|
||||
return 'b'
|
||||
}
|
||||
}), 'b')
|
||||
|
||||
t.is(getRegistry({name: 'normal'}, {
|
||||
get: function () {
|
||||
return null
|
||||
}
|
||||
}), 'https://registry.npmjs.org/')
|
||||
|
||||
t.is(getRegistry({name: '@scoped/foo'}, {
|
||||
get: function (input) {
|
||||
return input === '@scoped/registry' ? 'c' : 'd'
|
||||
}
|
||||
}), 'c')
|
||||
|
||||
t.is(getRegistry({name: '@scoped/bar'}, {
|
||||
get: function () {
|
||||
return 'e'
|
||||
}
|
||||
}), 'e')
|
||||
|
||||
t.is(getRegistry({name: '@scoped/baz'}, {
|
||||
get: function () {
|
||||
return null
|
||||
}
|
||||
}), 'https://registry.npmjs.org/')
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,97 @@
|
||||
var test = require('tap').test
|
||||
|
||||
var plugins = require('../../src/lib/plugins')
|
||||
|
||||
test('export plugins', function (t) {
|
||||
t.plan(5)
|
||||
|
||||
var defaultPlugins = plugins({})
|
||||
|
||||
t.is(typeof defaultPlugins.analyzeCommits, 'function')
|
||||
t.is(typeof defaultPlugins.generateNotes, 'function')
|
||||
t.is(typeof defaultPlugins.verifyConditions, 'function')
|
||||
t.is(typeof defaultPlugins.verifyRelease, 'function')
|
||||
t.is(typeof defaultPlugins.getLastRelease, 'function')
|
||||
})
|
||||
|
||||
test('plugin pipelines', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
t.test('get all results', function (tt) {
|
||||
var pipelinePlugins = plugins({
|
||||
verifyRelease: [
|
||||
'./src/lib/plugin-noop',
|
||||
'./test/mocks/plugin-result-a',
|
||||
'./test/mocks/plugin-result-b'
|
||||
]
|
||||
})
|
||||
|
||||
pipelinePlugins.verifyRelease({}, function (err, results) {
|
||||
tt.error(err)
|
||||
tt.same(results, [undefined, 'a', 'b'])
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get first error', function (tt) {
|
||||
var pipelinePlugins = plugins({
|
||||
verifyConditions: [
|
||||
'./src/lib/plugin-noop',
|
||||
'./test/mocks/plugin-error-a',
|
||||
'./test/mocks/plugin-error-b'
|
||||
]
|
||||
})
|
||||
|
||||
pipelinePlugins.verifyConditions({}, function (err) {
|
||||
tt.is(err.message, 'a')
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get error and only results before', function (tt) {
|
||||
var pipelinePlugins = plugins({
|
||||
verifyRelease: [
|
||||
'./src/lib/plugin-noop',
|
||||
'./test/mocks/plugin-result-a',
|
||||
'./test/mocks/plugin-error-b',
|
||||
'./test/mocks/plugin-result-b'
|
||||
]
|
||||
})
|
||||
|
||||
pipelinePlugins.verifyRelease({}, function (err, results) {
|
||||
tt.is(err.message, 'b')
|
||||
tt.same(results, [undefined, 'a', undefined])
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('normalize and load plugin', function (t) {
|
||||
t.test('load from string', function (tt) {
|
||||
var plugin = plugins.normalize('./src/lib/plugin-noop')
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('load from object', function (tt) {
|
||||
var plugin = plugins.normalize({
|
||||
path: './src/lib/plugin-noop'
|
||||
})
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('load from fallback', function (tt) {
|
||||
var plugin = plugins.normalize(null, '../../src/lib/plugin-noop')
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,74 @@
|
||||
var defaults = require('lodash').defaults
|
||||
var test = require('tap').test
|
||||
var proxyquire = require('proxyquire')
|
||||
|
||||
var post = proxyquire('../../src/post', {
|
||||
'git-head': require('../mocks/git-head'),
|
||||
github: require('../mocks/github')
|
||||
})
|
||||
|
||||
var pkg = {
|
||||
version: '1.0.0',
|
||||
repository: {url: 'http://github.com/whats/up.git'}
|
||||
}
|
||||
|
||||
var plugins = {
|
||||
generateNotes: function (pkg, cb) {
|
||||
cb(null, 'the log')
|
||||
}
|
||||
}
|
||||
|
||||
var defaultRelease = {
|
||||
owner: 'whats',
|
||||
repo: 'up',
|
||||
name: 'v1.0.0',
|
||||
tag_name: 'v1.0.0',
|
||||
target_commitish: 'master',
|
||||
body: 'the log'
|
||||
}
|
||||
|
||||
test('full post run', function (t) {
|
||||
t.test('in debug mode w/o token', function (tt) {
|
||||
post({
|
||||
options: {debug: true, branch: 'master'},
|
||||
pkg: pkg,
|
||||
plugins: plugins
|
||||
}, function (err, published, release) {
|
||||
tt.error(err)
|
||||
tt.is(published, false)
|
||||
tt.match(release, defaults({draft: true}, defaultRelease))
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('in debug mode w/token', function (tt) {
|
||||
post({
|
||||
options: {debug: true, githubToken: 'yo', branch: 'master'},
|
||||
pkg: pkg,
|
||||
plugins: plugins
|
||||
}, function (err, published, release) {
|
||||
tt.error(err)
|
||||
tt.is(published, true)
|
||||
tt.match(release, defaults({draft: true}, defaultRelease))
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('production', function (tt) {
|
||||
post({
|
||||
options: {githubToken: 'yo', branch: 'master'},
|
||||
pkg: pkg,
|
||||
plugins: plugins
|
||||
}, function (err, published, release) {
|
||||
tt.error(err)
|
||||
tt.is(published, true)
|
||||
tt.match(release, defaultRelease)
|
||||
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
var test = require('tap').test
|
||||
var proxyquire = require('proxyquire')
|
||||
|
||||
require('../mocks/registry')
|
||||
var pre = proxyquire('../../src/pre', {
|
||||
'./lib/commits': proxyquire('../../src/lib/commits', {
|
||||
'child_process': require('../mocks/child-process')
|
||||
})
|
||||
})
|
||||
|
||||
var versions = {
|
||||
available: '1.0.0'
|
||||
}
|
||||
|
||||
var plugins = {
|
||||
verifyRelease: function (release, cb) {
|
||||
cb(null, release)
|
||||
},
|
||||
analyzeCommits: function (commits, cb) {
|
||||
cb(null, 'major')
|
||||
},
|
||||
getLastRelease: function (config, cb) {
|
||||
cb(null, {version: versions[config.pkg.name] || null, gitHead: 'HEAD'})
|
||||
}
|
||||
}
|
||||
|
||||
var npm = {
|
||||
registry: 'http://registry.npmjs.org/',
|
||||
tag: 'latest'
|
||||
}
|
||||
|
||||
test('full pre run', function (t) {
|
||||
t.test('increase version', function (tt) {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
options: {branch: 'master'},
|
||||
npm: npm,
|
||||
pkg: {name: 'available'},
|
||||
plugins: plugins
|
||||
}, function (err, release) {
|
||||
tt.error(err)
|
||||
tt.is(release.type, 'major')
|
||||
tt.is(release.version, '2.0.0')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('increase version', function (tt) {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
options: {branch: 'master'},
|
||||
npm: npm,
|
||||
pkg: {name: 'unavailable'},
|
||||
plugins: plugins
|
||||
}, function (err, release) {
|
||||
tt.error(err)
|
||||
tt.is(release.type, 'initial')
|
||||
tt.is(release.version, '1.0.0')
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,60 @@
|
||||
var test = require('tap').test
|
||||
|
||||
var type = require('../../src/lib/type')
|
||||
|
||||
test('get type from commits', function (t) {
|
||||
t.test('get type from plugin', function (tt) {
|
||||
tt.plan(2)
|
||||
|
||||
type({
|
||||
commits: [{
|
||||
hash: '0',
|
||||
message: 'a'
|
||||
}],
|
||||
lastRelease: {version: '1.0.0'},
|
||||
plugins: {
|
||||
analyzeCommits: function (config, cb) {
|
||||
cb(null, 'major')
|
||||
}
|
||||
}
|
||||
}, function (err, type) {
|
||||
tt.error(err)
|
||||
tt.is(type, 'major')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('error when no changes', function (tt) {
|
||||
tt.plan(1)
|
||||
|
||||
type({
|
||||
commits: [],
|
||||
lastRelease: {},
|
||||
plugins: {
|
||||
analyzeCommits: function (config, cb) {
|
||||
cb(null, null)
|
||||
}
|
||||
}
|
||||
}, function (err) {
|
||||
tt.is(err.code, 'ENOCHANGE')
|
||||
})
|
||||
})
|
||||
|
||||
t.test('initial version', function (tt) {
|
||||
tt.plan(2)
|
||||
|
||||
type({
|
||||
commits: [],
|
||||
lastRelease: {},
|
||||
plugins: {
|
||||
analyzeCommits: function (config, cb) {
|
||||
cb(null, 'major')
|
||||
}
|
||||
}
|
||||
}, function (err, type) {
|
||||
tt.error(err)
|
||||
tt.is(type, 'initial')
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,72 @@
|
||||
var test = require('tap').test
|
||||
|
||||
var verify = require('../../src/lib/verify')
|
||||
|
||||
test('verify pkg, options and env', function (t) {
|
||||
t.test('dry run verification', function (tt) {
|
||||
var noErrors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'http://github.com/whats/up.git'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tt.is(noErrors.length, 0)
|
||||
|
||||
var errors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {}
|
||||
})
|
||||
|
||||
tt.is(errors.length, 2)
|
||||
tt.is(errors[0].code, 'ENOPKGNAME')
|
||||
tt.is(errors[1].code, 'ENOPKGREPO')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('dry run verification for gitlab repo', function (tt) {
|
||||
var noErrors = verify({
|
||||
options: {debug: true},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'http://gitlab.corp.com/whats/up.git'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tt.is(noErrors.length, 0)
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.test('publish verification', function (tt) {
|
||||
var noErrors = verify({
|
||||
env: {NPM_TOKEN: 'yo'},
|
||||
options: {githubToken: 'sup'},
|
||||
pkg: {
|
||||
name: 'package',
|
||||
repository: {
|
||||
url: 'http://github.com/whats/up.git'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tt.is(noErrors.length, 0)
|
||||
|
||||
var errors = verify({env: {}, options: {}, pkg: {}})
|
||||
|
||||
tt.is(errors.length, 4)
|
||||
tt.is(errors[0].code, 'ENOPKGNAME')
|
||||
tt.is(errors[1].code, 'ENOPKGREPO')
|
||||
tt.is(errors[2].code, 'ENOGHTOKEN')
|
||||
tt.is(errors[3].code, 'ENONPMTOKEN')
|
||||
|
||||
tt.end()
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
test:{SHA}C+7Hteo/D9vJXQ3UfzxbwnXaijM=
|
||||
@@ -1,4 +0,0 @@
|
||||
_auth=dGVzdDpmb28=
|
||||
email=test@example.com
|
||||
registry=http://127.0.0.1:4873/
|
||||
//registry.npmjs.org/:_authToken=testtoken
|
||||
@@ -1,17 +0,0 @@
|
||||
storage: ../.tmp/.storage
|
||||
|
||||
auth:
|
||||
htpasswd:
|
||||
file: ./.htpasswd
|
||||
|
||||
uplinks:
|
||||
npmjs:
|
||||
url: https://registry.npmjs.org/
|
||||
|
||||
logs:
|
||||
- {type: stdout, format: pretty, level: silent}
|
||||
|
||||
packages:
|
||||
'*':
|
||||
allow_access: all
|
||||
allow_publish: all
|
||||
@@ -1,35 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const exec = require('child_process').exec
|
||||
|
||||
const nixt = require('nixt')
|
||||
|
||||
module.exports = function (t, message, version, code, name, cwd) {
|
||||
t.test(name, (t) => {
|
||||
t.plan(3)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('npm_config_registry', 'http://127.0.0.1:4873/')
|
||||
.exec(`git commit --allow-empty -m "${message}"`)
|
||||
.run('npm run prepublish')
|
||||
.code(code)
|
||||
.stdout(/semantic-release.js pre\n\nDetermining new version\n/m)
|
||||
.end((err) => {
|
||||
t.error(err, 'nixt')
|
||||
|
||||
const pkg = JSON.parse(fs.readFileSync(`${cwd}/package.json`))
|
||||
t.is(pkg.version, version, 'version')
|
||||
|
||||
if (code === 1) {
|
||||
return t.error(null, 'no publish')
|
||||
}
|
||||
|
||||
exec('npm publish --ignore-scripts', {cwd}, (err) => {
|
||||
setTimeout(() => {
|
||||
t.error(err, 'publish')
|
||||
}, 300)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
const exec = require('child_process').exec
|
||||
const join = require('path').join
|
||||
|
||||
const efh = require('error-first-handler')
|
||||
const defaults = require('lodash.defaults')
|
||||
const uid = require('nano-uid')()
|
||||
|
||||
module.exports = function (input) {
|
||||
const cb = Array.prototype.pop.call(arguments)
|
||||
uid.generate(5, efh(cb)((id) => {
|
||||
const pkg = defaults((typeof input === 'object' ? input : {}), {
|
||||
name: id,
|
||||
version: '0.0.0',
|
||||
scripts: {
|
||||
prepublish: '../../../bin/semantic-release.js pre',
|
||||
postpublish: '../../../bin/semantic-release.js post'
|
||||
},
|
||||
publishConfig: {
|
||||
registry: 'http://localhost:4873/'
|
||||
}
|
||||
})
|
||||
|
||||
id = pkg.name
|
||||
const cwd = join(__dirname, '../../.tmp/modules', id)
|
||||
|
||||
exec(
|
||||
`mkdir ${cwd} &&
|
||||
cd ${cwd} &&
|
||||
git init &&
|
||||
echo '${JSON.stringify(pkg, null, 2)}' >> package.json &&
|
||||
git add . &&
|
||||
git config user.email "integration@test" &&
|
||||
git config user.name "Integration Test" &&
|
||||
git commit -m "initial"`
|
||||
, efh(cb)((stdout) => {
|
||||
cb(null, id, cwd)
|
||||
}))
|
||||
}))
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
module.exports = function (commits) {
|
||||
let type = null
|
||||
|
||||
commits.every((commit) => {
|
||||
if (/FOO/.test(commit.message)) {
|
||||
type = 'major'
|
||||
return false
|
||||
}
|
||||
|
||||
if (/BAR/.test(commit.message)) type = 'minor'
|
||||
|
||||
if (!type && /BAZ/.test(commit.message)) type = 'patch'
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
return type
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = function (opts, cb) {
|
||||
cb(null, !(opts.commits.length % 2))
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
const path = require('path')
|
||||
|
||||
const efh = require('error-first-handler')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
const commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
test('custom-analyzer', (t) => {
|
||||
createModule({
|
||||
release: {
|
||||
analyzer: path.join(__dirname, '../lib/custom-analyzer')
|
||||
}
|
||||
}, efh()((name, cwd) => {
|
||||
commitToVersionTest(t, 'HO', '0.0.0', 1, 'abort publish w/o changes', cwd)
|
||||
commitToVersionTest(t, 'BAZ', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd)
|
||||
commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd)
|
||||
commitToVersionTest(t, 'BAR', '1.1.0', 0, 'bump minor for feature', cwd)
|
||||
commitToVersionTest(t, 'FOO', '2.0.0', 0, 'bump major for breaking change', cwd)
|
||||
}))
|
||||
})
|
||||
@@ -1,40 +0,0 @@
|
||||
const path = require('path')
|
||||
|
||||
const efh = require('error-first-handler')
|
||||
const nixt = require('nixt')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
test('custom-verification', (t) => {
|
||||
createModule({
|
||||
release: {
|
||||
verification: path.join(__dirname, '../lib/custom-verification')
|
||||
}
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('even commit count', (t) => {
|
||||
t.plan(1)
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('npm_config_registry', 'http://127.0.0.1:4873/')
|
||||
.exec('git commit --allow-empty -m "feat: commit"')
|
||||
.run('npm run prepublish')
|
||||
.code(0)
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
|
||||
t.test('odd commit count', (t) => {
|
||||
t.plan(1)
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('npm_config_registry', 'http://127.0.0.1:4873/')
|
||||
.exec('git commit --allow-empty -m "feat: commit"')
|
||||
.run('npm run prepublish')
|
||||
.code(1)
|
||||
.stdout(/Verification failed/)
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
})
|
||||
@@ -1,36 +0,0 @@
|
||||
const fs = require('fs')
|
||||
|
||||
const efh = require('error-first-handler')
|
||||
const nixt = require('nixt')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
test('ignore', (t) => {
|
||||
createModule(efh()((name, cwd) => {
|
||||
ignoreTest(t, cwd, 'npm install', 'not doing anything when the module is installed')
|
||||
ignoreTest(t, cwd, 'npm i', 'not doing anything when the module is installed with abbrevd command')
|
||||
ignoreTest(t, cwd, 'npm link', 'not doing anything when the module is linked')
|
||||
ignoreTest(t, cwd, 'npm lin', 'not doing anything when the module is linked with abbrevd command')
|
||||
ignoreTest(t, cwd, 'npm pack', 'not doing anything when the module is packed')
|
||||
ignoreTest(t, cwd, 'npm pa', 'not doing anything when the module is packed with abbrevd command')
|
||||
}))
|
||||
})
|
||||
|
||||
function ignoreTest (t, cwd, command, name) {
|
||||
t.test(name, (t) => {
|
||||
t.plan(2)
|
||||
|
||||
const pkg = String(fs.readFileSync(cwd + '/package.json'))
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.run(command)
|
||||
.code(0)
|
||||
.stdout(/semantic-release.js pre\n$/m)
|
||||
.end((err) => {
|
||||
t.is(pkg, String(fs.readFileSync(`${cwd}/package.json`)), 'package')
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
const path = require('path')
|
||||
|
||||
const efh = require('error-first-handler')
|
||||
const GitHubApi = require('github')
|
||||
const nixt = require('nixt')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
const github = new GitHubApi({
|
||||
version: '3.0.0',
|
||||
port: 4343,
|
||||
protocol: 'http',
|
||||
host: '127.0.0.1'
|
||||
})
|
||||
|
||||
github.authenticate({
|
||||
type: 'oauth',
|
||||
token: '***'
|
||||
})
|
||||
|
||||
test('postpublish', (t) => {
|
||||
createModule({
|
||||
version: '2.0.0',
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'http://github.com/user/repo'
|
||||
}
|
||||
}, efh()((name, cwd) => {
|
||||
const base = getBase(cwd)
|
||||
|
||||
t.test('publish new version to github releases', (t) => {
|
||||
t.plan(1)
|
||||
|
||||
base.clone()
|
||||
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
|
||||
.run('npm run postpublish')
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
|
||||
t.test('publish new version (with detached HEAD) to github releases', (t) => {
|
||||
t.plan(1)
|
||||
|
||||
base.clone()
|
||||
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
|
||||
.exec('git checkout `git rev-parse HEAD`')
|
||||
.run('npm run postpublish')
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
|
||||
t.test('correct data published', (t) => {
|
||||
t.plan(4)
|
||||
|
||||
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, (err, raw) => {
|
||||
const res = JSON.parse(raw)
|
||||
t.error(err, 'github')
|
||||
t.is(res.tag_name, 'v2.0.0', 'version')
|
||||
t.is(res.author.login, 'user', 'user')
|
||||
t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\*\n.*the next big thing/.test(res.body), 'body')
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
||||
createModule({
|
||||
version: '2.0.0',
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'http://github.com/user/repo'
|
||||
},
|
||||
release: {
|
||||
notes: path.join(__dirname, '../lib/custom-release-notes')
|
||||
}
|
||||
}, efh()((name, cwd) => {
|
||||
const base = getBase(cwd)
|
||||
|
||||
t.test('publish new version (with custom notes) to github releases', (t) => {
|
||||
t.plan(1)
|
||||
|
||||
base.clone()
|
||||
.run('npm run postpublish')
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
|
||||
t.test('custom notes published', (t) => {
|
||||
t.plan(4)
|
||||
|
||||
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, (err, raw) => {
|
||||
const res = JSON.parse(raw)
|
||||
t.error(err, 'github')
|
||||
t.is(res.tag_name, 'v2.0.0', 'version')
|
||||
t.is(res.author.login, 'user', 'user')
|
||||
t.ok(/custom log/.test(res.body), 'body')
|
||||
})
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
function getBase (cwd) {
|
||||
return nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('GH_URL', 'http://127.0.0.1:4343/')
|
||||
.env('GH_TOKEN', '***')
|
||||
.exec('git commit --allow-empty -m "feat(cool): the next big thing"')
|
||||
.code(0)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
const efh = require('error-first-handler')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
const commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
test('prepublish', (t) => {
|
||||
createModule(efh()((name, cwd) => {
|
||||
commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', cwd)
|
||||
commitToVersionTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd)
|
||||
commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd)
|
||||
commitToVersionTest(t, 'feat: change', '1.1.0', 0, 'bump minor for feature', cwd)
|
||||
commitToVersionTest(t, 'fix: BREAKING CHANGE: change', '2.0.0', 0, 'bump major for breaking change', cwd)
|
||||
}))
|
||||
})
|
||||
@@ -1,34 +0,0 @@
|
||||
const efh = require('error-first-handler')
|
||||
const nixt = require('nixt')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
test('publish', (t) => {
|
||||
publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish')
|
||||
publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command')
|
||||
|
||||
function publishTest (t, command, testname, last) {
|
||||
createModule({
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'http://github.com/user/repo'
|
||||
}
|
||||
}, efh()((name, cwd) => {
|
||||
t.test(testname, (t) => {
|
||||
t.plan(1)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.env('GH_URL', 'http://127.0.0.1:4343/')
|
||||
.env('GH_TOKEN', '***')
|
||||
.exec('git commit --allow-empty -m "feat: super"')
|
||||
.run(command)
|
||||
.code(1)
|
||||
.stdout(/Everything is alright/)
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
}
|
||||
})
|
||||
@@ -1,37 +0,0 @@
|
||||
const join = require('path').join
|
||||
const readFile = require('fs').readFileSync
|
||||
|
||||
const efh = require('error-first-handler')
|
||||
const nixt = require('nixt')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
test('setup', (t) => {
|
||||
createModule({
|
||||
repository: {},
|
||||
scripts: {
|
||||
postpublish: 'npm run gh-pages'
|
||||
}
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('setup "package.json"', (t) => {
|
||||
t.plan(5)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.exec('git remote add origin git@github.com:user/repo.git')
|
||||
.run('../../../bin/semantic-release.js setup')
|
||||
.code(0)
|
||||
.end((err) => {
|
||||
t.error(err, 'nixt')
|
||||
|
||||
const pkg = JSON.parse(readFile(join(cwd, 'package.json')))
|
||||
|
||||
t.is(pkg.version, '0.0.0-semantically-released', 'version')
|
||||
t.is(pkg.repository.url, 'https://github.com/user/repo', 'repo')
|
||||
t.is(pkg.scripts.prepublish, 'semantic-release pre', 'pre')
|
||||
t.is(pkg.scripts.postpublish, 'npm run gh-pages && semantic-release post', 'post')
|
||||
})
|
||||
})
|
||||
}))
|
||||
})
|
||||
@@ -1,45 +0,0 @@
|
||||
const efh = require('error-first-handler')
|
||||
const nixt = require('nixt')
|
||||
const test = require('tap').test
|
||||
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
test('verify', (t) => {
|
||||
createModule({
|
||||
repository: {},
|
||||
scripts: {
|
||||
prepublish: '../../../bin/semantic-release.js pre --no-token'
|
||||
}
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('verify package and options before publishing', (t) => {
|
||||
t.plan(1)
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.run('npm publish')
|
||||
.stderr(new RegExp(
|
||||
`You must define a GitHub token\.
|
||||
You must define your GitHub "repository" inside the "package.json"\.
|
||||
You must define your "scripts" inside the "package.json"\.`
|
||||
, 'm'
|
||||
))
|
||||
.code(1)
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
|
||||
createModule({
|
||||
version: '1.0.0-semantically-released'
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('not publishing placeholder versions', (t) => {
|
||||
t.plan(1)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.run('npm publish --semantic-release-rerun')
|
||||
.code(1)
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
})
|
||||
@@ -1,49 +0,0 @@
|
||||
const test = require('tap').test
|
||||
const nock = require('nock')
|
||||
|
||||
const npmInfo = require('../../dist/lib/npm-info.js')
|
||||
|
||||
const registry = 'http://registry.npmjs.org/'
|
||||
|
||||
const defaultModule = {
|
||||
'dist-tags': {
|
||||
latest: '1.0.0'
|
||||
},
|
||||
versions: {
|
||||
'1.0.0': {
|
||||
gitHead: 'HEAD'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process.env.npm_config_registry = registry
|
||||
|
||||
test('npm-info', (t) => {
|
||||
const regMock = nock(registry, {
|
||||
reqheaders: {
|
||||
'authorization': 'Bearer testtoken'
|
||||
}
|
||||
})
|
||||
.get('/express')
|
||||
.reply(200, defaultModule)
|
||||
.get('/@user%2Fmodule')
|
||||
.reply(200, defaultModule)
|
||||
|
||||
t.test('get unscoped module', (t) => {
|
||||
t.plan(3)
|
||||
npmInfo('express', (err, info) => {
|
||||
t.error(err, 'error')
|
||||
t.is(info.version, '1.0.0', 'version')
|
||||
t.is(info.gitHead, 'HEAD', 'gitHead')
|
||||
})
|
||||
})
|
||||
t.test('get scoped module', (t) => {
|
||||
t.plan(3)
|
||||
npmInfo('@user/module', (err, info) => {
|
||||
t.error(err, 'error')
|
||||
t.is(info.version, '1.0.0', 'version')
|
||||
t.is(info.gitHead, 'HEAD', 'gitHead')
|
||||
regMock.done()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user