Skip to content

Commit 2a5593c

Browse files
authoredFeb 24, 2022
Merge pull request #20 from commitizen-tools/feat/commitizen-version
feat: add commitizen version input
2 parents e96ec81 + 747b20d commit 2a5593c

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed
 

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ jobs:
7777
| `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` |
7878
| `push` | Define if the changes should be pushed to the branch. | true |
7979
| `commit` | Define if the changes should be committed to the branch. | true |
80-
| <!-- | `changelog` | Create changelog when bumping the version | true | --> |
80+
| `commitizen_version` | Specify the version to be used by commitizen. Eg: `2.21.0` | latest |
81+
| `changelog` | Create changelog when bumping the version | true |
8182

8283
## Outputs
8384

‎action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ inputs:
5454
description: 'Email address used to configure git (for git operations)'
5555
required: false
5656
default: 'github-actions[bot]@users.noreply.github.com'
57+
commitizen_version:
58+
description: 'Specify the version to be used by commitizen'
59+
required: false
60+
default: 'latest'

‎entrypoint.sh

+16-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ if [ $INPUT_DRY_RUN ]; then INPUT_DRY_RUN='--dry-run'; else INPUT_DRY_RUN=''; fi
44
if [ $INPUT_CHANGELOG ]; then INPUT_CHANGELOG='--changelog'; else INPUT_CHANGELOG=''; fi
55
if [ $INPUT_PRERELEASE ]; then INPUT_PRERELEASE="--prerelease $INPUT_PRERELEASE"; else INPUT_PRERELEASE=''; fi
66
if [ "$INPUT_COMMIT" == 'false' ]; then INPUT_COMMIT='--files-only'; else INPUT_COMMIT=''; fi
7+
if [ "$INPUT_COMMITIZEN_VERSION" == 'latest' ]; then INPUT_COMMITIZEN_VERSION="commitizen"; else INPUT_COMMITIZEN_VERSION="commitizen==$INPUT_COMMITIZEN_VERSION"; fi
8+
9+
710
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
811
INPUT_BRANCH=${INPUT_BRANCH:-$CURRENT_BRANCH}
912
INPUT_EXTRA_REQUIREMENTS=${INPUT_EXTRA_REQUIREMENTS:-''}
@@ -13,46 +16,44 @@ REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
1316
set -e
1417

1518
[ -z "${INPUT_GITHUB_TOKEN}" ] && {
16-
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".';
17-
exit 1;
18-
};
19+
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".'
20+
exit 1
21+
}
1922

2023
echo "Repository: $REPOSITORY"
2124
echo "Actor: $GITHUB_ACTOR"
2225

2326
echo "Installing requirements..."
24-
pip install commitizen $INPUT_EXTRA_REQUIREMENTS
27+
pip install "$INPUT_COMMITIZEN_VERSION" $INPUT_EXTRA_REQUIREMENTS
2528
echo "Commitizen version:"
2629
cz version
2730

28-
2931
echo "Configuring git user and email..."
3032
git config --local user.name "$INPUT_GIT_NAME"
3133
git config --local user.email "$INPUT_GIT_EMAIL"
3234
echo "Git name: $(git config --get user.name)"
3335
echo "Git email: $(git config --get user.email)"
3436

35-
3637
echo "Running cz: $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE"
3738

38-
if [ $INPUT_CHANGELOG_INCREMENT_FILENAME ];
39-
then
40-
cz bump --yes --changelog-to-stdout $INPUT_COMMIT $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE > $INPUT_CHANGELOG_INCREMENT_FILENAME;
39+
if [ $INPUT_CHANGELOG_INCREMENT_FILENAME ]; then
40+
cz bump --yes --changelog-to-stdout $INPUT_COMMIT $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE >$INPUT_CHANGELOG_INCREMENT_FILENAME
4141
else
42-
cz bump --yes $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE;
42+
cz bump --yes $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE
4343
fi
4444

45-
export REV=`cz version --project`
46-
echo "REVISION=$REV" >> $GITHUB_ENV
45+
REV=$(cz version --project)
46+
export REV
47+
48+
echo "REVISION=$REV" >>$GITHUB_ENV
4749

4850
echo "::set-output name=version::$REV"
4951

50-
if [ "$INPUT_PUSH" == "true" ];
51-
then
52+
if [ "$INPUT_PUSH" == "true" ]; then
5253
echo "Pushing to branch..."
5354
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
5455
git pull ${remote_repo} ${INPUT_BRANCH}
55-
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags --tags;
56+
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags --tags
5657
else
5758
echo "Not pushing"
5859
fi

0 commit comments

Comments
 (0)
Please sign in to comment.