Skip to content

Instantly share code, notes, and snippets.

@benjamincharity
Last active April 23, 2019 14:43
Show Gist options
  • Save benjamincharity/dfd8d58ee08eb0bb42a2551144c0a21e to your computer and use it in GitHub Desktop.
Save benjamincharity/dfd8d58ee08eb0bb42a2551144c0a21e to your computer and use it in GitHub Desktop.
CircleCI deploy to NPM
machine:
node:
version: 6.9.5
dependencies:
pre:
- 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
test:
override:
- rm -rf $CIRCLE_ARTIFACTS/coverage
- npm run lint
- npm run test
- cp -r coverage $CIRCLE_ARTIFACTS
- node node_modules/coveralls/bin/coveralls.js < coverage/coverage.lcov
compile:
override:
- npm run build
deployment:
feature:
branch: master
commands:
- ./config/npm-deploy-feature.sh
production:
tag: /(v)?[0-9]+(\.[0-9]+)*/
commands:
- ./config/npm-deploy.sh
#!/bin/bash
git config --global -l
git config --global user.email circleci@circleci
git config --global user.name CircleCI
git remote --v
# Get the last tag from GitHub
lastTag=$(git describe --tags $(git rev-list --tags --max-count=1))
# Bump the version
npm version $lastTag-feature.$CIRCLE_BUILD_NUM
# Push the new tag to Github
git push --tags
# Copy files to dist
cpx package.json dist
cpx README.md dist
# Publish to NPM
npm publish --tag feature
#!/bin/bash
# Get the last tag from GitHub
lastTag=$(git describe --tags $(git rev-list --tags --max-count=1))
# Print it to the console for verification
echo "Bumping version to new tag: ${lastTag}"
# Bump the version
npm --no-git-tag-version version $lastTag
# Copy files to dist
cpx package.json dist
cpx README.md dist
# Publish to NPM
npm publish
@alexjfno1
Copy link

alexjfno1 commented Aug 18, 2017

How do you go about pushing the updated package.json to the git repo? How do you avoid conflicts etc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment