Skip to content

Commit 21ee06a

Browse files
Merge pull request #58 from step-security/auto-cherry-pick
chore: Cherry-picked changes from upstream
2 parents 9683c10 + 06daf79 commit 21ee06a

File tree

5 files changed

+549
-169
lines changed

5 files changed

+549
-169
lines changed

README.md

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Adding git-auto-commit to your Workflow only takes a couple lines of code.
1616
2. Add the following step at the end of your job, after other steps that might add or change files.
1717

1818
```yaml
19-
- uses: step-security/git-auto-commit-action@v5
19+
- uses: step-security/git-auto-commit-action@v7
2020
```
2121
2222
Your Workflow should look similar to this example.
@@ -36,15 +36,15 @@ jobs:
3636
contents: write
3737

3838
steps:
39-
- uses: actions/checkout@v4
39+
- uses: actions/checkout@v5
4040
with:
4141
ref: ${{ github.head_ref }}
4242

4343
# Other steps that change files in the repository go here
4444
#
4545

4646
# Commit all changed files back to the repository
47-
- uses: step-security/git-auto-commit-action@v5
47+
- uses: step-security/git-auto-commit-action@v7
4848
```
4949
5050
> [!NOTE]
@@ -53,7 +53,7 @@ jobs:
5353
The following is an extended example with all available options.
5454

5555
```yaml
56-
- uses: step-security/git-auto-commit-action@v5
56+
- uses: step-security/git-auto-commit-action@v7
5757
with:
5858
# Optional. Commit message for the created commit.
5959
# Defaults to "Apply automatic changes"
@@ -82,10 +82,15 @@ The following is an extended example with all available options.
8282
commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]"
8383
commit_user_email: [email protected] # defaults to "41898282+github-actions[bot]@users.noreply.github.com"
8484
commit_author: Author <[email protected]> # defaults to "username <[email protected]>", where "numeric_id" and "username" belong to the author of the commit that triggered the run
85+
86+
# Optional. Tag name to be created in the local repository and
87+
# pushed to the remote repository on the defined branch.
88+
# If only one of `tag_name` or `tagging_message` is provided, the value of the provided field will be used for both tag name and message.
89+
tag_name: 'v1.0.0'
8590

86-
# Optional. Tag name being created in the local repository and
87-
# pushed to remote repository and defined branch.
88-
tagging_message: 'v1.0.0'
91+
# Optional. Message to annotate the created tag with.
92+
# If only one of `tag_name` or `tagging_message` is provided, the value of the provided field will be used for both tag name and message.
93+
tagging_message: 'Codename "Sunshine"'
8994

9095
# Optional. Option used by `git-status` to determine if the repository is
9196
# dirty. See https://git-scm.com/docs/git-status#_options
@@ -102,12 +107,21 @@ The following is an extended example with all available options.
102107
# Optional. Disable dirty check and always try to create a commit and push
103108
skip_dirty_check: true
104109

110+
# Optional. Skip internal call to `git fetch`
111+
skip_fetch: true
112+
113+
# Optional. Skip internal call to `git checkout`
114+
skip_checkout: true
115+
105116
# Optional. Prevents the shell from expanding filenames.
106117
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
107118
disable_globbing: true
108119

120+
# Optional. Create given branch name in local and remote repository.
121+
create_branch: true
122+
109123
# Optional. Creates a new tag and pushes it to remote without creating a commit.
110-
# Skips dirty check and changed files. Must be used with `tagging_message`.
124+
# Skips dirty check and changed files. Must be used in combination with `tag` and `tagging_message`.
111125
create_git_tag_only: false
112126
```
113127
@@ -138,14 +152,14 @@ jobs:
138152
contents: write
139153
140154
steps:
141-
- uses: actions/checkout@v4
155+
- uses: actions/checkout@v5
142156
with:
143157
ref: ${{ github.head_ref }}
144158
145159
- name: Run php-cs-fixer
146160
uses: docker://oskarstark/php-cs-fixer-ga
147161
148-
- uses: step-security/git-auto-commit-action@v5
162+
- uses: step-security/git-auto-commit-action@v7
149163
with:
150164
commit_message: Apply php-cs-fixer changes
151165
```
@@ -167,7 +181,7 @@ You can use these outputs to trigger other Actions in your Workflow run based on
167181
### Example
168182

169183
```yaml
170-
- uses: step-security/git-auto-commit-action@v5
184+
- uses: step-security/git-auto-commit-action@v7
171185
id: auto-commit-action #mandatory for the output to show up in ${{ steps }}
172186
with:
173187
commit_message: Apply php-cs-fixer changes
@@ -203,7 +217,7 @@ You must use `action/checkout@v2` or later versions to check out the repository.
203217
In non-`push` events, such as `pull_request`, make sure to specify the `ref` to check out:
204218

205219
```yaml
206-
- uses: actions/checkout@v4
220+
- uses: actions/checkout@v5
207221
with:
208222
ref: ${{ github.head_ref }}
209223
```
@@ -221,7 +235,7 @@ You can change this by creating a new [Personal Access Token (PAT)](https://gith
221235
storing the token as a secret in your repository and then passing the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
222236

223237
```yaml
224-
- uses: actions/checkout@v4
238+
- uses: actions/checkout@v5
225239
with:
226240
token: ${{ secrets.PAT }}
227241
```
@@ -267,7 +281,7 @@ The example below can be used as a starting point to generate a multiline commit
267281
# Quick and dirty step to get rid of the temporary file holding the commit message
268282
- run: rm -rf commitmessage.txt
269283
270-
- uses: step-security/git-auto-commit-action@v5
284+
- uses: step-security/git-auto-commit-action@v7
271285
id: commit
272286
with:
273287
commit_message: ${{ steps.commit_message_step.outputs.commit_message }}
@@ -291,7 +305,7 @@ As git-auto-commit by default does not use **your** username and email when crea
291305
git_commit_gpgsign: true
292306
293307
- name: "Commit and push changes"
294-
uses: step-security/git-auto-commit-action@v5
308+
uses: step-security/git-auto-commit-action@v7
295309
with:
296310
commit_author: "${{ steps.import-gpg.outputs.name }} <${{ steps.import-gpg.outputs.email }}>"
297311
commit_user_name: ${{ steps.import-gpg.outputs.name }}
@@ -351,7 +365,7 @@ jobs:
351365
contents: write
352366
353367
steps:
354-
- uses: actions/checkout@v4
368+
- uses: actions/checkout@v5
355369
with:
356370
# Checkout the fork/head-repository and push changes to the fork.
357371
# If you skip this, the base repository will be checked out and changes
@@ -365,7 +379,7 @@ jobs:
365379
- name: Run php-cs-fixer
366380
uses: docker://oskarstark/php-cs-fixer-ga
367381
368-
- uses: step-security/git-auto-commit-action@v5
382+
- uses: step-security/git-auto-commit-action@v7
369383
```
370384

371385
For more information about running Actions on forks, see [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/).
@@ -400,12 +414,13 @@ The steps in your workflow might look like this:
400414
echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
401415
echo "author=$(git log -1 --pretty=\"%an <%ae>\")" >> $GITHUB_OUTPUT
402416
403-
- uses: step-security/git-auto-commit-action@v5
417+
- uses: step-security/git-auto-commit-action@v7
404418
with:
405419
commit_author: ${{ steps.last-commit.outputs.author }}
406420
commit_message: ${{ steps.last-commit.outputs.message }}
407421
commit_options: '--amend --no-edit'
408422
push_options: '--force'
423+
skip_fetch: true
409424
```
410425
411426
@@ -439,7 +454,7 @@ If you create a personal access token (classic), apply the `repo` and `workflow`
439454
If you create a fine-grained personal access token, apply the `Contents`-permissions.
440455
441456
```yaml
442-
- uses: actions/checkout@v4
457+
- uses: actions/checkout@v5
443458
with:
444459
# We pass the "PAT" secret to the checkout action; if no PAT secret is available to the workflow runner (eg. Dependabot) we fall back to the default "GITHUB_TOKEN".
445460
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
@@ -453,7 +468,7 @@ You can learn more about Personal Access Token in the [GitHub documentation](htt
453468
If you go the "force pushes" route, you have to enable force pushes to a protected branch (see [documentation](https://help.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)) and update your Workflow to use force push like this.
454469
455470
```yaml
456-
- uses: step-security/git-auto-commit-action@v5
471+
- uses: step-security/git-auto-commit-action@v7
457472
with:
458473
commit_message: Apply php-cs-fixer changes
459474
push_options: --force
@@ -482,7 +497,7 @@ This is due to the fact, that the `*.md`-glob is expanded before sending it to `
482497
To fix this add `disable_globbing: true` to your Workflow.
483498
484499
```yaml
485-
- uses: step-security/git-auto-commit-action@v5
500+
- uses: step-security/git-auto-commit-action@v7
486501
with:
487502
file_pattern: '*.md'
488503
disable_globbing: true
@@ -509,7 +524,7 @@ yarn test
509524
510525
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/step-security/git-auto-commit-action/tags).
511526
512-
We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use `step-security/git-auto-commit-action@v5` to always use the latest release of the current major version.
527+
We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use `step-security/git-auto-commit-action@v7` to always use the latest release of the current major version.
513528
(More information about this [here](https://help.github.com/en/actions/building-actions/about-actions#versioning-your-action).)
514529
515530

action.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ inputs:
4444
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
4545
required: false
4646
default: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
47+
tag_name:
48+
description: Tag name used for creating a new git tag with the commit. Keep this empty, if no tag should be created.
49+
required: false
50+
default: ''
4751
tagging_message:
48-
description: Message used to create a new git tag with the commit. Keep this empty, if no tag should be created.
52+
description: Tagging message used for creating a new git tag with the commit. Keep this empty, if no tag should be created.
4953
required: false
5054
default: ''
5155
push_options:
@@ -56,27 +60,27 @@ inputs:
5660
description: Skip the check if the git repository is dirty and always try to create a commit.
5761
required: false
5862
default: false
63+
skip_fetch:
64+
description: Skip the call to git-fetch.
65+
required: false
66+
default: false
67+
skip_checkout:
68+
description: Skip the call to git-checkout.
69+
required: false
70+
default: false
5971
disable_globbing:
6072
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
6173
default: false
74+
create_branch:
75+
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
76+
default: false
6277
create_git_tag_only:
6378
description: Perform a clean git tag and push, without commiting anything
6479
required: false
6580
default: false
6681
internal_git_binary:
6782
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
6883
default: git
69-
skip_fetch:
70-
description: "Deprecated: skip_fetch has been removed in v6. It does not have any effect anymore."
71-
required: false
72-
default: false
73-
skip_checkout:
74-
description: "Deprecated: skip_checkout has been removed in v6. It does not have any effect anymore."
75-
required: false
76-
default: false
77-
create_branch:
78-
description: "Deprecated: create_branch has been removed in v6. It does not have any effect anymore."
79-
default: false
8084

8185

8286
outputs:
@@ -88,7 +92,7 @@ outputs:
8892
description: Value is "true", if a git tag was created using the `create_git_tag_only`-input.
8993

9094
runs:
91-
using: 'node20'
95+
using: 'node24'
9296
main: 'dist/index.js'
9397

9498
branding:

dist/entrypoint.sh

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,13 @@ _log() {
2727
}
2828

2929
_main() {
30-
if "$INPUT_SKIP_FETCH"; then
31-
_log "warning" "git-auto-commit: skip_fetch has been removed in v6. It does not have any effect anymore.";
32-
fi
33-
34-
if "$INPUT_SKIP_CHECKOUT"; then
35-
_log "warning" "git-auto-commit: skip_checkout has been removed in v6. It does not have any effect anymore.";
36-
fi
37-
38-
if "$INPUT_CREATE_BRANCH"; then
39-
_log "warning" "git-auto-commit: create_branch has been removed in v6. It does not have any effect anymore.";
40-
fi
41-
4230
_check_if_git_is_available
4331

4432
_switch_to_repository
4533

4634
_check_if_is_git_repository
4735

48-
# _check_if_repository_is_in_detached_state
36+
_check_if_repository_is_in_detached_state
4937

5038
if "$INPUT_CREATE_GIT_TAG_ONLY"; then
5139
_log "debug" "Create git tag only";
@@ -56,6 +44,8 @@ _main() {
5644

5745
_set_github_output "changes_detected" "true"
5846

47+
_switch_to_branch
48+
5949
_add_files
6050

6151
# Check dirty state of repo again using git-diff.
@@ -120,13 +110,40 @@ _check_if_is_git_repository() {
120110
_check_if_repository_is_in_detached_state() {
121111
if [ -z "$(git symbolic-ref HEAD)" ]
122112
then
123-
_log "error" "Repository is in detached HEAD state. Please make sure you check out a branch. Adjust the `ref` input accordingly.";
124-
exit 1;
113+
_log "warning" "Repository is in a detached HEAD state. git-auto-commit will likely handle this automatically. To avoid it, check out a branch using the ref option in actions/checkout.";
125114
else
126115
_log "debug" "Repository is on a branch.";
127116
fi
128117
}
129118
119+
_switch_to_branch() {
120+
echo "INPUT_BRANCH value: $INPUT_BRANCH";
121+
122+
# Fetch remote to make sure that repo can be switched to the right branch.
123+
if "$INPUT_SKIP_FETCH"; then
124+
_log "debug" "git-fetch will not be executed.";
125+
else
126+
_log "debug" "git-fetch will be executed.";
127+
git fetch --depth=1;
128+
fi
129+
130+
# If `skip_checkout`-input is true, skip the entire checkout step.
131+
if "$INPUT_SKIP_CHECKOUT"; then
132+
_log "debug" "git-checkout will not be executed.";
133+
else
134+
_log "debug" "git-checkout will be executed.";
135+
# Create new local branch if `create_branch`-input is true
136+
if "$INPUT_CREATE_BRANCH"; then
137+
# shellcheck disable=SC2086
138+
git checkout -B $INPUT_BRANCH --;
139+
else
140+
# Switch to branch from current Workflow run
141+
# shellcheck disable=SC2086
142+
git checkout $INPUT_BRANCH --;
143+
fi
144+
fi
145+
}
146+
130147
_add_files() {
131148
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
132149
_log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";
@@ -159,14 +176,17 @@ _local_commit() {
159176
}
160177
161178
_tag_commit() {
179+
echo "INPUT_TAG_NAME: ${INPUT_TAG_NAME}"
162180
echo "INPUT_TAGGING_MESSAGE: ${INPUT_TAGGING_MESSAGE}"
163181
164-
if [ -n "$INPUT_TAGGING_MESSAGE" ]
165-
then
166-
_log "debug" "Create tag $INPUT_TAGGING_MESSAGE";
167-
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE";
182+
if [ -n "$INPUT_TAG_NAME" ] || [ -n "$INPUT_TAGGING_MESSAGE" ]; then
183+
INTERNAL_TAG=${INPUT_TAG_NAME:-$INPUT_TAGGING_MESSAGE}
184+
INTERNAL_TAGGING_MESSAGE=${INPUT_TAGGING_MESSAGE:-$INPUT_TAG_NAME}
185+
186+
_log "debug" "Create tag $INTERNAL_TAG: $INTERNAL_TAGGING_MESSAGE"
187+
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INTERNAL_TAG" -m "$INTERNAL_TAGGING_MESSAGE"
168188
else
169-
echo "No tagging message supplied. No tag will be added.";
189+
echo "Neither tag nor tag message is set. No tag will be added.";
170190
fi
171191
}
172192
@@ -182,8 +202,8 @@ _push_to_github() {
182202
183203
if [ -z "$INPUT_BRANCH" ]
184204
then
185-
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
186-
if [ -n "$INPUT_TAGGING_MESSAGE" ]
205+
# Only add `--tags` option, if `$INPUT_TAG_NAME` or `$INPUT_TAGGING_MESSAGE` is set
206+
if [ -n "$INPUT_TAG_NAME" ] || [ -n "$INPUT_TAGGING_MESSAGE" ]
187207
then
188208
_log "debug" "git push origin --tags";
189209
git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};

0 commit comments

Comments
 (0)