Skip to content

Instantly share code, notes, and snippets.

@wojtek1150
Created April 6, 2023 08:30
Show Gist options
  • Save wojtek1150/cdb1470d02412c944ef5a063f48461b5 to your computer and use it in GitHub Desktop.
Save wojtek1150/cdb1470d02412c944ef5a063f48461b5 to your computer and use it in GitHub Desktop.
YML script for create tag for NPM based project
# YML script for creating tag of npm project from release branch
# There are 2 wersions, x.y.z-SNAPSHOT for development and x.y.z for releasing.
# Tag will be created without snapshot postfix
before_script:
# fetch version to release from package.json snapshot version
- export RELEASE_VERSION=$(node -p "require('./package.json').version.replace('-SNAPSHOT','')")
# bump next patch version in pattern X.X.X+1 from RELEASE_VERSION
- export NEXT_PATCH_VERSION=$(perl -pe 's/^(\d+)\.(\d+)\.(\d+)$/"$1.$2.".($3+1)/e' <<< $RELEASE_VERSION)
script:
# set RELEASE_VERSION in package.json
- npm version ${RELEASE_VERSION} -git-tag-version=false
# commit and tag
- git commit -a -m "Release ${RELEASE_VERSION}"
- git push --push-option=ci.skip origin HEAD:${CI_COMMIT_REF_NAME}
- git tag ${RELEASE_VERSION}
- git push origin ${RELEASE_VERSION}
# set NEXT_PATCH_VERSION (snapshot) in package.json
- npm version ${NEXT_PATCH_VERSION}-SNAPSHOT -git-tag-version=false
# commit, push and sync to develop
- git commit -a -m "New snapshot version ${NEXT_PATCH_VERSION}"
- git push --push-option=ci.skip origin HEAD:${CI_COMMIT_REF_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment