diff --git a/.github/workflows/nodejs.yml b/.github/workflows/ci-cd.yml similarity index 62% rename from .github/workflows/nodejs.yml rename to .github/workflows/ci-cd.yml index 4a8899a..c34487d 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/ci-cd.yml @@ -4,7 +4,7 @@ on: [push] jobs: build: - + name: build runs-on: ubuntu-latest strategy: @@ -24,3 +24,16 @@ jobs: npm test env: CI: true + + release: + name: release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js 21.x + uses: actions/setup-node@v4 + with: + node-version: 21.x + - name: release + run: | + npm run release diff --git a/README.md b/README.md index d008b7d..55b9291 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ + [Encoding](#encoding) * [Chaining Pattern](#chaining-pattern) - [Development](#development) +- [CI/CD](#ci/cd-github-action) - [License](#license) - [Buy me a Coffee](#buy-me-a-coffee) @@ -308,6 +309,14 @@ csvToJson.fieldDelimiter(',') npm run test-debug ~~~ +## CI/CD github action +Pushing on the master branch, depending on the git message, an new version will always be released. +If the commit message contains the keyword: +* **[MAJOR]**: new major relase, e.g. v1.0.0 -> v2.0.0 +* **[PATCH]**: new patch relase, e.g. v1.0.0 -> v1.0.1 +* without any of the above keywords a new minor relase will be applied, e.g. v1.0.0 -> v1.1.0 + + ## License CSVtoJSON is licensed under the GNU General Public License v3.0 [License](LICENSE). 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..1b2d10e --- /dev/null +++ b/semantic-versioning.sh @@ -0,0 +1,26 @@ +#!/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..." + npm run version-patch; +elif [[ $COMMIT_MSG == *"$MAJOR_MSG"* ]]; then + echo "Executing new MAJOR release..." + npm run version-major; +else + echo "Executing new MINOR release..."; + npm run version-minor; +fi +echo "End Semantic Versioning release."; \ No newline at end of file