From 0e65f8b133f13034f4c51138b89e2c3263eafaeb Mon Sep 17 00:00:00 2001 From: Craig Weber Date: Thu, 8 Aug 2024 13:44:52 -0400 Subject: [PATCH] ci: add commitizen --- .cz.toml | 23 +++++++++++++++++++++++ .pre-commit-config.yaml | 6 ++++++ CHANGELOG.md | 1 + bin/publish.sh | 37 +++---------------------------------- 4 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 .cz.toml create mode 100644 CHANGELOG.md diff --git a/.cz.toml b/.cz.toml new file mode 100644 index 0000000..c56a3a0 --- /dev/null +++ b/.cz.toml @@ -0,0 +1,23 @@ +[tool.commitizen] +name = "cz_conventional_commits" +annotated_tag = true +gpg_sign = true +major_version_zero = true +tag_format = "v$version" +update_changelog_on_bump = true +changelog_merge_prerelease = true +version_provider = "npm" +version_scheme = "semver" +version_files = [ + "package.json:version", +] +pre_bump_hooks = [ + "npm i", + "npm run lint", + "npm run build", + "pre-commit run --all-files || true", +] +post_bump_hooks = [ + "git push origin master $CZ_POST_CURRENT_TAG_VERSION", + "npm publish", +] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 906e928..158955c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,5 +23,11 @@ repos: rev: "v3.3.3" hooks: - id: prettier + exclude: "^.git/" + + - repo: https://github.com/commitizen-tools/commitizen + rev: v3.28.0 + hooks: + - id: commitizen exclude: "^dist/" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..268a01b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +## Unreleased diff --git a/bin/publish.sh b/bin/publish.sh index f766487..139d840 100755 --- a/bin/publish.sh +++ b/bin/publish.sh @@ -1,17 +1,6 @@ #!/usr/bin/env bash -set -e - -# Validate tag name -TAG_NAME="$1" -if [ -z "$TAG_NAME" ]; then - echo "Tag name is missing" - exit 1 -fi - -# Remove the "r" prefix from the tag name -PREFIX="v" -VERSION="${TAG_NAME#"$PREFIX"}" +set -euxo pipefail # Check git status git fetch --all @@ -29,25 +18,5 @@ else exit 1 fi -# Set version in packages/thelab-ui-js/package.json -PKG_FILE="package.json" -PKG_BK_FILE="${PKG_FILE}.bk" -jq --arg VERSION "$VERSION" '.version=$VERSION' "$PKG_FILE" > "$PKG_BK_FILE" -mv "$PKG_BK_FILE" "$PKG_FILE" -npm i -git add "$PKG_FILE" "package-lock.json" - -# Build -npm run lint -npm run build - -# Commit -git commit -m "release: ${TAG_NAME}" -git tag -a "$TAG_NAME" -m "New Release: $TAG_NAME" - -# Push branch and tags. CI will see the new tag and run a job to publish the packages. -git push origin master -git push origin "$TAG_NAME" - -# Publish to NPM -npm publish +# Update version and publish via commitizen +cz bump "$@"