Skip to content

Commit 3495f4c

Browse files
Vinnlunknown
authored andcommitted
Publish branches as npm tags
Although this does not yet add the ability to publish stable releases to npm from CI, this does publish every newly pushed branch to npm using that branch's name as the tag. This will allow us to test whether a package still works properly after it's published and built.
1 parent c9e6e84 commit 3495f4c

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@ script:
55
- npm test
66
# Make sure it still builds successfully - the build isn't actually used yet:
77
- 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

travis/bumpversion.js

Lines changed: 19 additions & 0 deletions
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)