I'd like to write a cli command to integrate all actions I have to do when I complete a local working session on my (react-js) project:
- increase by one the version of the project (in
version
field inpackage.json
file) - add all changes I did to git index
- commit changes to git (with a message)
- tag the version with new version number and commit message
- pull from remote
- push to remote (including tags)
The push to remote (github or gitlab, for example) will initiate a CI/CD build, too.
What I came up with until now is something as ugly as this:
m="debugging tag & version"; npm version --no-git-tag-version --force patch && git add . && git commit -m "$m" && git tag -a v`node -p "require('./package.json').version"` -m "$m" && git pull --no-edit && git push --follow-tags
The main drawback of this is that it forces a double build on remote, probably because it is pushing twice... But I can't see why, since I do not know in depth all the interested commands.
Can you give some advise to correct my solution, or suggest a different strategy?
UPDATE: I include my GitLab's CI configuration file (.gitlab-ci.yml) here, it it can be of any help...
variables:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
build site:
image: node:12
stage: build
script:
- yarn install --no-progress 2> >(grep -v warning 1>&2)
- yarn build
artifacts:
expire_in: 1 week
paths:
- build/
# we test only on master branch to speed up CI/CD while developing, for the moment...
unit test:
image: node:12
stage: test
only:
- master
script:
- yarn install --no-progress 2> >(grep -v warning 1>&2)
- yarn test
# we only deploy on master and developing branches; for other feature branches,
# we work locally only and then merge into developing or master.
deploy:
image: alpine
stage: deploy
only:
- master
- developing
before_script:
- apk add --no-cache rsync openssh sshpass
script:
- if [ -z "$CI_COMMIT_BRANCH" -o "$CI_COMMIT_BRANCH" = "master" ]; then DEPLOY_PATH="marketplace"; else DEPLOY_PATH="marketplace.test"; fi
- echo "On branch $CI_COMMIT_BRANCH, deploying to $DEPLOY_PATH"
- sshpass -p $DEVEL_PASS rsync -az --delete --no-perms --no-g -O -e "ssh -o StrictHostKeyChecking=no" build/ $DEVEL_USER@$SERVER_NAME:/var/www/$DEPLOY_PATH/