Skip to content

Commit fdd3ff7

Browse files
committed
feat: add commit and push inputs
test: add test for `push` and `commit` inputs fix: test action commit failing fix: bash condtion fix: tag not found on test test: add echo for debugging to workflow fix: wrong test condition fix: missing log for new option fix: bash scripting syntax fix: commit input being inverted
1 parent 23b84fa commit fdd3ff7

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

.github/workflows/test_action.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
pull_request:
3+
types:
4+
- opened
5+
- synchronize
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
with:
13+
fetch-depth: 0 # ensures that tags are fetched, seems to be needed
14+
ref: ${{github.head_ref}}
15+
- name: Capture commit id
16+
id: capture
17+
run: |
18+
COMMIT_ID=$(git rev-parse HEAD)
19+
echo "The sha of the starting commit is $COMMIT_ID"
20+
echo "::set-output name=commit::$COMMIT_ID"
21+
- name: create test commit
22+
run: |
23+
touch test_file
24+
git config --global user.email "you@example.com"
25+
git config --global user.name "Your Name"
26+
git add test_file
27+
git commit -m "feat: test feature"
28+
- name: test action
29+
uses: ./
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}
32+
commit: false
33+
push: false
34+
- name: Test push
35+
run: |
36+
last_pushed_commit=$(git rev-parse origin/${{ github.head_ref }})
37+
echo "Commit sha on origin : $last_pushed_commit"
38+
if [[ $last_pushed_commit != ${{steps.capture.outputs.commit}} ]]; then
39+
echo "Something got pushed to ${{ github.head_ref }}"
40+
exit 1
41+
fi
42+
- name: Test commit
43+
run: |
44+
commit_message=$(git log -1 HEAD --pretty=format:%s)
45+
echo "Latest commit: $commit_message"
46+
if [[ $commit_message != "feat: test feature" ]]; then
47+
echo "The latest commit message is not 'feat: test feature'"
48+
exit 1
49+
fi

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ jobs:
7575
| `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` | - |
7676
| `git_name` | Name used to configure git (for git operations) | `github-actions[bot]` |
7777
| `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` |
78-
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 |
7980
<!-- | `changelog` | Create changelog when bumping the version | true | -->
8081

8182
## Outputs

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ inputs:
1313
dry_run:
1414
description: 'Run without creating commit, output to stdout'
1515
required: false
16+
commit:
17+
description: 'If true a commit is created containing the bump changes'
18+
required: false
19+
default: "true"
20+
push:
21+
description: 'If true the bump commit is pushed to the remote repository'
22+
required: false
23+
default: "true"
1624
prerelease:
1725
description: 'Set as prerelease version'
1826
required: false
@@ -45,4 +53,4 @@ inputs:
4553
git_email:
4654
description: 'Email address used to configure git (for git operations)'
4755
required: false
48-
default: 'github-actions[bot]@users.noreply.github.com'
56+
default: 'github-actions[bot]@users.noreply.github.com'

entrypoint.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
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
6+
if [ $INPUT_COMMIT ]; then INPUT_COMMIT='--files-only'; else INPUT_COMMIT=''; fi
67
INPUT_BRANCH=${INPUT_BRANCH:-master}
78
INPUT_EXTRA_REQUIREMENTS=${INPUT_EXTRA_REQUIREMENTS:-''}
89
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
@@ -31,23 +32,27 @@ echo "Git name: $(git config --get user.name)"
3132
echo "Git email: $(git config --get user.email)"
3233

3334

34-
echo "Running cz: $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE"
35+
echo "Running cz: $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE"
3536

3637
if [ $INPUT_CHANGELOG_INCREMENT_FILENAME ];
3738
then
38-
cz bump --yes --changelog-to-stdout $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE > $INPUT_CHANGELOG_INCREMENT_FILENAME;
39+
cz bump --yes --changelog-to-stdout $INPUT_COMMIT $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE > $INPUT_CHANGELOG_INCREMENT_FILENAME;
3940
else
40-
cz bump --yes $INPUT_DRY_RUN $INPUT_CHANGELOG $INPUT_PRERELEASE;
41+
cz bump --yes $INPUT_DRY_RUN $INPUT_COMMIT $INPUT_CHANGELOG $INPUT_PRERELEASE;
4142
fi
4243

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

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

48-
echo "Pushing to branch..."
49-
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
50-
git pull ${remote_repo} ${INPUT_BRANCH}
51-
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags --tags;
52-
49+
if [ "$INPUT_PUSH" == "true" ];
50+
then
51+
echo "Pushing to branch..."
52+
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
53+
git pull ${remote_repo} ${INPUT_BRANCH}
54+
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags --tags;
55+
else
56+
echo "Not pushing"
57+
fi
5358
echo "Done."

0 commit comments

Comments
 (0)