Skip to content

Commit

Permalink
add CD releasing [PATCH]
Browse files Browse the repository at this point in the history
  • Loading branch information
iuccio committed Feb 24, 2024
1 parent 853a318 commit b27f326
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/nodejs.yml → .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]

jobs:
build:

name: build
runs-on: ubuntu-latest

strategy:
Expand All @@ -24,3 +24,19 @@ 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
registry-url: 'https://registry.npmjs.org'
- name: release
run: |
npm run release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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).

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions semantic-versioning.sh
Original file line number Diff line number Diff line change
@@ -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.";

0 comments on commit b27f326

Please sign in to comment.