Skip to content

feat: optional push and commit input #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/test_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
on:
pull_request:
types:
- opened
- synchronize

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
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
id: capture
run: |
COMMIT_ID=$(git rev-parse ${{ github.head_ref }})
echo "The sha of the starting commit is $COMMIT_ID"
echo "::set-output name=commit::$COMMIT_ID"
- name: create test commit
run: |
touch test_file
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git add test_file
git commit -m "feat: test feature"
- name: test action
uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit: false
push: false
- uses: actions/checkout@v2
with:
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
- name: Test push
run: |
cd new_head
last_pushed_commit=$(git rev-parse ${{ github.head_ref }})
echo "Commit sha on origin : $last_pushed_commit"
if [[ $last_pushed_commit != ${{steps.capture.outputs.commit}} ]]; then
echo "Something got pushed to ${{ github.head_ref }}"
exit 1
fi
- name: Test commit
run: |
commit_message=$(git log -1 HEAD --pretty=format:%s)
echo "Latest commit: $commit_message"
if [[ $commit_message != "feat: test feature" ]]; then
echo "The latest commit message is not 'feat: test feature'"
exit 1
fi
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ jobs:
| `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 |
<!-- | `changelog` | Create changelog when bumping the version | true | -->

## Outputs
Expand Down
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ inputs:
dry_run:
description: 'Run without creating commit, output to stdout'
required: false
commit:
description: 'If true a commit is created containing the bump changes'
required: false
default: "true"
push:
description: 'If true the bump commit is pushed to the remote repository'
required: false
default: "true"
prerelease:
description: 'Set as prerelease version'
required: false
Expand Down Expand Up @@ -45,4 +53,4 @@ inputs:
git_email:
description: 'Email address used to configure git (for git operations)'
required: false
default: 'github-actions[bot]@users.noreply.github.com'
default: 'github-actions[bot]@users.noreply.github.com'
21 changes: 13 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
INPUT_BRANCH=${INPUT_BRANCH:-master}
INPUT_EXTRA_REQUIREMENTS=${INPUT_EXTRA_REQUIREMENTS:-''}
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
Expand Down Expand Up @@ -31,23 +32,27 @@ echo "Git name: $(git config --get user.name)"
echo "Git email: $(git config --get user.email)"


echo "Running cz: $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE"
echo "Running cz: $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE"

if [ $INPUT_CHANGELOG_INCREMENT_FILENAME ];
then
cz bump --yes --changelog-to-stdout $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE > $INPUT_CHANGELOG_INCREMENT_FILENAME;
cz bump --yes --changelog-to-stdout $INPUT_COMMIT $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE > $INPUT_CHANGELOG_INCREMENT_FILENAME;
else
cz bump --yes $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE;
cz bump --yes $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE;
fi

export REV=`cz version --project`
echo "REVISION=$REV" >> $GITHUB_ENV

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

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} --follow-tags --tags;

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} --follow-tags --tags;
else
echo "Not pushing"
fi
echo "Done."