Skip to content

Commit 6add3d3

Browse files
committed
Build and publish pre-releases in Travis CI
1 parent 1b5c791 commit 6add3d3

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file primarily exists to prevent ./dist from being ignored when publishing.
2+
# (Because it's listed in .gitignore).
3+
4+
coverage

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
install:
3+
- npm install
4+
script:
5+
- npm test
6+
# Make sure it still builds successfully - the build isn't actually used yet:
7+
- npm run build
8+
before_deploy:
9+
- node ./travis/bumpversion.js
10+
deploy:
11+
provider: npm
12+
# Do not throw away the updated package.json we generated in `before_deploy`:
13+
skip_cleanup: true
14+
email: "$NPM_EMAIL"
15+
api_key: "$NPM_TOKEN"
16+
# Note: do not deploy on pull request, because $TRAVIS_BRANCH will be the target branch.
17+
tag: "$TRAVIS_BRANCH"
18+
on:
19+
all_branches: true

build.sh

-5
This file was deleted.

travis/bumpversion.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* npm does not allow you to publish a package with the same version multiple times.
3+
* Thus, to publish prerelease versions tagged to the branch they're built from,
4+
* we need to generate unique version numbers that are also higher than versions already published.
5+
* To achieve this, we append `build<build_number>` to the version number.
6+
* The actual release version can eventually be published without the suffix.
7+
*/
8+
9+
if (!process.env.TRAVIS_BUILD_NUMBER || process.env.TRAVIS_BUILD_NUMBER.length === 0) {
10+
console.error('Could not read the build number to bump the package version - aborting publish.')
11+
process.exit(1)
12+
}
13+
14+
const fs = require('fs')
15+
const path = require('path')
16+
17+
const packageJson = require('../package.json')
18+
packageJson.version = `${packageJson.version}build${process.env.TRAVIS_BUILD_NUMBER}`
19+
fs.writeFileSync(path.resolve(__dirname, '../package.json'), JSON.stringify(packageJson))

0 commit comments

Comments
 (0)