-
-
Save orocancourt/be3ae4c9781dba0f2bcca51f9f017ea6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
shopt -s nocasematch | |
set -e | |
set -o pipefail | |
npm run test | |
FIX_PATTERN="*FIX*" | |
MASTER_BRANCH="master" | |
B2C_REPOSITORY="ClubMediterranee/cm-b2c" | |
CI_SKIP="[ci skip]" | |
FORCE_PUBLISH="[ci publish]" | |
COMMIT_MESSAGE="$(git log --format=%B --no-merges -n 1)" | |
if [ "${TRAVIS_REPO_SLUG}" == "${B2C_REPOSITORY}" ] && [ "${TRAVIS_BRANCH}" != "${MASTER_BRANCH}" ]; then | |
if [[ ${COMMIT_MESSAGE} =~ "${FORCE_PUBLISH}" ]]; then | |
echo "Publish required ! Continuing." | |
else | |
echo "No NPM publish for cm-b2c branches. Exiting." | |
exit 0 | |
fi | |
fi | |
################################################################################################### | |
### Configure workspace | |
################################################################################################### | |
if [ -n "$GIT_USER_EMAIL" ] && [ -n "$GIT_USER_NAME" ]; | |
then | |
echo "Configure git with username" ${GIT_USER_NAME} "and email" ${GIT_USER_EMAIL} | |
git config --global user.name ${GIT_USER_NAME} | |
git config --global user.email ${GIT_USER_EMAIL} | |
else | |
echo ERROR:"Ignore git configuration (Empty GIT_USER_EMAIL or/and GIT_USER_NAME variables)" | |
exit 1 | |
fi | |
npm config set loglevel warn | |
npm config set git-tag-version false | |
git checkout ${TRAVIS_BRANCH} | |
NPM_PACKAGE_NAME=$(node -p -e "require('./package.json').name") | |
NPM_PACKAGE_VERSION=`npm show {NPM_PACKAGE_NAME} version` | |
echo "-----------------------------------" | |
echo "--- Package info" | |
echo "-----------------------------------" | |
echo "Name : " ${NPM_PACKAGE_NAME} | |
echo "Version : " ${NPM_PACKAGE_VERSION} | |
################################################################################################### | |
### Prepare release infos | |
################################################################################################### | |
if [[ ${RELEASE_MESSAGE} == ${FIX_PATTERN} ]]; then | |
RELEASE_TYPE="patch" | |
else | |
RELEASE_TYPE="minor" | |
fi | |
RELEASE_NPM_TAG="latest" | |
RELEASE_MESSAGE="$(git log --first-parent --format=%B -n 1)" | |
RELEASE_VERSION=`semver ${NPM_PACKAGE_VERSION} -i ${RELEASE_TYPE}` | |
if [[ ${TRAVIS_BRANCH} != ${MASTER_BRANCH} ]]; then | |
SHORT_HASH="$(git rev-parse --short ${TRAVIS_COMMIT})" | |
RELEASE_NPM_TAG="rc" | |
RELEASE_VERSION=${RELEASE_VERSION}-${SHORT_HASH} | |
fi | |
RELEASE_TAG="version-${RELEASE_VERSION}" | |
RELEASE_MESSAGE=$(echo ${RELEASE_MESSAGE} | sed ':a;N;$!ba;s/\n/ /g') | |
echo "-----------------------------------" | |
echo "--- Release info" | |
echo "-----------------------------------" | |
echo "Type :" ${RELEASE_TYPE} | |
echo "Version :" ${RELEASE_VERSION} | |
echo "Tag :" ${RELEASE_TAG} | |
echo "Npm Tag :" ${RELEASE_NPM_TAG} | |
echo "Message :" ${RELEASE_MESSAGE} | |
################################################################################################### | |
### Publish release | |
################################################################################################### | |
npm version ${RELEASE_VERSION} | |
if [[ ${TRAVIS_BRANCH} == ${MASTER_BRANCH} ]]; then | |
git add package.json | |
git commit -m "${RELEASE_MESSAGE} - ${CI_SKIP}" | |
git pull --rebase | |
git push origin ${TRAVIS_BRANCH} | |
fi | |
echo "Publishing on NPM" | |
npm publish --tag ${RELEASE_NPM_TAG} | |
echo "Tagging on Github" | |
git tag ${RELEASE_TAG} -a -m "Version ${RELEASE_VERSION}" | |
echo "Pushing on Github" | |
git push origin ${RELEASE_TAG} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment