From ef0a0690a9027bc3c22e8b02ed89a7ea15564d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B2?= Date: Sat, 24 Feb 2024 16:10:05 +0000 Subject: [PATCH] add CD releasing [PATCH] --- .github/workflows/{nodejs.yml => ci-cd.yml} | 3 +++ package.json | 3 ++- semantic-versioning.sh | 23 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) rename .github/workflows/{nodejs.yml => ci-cd.yml} (89%) create mode 100755 semantic-versioning.sh diff --git a/.github/workflows/nodejs.yml b/.github/workflows/ci-cd.yml similarity index 89% rename from .github/workflows/nodejs.yml rename to .github/workflows/ci-cd.yml index 4a8899a..a4c7ec5 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/ci-cd.yml @@ -22,5 +22,8 @@ jobs: npm install npm ci npm test + - name: release + run: | + npm run release env: CI: true diff --git a/package.json b/package.json index 106ea48..2e68ffc 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test-debug": "node --inspect-brk node_modules/.bin/jest --runInBand --detectOpenHandles", "version-patch": "npm version patch --force && npm publish && git push --follow-tags", "version-minor": "npm version minor --force && npm publish && git push --follow-tags", - "version-major": "npm version major --force && npm publish && git push --follow-tags" + "version-major": "npm version major --force && npm publish && git push --follow-tags", + "release": "./semantic-versioning.sh" }, "repository": { "type": "git", diff --git a/semantic-versioning.sh b/semantic-versioning.sh new file mode 100755 index 0000000..2ab291f --- /dev/null +++ b/semantic-versioning.sh @@ -0,0 +1,23 @@ +#!/bin/bash +echo "Start Semantic Versioning release..."; +echo "Checking branch..."; +RELEASE_BRANCH="master"; +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD); +if [ $RELEASE_BRANCH != $CURRENT_BRANCH ]; then + echo "A new release version is only bumped on branch: $RELEASE_BRANCH."; + echo "Exiting..."; + exit 0; +fi +PATCH_MSG="[PATCH]"; +MAJOR_MSG="[MAJOR]"; +echo "Parsing git message..."; +COMMIT_MSG=$(git log -1 --pretty=format:"%s"); +echo "Last commit message: ${COMMIT_MSG}"; +if [[ $COMMIT_MSG == *"$PATCH_MSG"* ]]; then + echo "Executing new PATCH release..." +elif [[ $COMMIT_MSG == *"$MAJOR_MSG"* ]]; then + echo "Executing new MAJOR release..." +else + echo "Executing new MINOR release..."; +fi +echo "End Semantic Versioning release."; \ No newline at end of file