Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c355ee1

Browse files
authored
Merge pull request #16 from nbrugger-tgm/feat/optional_push
feat: optional `push` and `commit` input
2 parents 23b84fa + cf3dee9 commit c355ee1

File tree

4 files changed

+81
-10
lines changed

4 files changed

+81
-10
lines changed

‎.github/workflows/test_action.yml‎

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

AltStyle によって変換されたページ (->オリジナル) /