Skip to content

Commit 5d5be47

Browse files
authored
Merge pull request #30 from Kurt-von-Laven/quote-variables
2 parents 4971518 + 7931f23 commit 5d5be47

File tree

4 files changed

+82
-72
lines changed

4 files changed

+82
-72
lines changed

.github/workflows/bumpversion.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ jobs:
1010
runs-on: ubuntu-latest
1111
name: 'Bump version and create changelog with commitizen'
1212
steps:
13-
- name: Check out
14-
uses: actions/checkout@v2
15-
with:
16-
fetch-depth: 0
17-
- name: Create bump and changelog
18-
uses: commitizen-tools/commitizen-action@master
19-
with:
20-
github_token: ${{ secrets.GITHUB_TOKEN }}
21-
changelog_increment_filename: body.md
22-
- name: Release
23-
uses: softprops/action-gh-release@v1
24-
with:
25-
body_path: "body.md"
26-
tag_name: ${{ env.REVISION }}
27-
env:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
- name: Check out
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Create bump and changelog
18+
uses: commitizen-tools/commitizen-action@master
19+
with:
20+
github_token: ${{ secrets.GITHUB_TOKEN }}
21+
changelog_increment_filename: body.md
22+
- name: Release
23+
uses: softprops/action-gh-release@v1
24+
with:
25+
body_path: "body.md"
26+
tag_name: ${{ env.REVISION }}
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test_action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v2
1212
with:
13-
ref: ${{github.event.pull_request.head.ref}}
13+
ref: ${{github.event.pull_request.head.ref}}
1414
repository: ${{github.event.pull_request.head.repo.full_name}}
1515
fetch-depth: 0 # ensures that tags are fetched, seems to be needed
1616
- name: Capture commit id
@@ -34,7 +34,7 @@ jobs:
3434
push: false
3535
- uses: actions/checkout@v2
3636
with:
37-
ref: ${{github.event.pull_request.head.ref}}
37+
ref: ${{github.event.pull_request.head.ref}}
3838
repository: ${{github.event.pull_request.head.repo.full_name}}
3939
fetch-depth: 0 # ensures that tags are fetched, seems to be needed
4040
path: new_head

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ jobs:
6464
6565
## Variables
6666
67-
| Name | Description | Default |
68-
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
69-
| `github_token` | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}` **required** | - |
70-
| `dry_run` | Run without creating commit, output to stdout | false |
71-
| `repository` | Repository name to push. Default or empty value represents current github repository | current one |
72-
| `branch` | Destination branch to push changes | Same as the one executing the action by default |
73-
| `prerelease` | Set as prerelease {alpha,beta,rc} choose type of prerelease | - |
74-
| `extra_requirements` | Custom requirements, if your project uses a custom rule or plugins, you can specify them separated by a space. E.g: `'commitizen-emoji conventional-JIRA'` | - |
75-
| `changelog_increment_filename` | Filename to store the incremented generated changelog. This is different to changelog as it only contains the changes for the just generated version. Example: `body.md` | - |
76-
| `git_name` | Name used to configure git (for git operations) | `github-actions[bot]` |
77-
| `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` |
78-
| `push` | Define if the changes should be pushed to the branch. | true |
79-
| `commit` | Define if the changes should be committed to the branch. | 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 |
67+
| Name | Description | Default |
68+
|--------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
69+
| `github_token` | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}` **required** | - |
70+
| `dry_run` | Run without creating commit, output to stdout | false |
71+
| `repository` | Repository name to push. Default or empty value represents current github repository | current one |
72+
| `branch` | Destination branch to push changes | Same as the one executing the action by default |
73+
| `prerelease` | Set as prerelease {alpha,beta,rc} choose type of prerelease | - |
74+
| `extra_requirements` | Custom requirements, if your project uses a custom rule or plugins, you can specify them separated by a space. E.g: `'commitizen-emoji conventional-JIRA'` | - |
75+
| `changelog_increment_filename` | Filename to store the incremented generated changelog. This is different to changelog as it only contains the changes for the just generated version. Example: `body.md` | - |
76+
| `git_name` | Name used to configure git (for git operations) | `github-actions[bot]` |
77+
| `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` |
78+
| `push` | Define if the changes should be pushed to the branch. | true |
79+
| `commit` | Define if the changes should be committed to the branch. | 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 |
8282
| `no_raise` | Don't raise the given comma-delimited exit codes (e.g., no_raise: '20,21'). Use with caution! Open an issue in [commitizen](https://github.com/commitizen-tools/commitizen/issues) if you need help thinking about your workflow. | [21](https://commitizen-tools.github.io/commitizen/exit_codes/) |
8383

8484
## Outputs
8585

8686
| Name | Description |
87-
| --------- | --------------- |
87+
|-----------|-----------------|
8888
| `version` | The new version |
8989

9090
Additionally, the new version is also available as an environment variable under `REVISION`.

entrypoint.sh

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,70 @@
11
#!/bin/bash
22

3-
if [ $INPUT_DRY_RUN ]; then INPUT_DRY_RUN='--dry-run'; else INPUT_DRY_RUN=''; fi
4-
if [ $INPUT_CHANGELOG ]; then INPUT_CHANGELOG='--changelog'; else INPUT_CHANGELOG=''; fi
5-
if [ $INPUT_PRERELEASE ]; then INPUT_PRERELEASE="--prerelease $INPUT_PRERELEASE"; else INPUT_PRERELEASE=''; fi
6-
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-
if [ -n "$INPUT_NO_RAISE" ]; then INPUT_NO_RAISE="--no-raise $INPUT_NO_RAISE"; else INPUT_NO_RAISE=''; fi
9-
10-
CURRENT_BRANCH="$(git branch --show-current)"
11-
INPUT_BRANCH=${INPUT_BRANCH:-$CURRENT_BRANCH}
12-
INPUT_EXTRA_REQUIREMENTS=${INPUT_EXTRA_REQUIREMENTS:-''}
13-
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
14-
# : "${INPUT_CHANGELOG:=true}" ignored for now, let's check that it works
15-
163
set -e
174

18-
[ -z "${INPUT_GITHUB_TOKEN}" ] && {
5+
if [[ -z $INPUT_GITHUB_TOKEN ]]; then
196
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".'
207
exit 1
21-
}
22-
23-
echo "Repository: $REPOSITORY"
24-
echo "Actor: $GITHUB_ACTOR"
25-
26-
echo "Installing requirements..."
27-
pip install "$INPUT_COMMITIZEN_VERSION" $INPUT_EXTRA_REQUIREMENTS
28-
echo "Commitizen version:"
29-
cz version
8+
fi
309

3110
echo "Configuring Git username, email, and pull behavior..."
32-
git config --local user.name "$INPUT_GIT_NAME"
33-
git config --local user.email "$INPUT_GIT_EMAIL"
11+
git config --local user.name "${INPUT_GIT_NAME}"
12+
git config --local user.email "${INPUT_GIT_EMAIL}"
3413
git config --local pull.rebase true
3514
echo "Git name: $(git config --get user.name)"
3615
echo "Git email: $(git config --get user.email)"
3716

38-
echo "Running cz: $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE"
39-
40-
if [ $INPUT_CHANGELOG_INCREMENT_FILENAME ]; then
41-
cz $INPUT_NO_RAISE bump --yes --changelog-to-stdout $INPUT_COMMIT $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE >$INPUT_CHANGELOG_INCREMENT_FILENAME
17+
PIP_CMD=('pip' 'install')
18+
if [[ $INPUT_COMMITIZEN_VERSION == 'latest' ]]; then
19+
PIP_CMD+=('commitizen')
4220
else
43-
cz $INPUT_NO_RAISE bump --yes $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE
21+
PIP_CMD+=("commitizen==${INPUT_COMMITIZEN_VERSION}")
4422
fi
23+
IFS=" " read -r -a INPUT_EXTRA_REQUIREMENTS <<<"$INPUT_EXTRA_REQUIREMENTS"
24+
PIP_CMD+=("${INPUT_EXTRA_REQUIREMENTS[@]}")
25+
echo "${PIP_CMD[@]}"
26+
"${PIP_CMD[@]}"
27+
echo "Commitizen version: $(cz version)"
4528

46-
REV=$(cz version --project)
47-
export REV
29+
CZ_CMD=('cz')
30+
if [[ $INPUT_NO_RAISE ]]; then
31+
CZ_CMD+=('--no-raise' "$INPUT_NO_RAISE")
32+
fi
33+
CZ_CMD+=('bump' '--yes')
34+
if [[ $INPUT_DRY_RUN == 'true' ]]; then
35+
CZ_CMD+=('--dry-run')
36+
fi
37+
if [[ $INPUT_CHANGELOG == 'true' ]]; then
38+
CZ_CMD+=('--changelog')
39+
fi
40+
if [[ $INPUT_PRERELEASE ]]; then
41+
CZ_CMD+=('--prerelease' "$INPUT_PRERELEASE")
42+
fi
43+
if [[ $INPUT_COMMIT == 'false' ]]; then
44+
CZ_CMD+=('--files-only')
45+
fi
46+
if [[ $INPUT_CHANGELOG_INCREMENT_FILENAME ]]; then
47+
CZ_CMD+=('--changelog-to-stdout' ">$INPUT_CHANGELOG_INCREMENT_FILENAME")
48+
fi
49+
echo "${CZ_CMD[@]}"
50+
"${CZ_CMD[@]}"
51+
52+
REV="$(cz version --project)"
53+
echo "REVISION=${REV}" >>"$GITHUB_ENV"
54+
echo "::set-output name=version::${REV}"
4855

49-
echo "REVISION=$REV" >>$GITHUB_ENV
56+
CURRENT_BRANCH="$(git branch --show-current)"
57+
INPUT_BRANCH="${INPUT_BRANCH:-$CURRENT_BRANCH}"
58+
INPUT_REPOSITORY="${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}"
5059

51-
echo "::set-output name=version::$REV"
60+
echo "Repository: ${INPUT_REPOSITORY}"
61+
echo "Actor: ${GITHUB_ACTOR}"
5262

53-
if [ "$INPUT_PUSH" == "true" ]; then
63+
if [[ $INPUT_PUSH == 'true' ]]; then
5464
echo "Pushing to branch..."
55-
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
56-
git pull ${remote_repo} ${INPUT_BRANCH}
57-
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --tags
65+
REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git"
66+
git pull "$REMOTE_REPO" "$INPUT_BRANCH"
67+
git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags
5868
else
5969
echo "Not pushing"
6070
fi

0 commit comments

Comments
 (0)