From 42e06d23e8da0a017bba84adc79df4fd688bbdd5 Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sat, 7 May 2022 01:38:27 -0700 Subject: [PATCH 1/4] style: Remove trailing whitespace from test_action --- .github/workflows/test_action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_action.yml b/.github/workflows/test_action.yml index b76dc16..42f53a3 100644 --- a/.github/workflows/test_action.yml +++ b/.github/workflows/test_action.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/checkout@v2 with: - ref: ${{github.event.pull_request.head.ref}} + ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} fetch-depth: 0 # ensures that tags are fetched, seems to be needed - name: Capture commit id @@ -34,7 +34,7 @@ jobs: push: false - uses: actions/checkout@v2 with: - ref: ${{github.event.pull_request.head.ref}} + ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} fetch-depth: 0 # ensures that tags are fetched, seems to be needed path: new_head From f796cff66fbb6339e024f582b28aa484bef02c8f Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sat, 7 May 2022 01:58:31 -0700 Subject: [PATCH 2/4] style: Use consistent indentation in bumpversion --- .github/workflows/bumpversion.yaml | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/bumpversion.yaml b/.github/workflows/bumpversion.yaml index 40169cc..c43e2e2 100644 --- a/.github/workflows/bumpversion.yaml +++ b/.github/workflows/bumpversion.yaml @@ -10,19 +10,19 @@ jobs: runs-on: ubuntu-latest name: 'Bump version and create changelog with commitizen' steps: - - name: Check out - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Create bump and changelog - uses: commitizen-tools/commitizen-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - changelog_increment_filename: body.md - - name: Release - uses: softprops/action-gh-release@v1 - with: - body_path: "body.md" - tag_name: ${{ env.REVISION }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Check out + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Create bump and changelog + uses: commitizen-tools/commitizen-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + changelog_increment_filename: body.md + - name: Release + uses: softprops/action-gh-release@v1 + with: + body_path: "body.md" + tag_name: ${{ env.REVISION }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c8bd9bd32e1ec371ebac6d7bcf3eb0f6467d1b88 Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sat, 7 May 2022 01:40:40 -0700 Subject: [PATCH 3/4] docs: Run markdown-table-formatter on README Fix Markdown table column alignment. Refer to https://github.com/nvuillam/markdown-table-formatter. --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c316a26..308ed3c 100644 --- a/README.md +++ b/README.md @@ -64,27 +64,27 @@ jobs: ## Variables -| Name | Description | Default | -| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | -| `github_token` | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}` **required** | - | -| `dry_run` | Run without creating commit, output to stdout | false | -| `repository` | Repository name to push. Default or empty value represents current github repository | current one | -| `branch` | Destination branch to push changes | Same as the one executing the action by default | -| `prerelease` | Set as prerelease {alpha,beta,rc} choose type of prerelease | - | -| `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'` | - | -| `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` | - | -| `git_name` | Name used to configure git (for git operations) | `github-actions[bot]` | -| `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` | -| `push` | Define if the changes should be pushed to the branch. | true | -| `commit` | Define if the changes should be committed to the branch. | true | -| `commitizen_version` | Specify the version to be used by commitizen. Eg: `2.21.0` | latest | -| `changelog` | Create changelog when bumping the version | true | +| Name | Description | Default | +|--------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------| +| `github_token` | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}` **required** | - | +| `dry_run` | Run without creating commit, output to stdout | false | +| `repository` | Repository name to push. Default or empty value represents current github repository | current one | +| `branch` | Destination branch to push changes | Same as the one executing the action by default | +| `prerelease` | Set as prerelease {alpha,beta,rc} choose type of prerelease | - | +| `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'` | - | +| `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` | - | +| `git_name` | Name used to configure git (for git operations) | `github-actions[bot]` | +| `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` | +| `push` | Define if the changes should be pushed to the branch. | true | +| `commit` | Define if the changes should be committed to the branch. | true | +| `commitizen_version` | Specify the version to be used by commitizen. Eg: `2.21.0` | latest | +| `changelog` | Create changelog when bumping the version | true | | `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/) | ## Outputs | Name | Description | -| --------- | --------------- | +|-----------|-----------------| | `version` | The new version | Additionally, the new version is also available as an environment variable under `REVISION`. From 7931f23e45795cd5c521d908a0b391f3eb43900b Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Fri, 6 May 2022 23:46:35 -0700 Subject: [PATCH 4/4] fix: Follow Bash best practices in entrypoint - Simplify command-line construction by building up arrays rather than passing empty strings via unquoted variables. - Prefer [[ ]] to [ ] to prevent globbing and word splitting in tests. - Quote Bash variables elsewhere to prevent globbing and word splitting. - Reorder code to start with set directive, fail fast, and colocate related sections. - Use consistent style recommended by shfmt for if/then/else blocks. - Use UPPER_CASE consistently for variable names. - Use single quotes consistently for string literals. - Use curly braces to delimit variables from surrounding string literals but not in isolation. --- entrypoint.sh | 86 ++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 278bdb3..ea55b49 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,60 +1,70 @@ #!/bin/bash -if [ $INPUT_DRY_RUN ]; then INPUT_DRY_RUN='--dry-run'; else INPUT_DRY_RUN=''; fi -if [ $INPUT_CHANGELOG ]; then INPUT_CHANGELOG='--changelog'; else INPUT_CHANGELOG=''; fi -if [ $INPUT_PRERELEASE ]; then INPUT_PRERELEASE="--prerelease $INPUT_PRERELEASE"; else INPUT_PRERELEASE=''; fi -if [ "$INPUT_COMMIT" == 'false' ]; then INPUT_COMMIT='--files-only'; else INPUT_COMMIT=''; fi -if [ "$INPUT_COMMITIZEN_VERSION" == 'latest' ]; then INPUT_COMMITIZEN_VERSION="commitizen"; else INPUT_COMMITIZEN_VERSION="commitizen==$INPUT_COMMITIZEN_VERSION"; fi -if [ -n "$INPUT_NO_RAISE" ]; then INPUT_NO_RAISE="--no-raise $INPUT_NO_RAISE"; else INPUT_NO_RAISE=''; fi - -CURRENT_BRANCH="$(git branch --show-current)" -INPUT_BRANCH=${INPUT_BRANCH:-$CURRENT_BRANCH} -INPUT_EXTRA_REQUIREMENTS=${INPUT_EXTRA_REQUIREMENTS:-''} -REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY} -# : "${INPUT_CHANGELOG:=true}" ignored for now, let's check that it works - set -e -[ -z "${INPUT_GITHUB_TOKEN}" ] && { +if [[ -z $INPUT_GITHUB_TOKEN ]]; then echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".' exit 1 -} - -echo "Repository: $REPOSITORY" -echo "Actor: $GITHUB_ACTOR" - -echo "Installing requirements..." -pip install "$INPUT_COMMITIZEN_VERSION" $INPUT_EXTRA_REQUIREMENTS -echo "Commitizen version:" -cz version +fi echo "Configuring Git username, email, and pull behavior..." -git config --local user.name "$INPUT_GIT_NAME" -git config --local user.email "$INPUT_GIT_EMAIL" +git config --local user.name "${INPUT_GIT_NAME}" +git config --local user.email "${INPUT_GIT_EMAIL}" git config --local pull.rebase true echo "Git name: $(git config --get user.name)" echo "Git email: $(git config --get user.email)" -echo "Running cz: $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE" - -if [ $INPUT_CHANGELOG_INCREMENT_FILENAME ]; then - cz $INPUT_NO_RAISE bump --yes --changelog-to-stdout $INPUT_COMMIT $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE >$INPUT_CHANGELOG_INCREMENT_FILENAME +PIP_CMD=('pip' 'install') +if [[ $INPUT_COMMITIZEN_VERSION == 'latest' ]]; then + PIP_CMD+=('commitizen') else - cz $INPUT_NO_RAISE bump --yes $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE + PIP_CMD+=("commitizen==${INPUT_COMMITIZEN_VERSION}") fi +IFS=" " read -r -a INPUT_EXTRA_REQUIREMENTS <<<"$INPUT_EXTRA_REQUIREMENTS" +PIP_CMD+=("${INPUT_EXTRA_REQUIREMENTS[@]}") +echo "${PIP_CMD[@]}" +"${PIP_CMD[@]}" +echo "Commitizen version: $(cz version)" -REV=$(cz version --project) -export REV +CZ_CMD=('cz') +if [[ $INPUT_NO_RAISE ]]; then + CZ_CMD+=('--no-raise' "$INPUT_NO_RAISE") +fi +CZ_CMD+=('bump' '--yes') +if [[ $INPUT_DRY_RUN == 'true' ]]; then + CZ_CMD+=('--dry-run') +fi +if [[ $INPUT_CHANGELOG == 'true' ]]; then + CZ_CMD+=('--changelog') +fi +if [[ $INPUT_PRERELEASE ]]; then + CZ_CMD+=('--prerelease' "$INPUT_PRERELEASE") +fi +if [[ $INPUT_COMMIT == 'false' ]]; then + CZ_CMD+=('--files-only') +fi +if [[ $INPUT_CHANGELOG_INCREMENT_FILENAME ]]; then + CZ_CMD+=('--changelog-to-stdout' ">$INPUT_CHANGELOG_INCREMENT_FILENAME") +fi +echo "${CZ_CMD[@]}" +"${CZ_CMD[@]}" + +REV="$(cz version --project)" +echo "REVISION=${REV}" >>"$GITHUB_ENV" +echo "::set-output name=version::${REV}" -echo "REVISION=$REV" >>$GITHUB_ENV +CURRENT_BRANCH="$(git branch --show-current)" +INPUT_BRANCH="${INPUT_BRANCH:-$CURRENT_BRANCH}" +INPUT_REPOSITORY="${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}" -echo "::set-output name=version::$REV" +echo "Repository: ${INPUT_REPOSITORY}" +echo "Actor: ${GITHUB_ACTOR}" -if [ "$INPUT_PUSH" == "true" ]; then +if [[ $INPUT_PUSH == 'true' ]]; then echo "Pushing to branch..." - remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git" - git pull ${remote_repo} ${INPUT_BRANCH} - git push "${remote_repo}" HEAD:${INPUT_BRANCH} --tags + REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git" + git pull "$REMOTE_REPO" "$INPUT_BRANCH" + git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags else echo "Not pushing" fi