Skip to content

Commit 04bf3da

Browse files
authored
Commit changes by default (#1)
* Commit changes by default * Fix predicate * Add logs * Fix predicate and logs * Move no-commit logs to debug * Update README.md
1 parent a966d37 commit 04bf3da

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ jobs:
2020
fetch-depth: 0
2121
- name: Run yor action
2222
uses: bridgecrewio/yor-action@main
23-
- name: Commit tag changes
24-
uses: stefanzweifel/git-auto-commit-action@v4
2523
```
2624
2725
Note that this example uses the latest version (`main`).
@@ -47,8 +45,6 @@ jobs:
4745
tag_groups: git,code2cloud
4846
custom_tags: path/to/plugin.so
4947
output_format: json
50-
- name: Commit tag changes
51-
uses: stefanzweifel/git-auto-commit-action@v4
5248
```
5349

5450
#### Using skip_tags + tag_groups Parameters
@@ -74,3 +70,18 @@ jobs:
7470
- name: Commit tag changes
7571
uses: stefanzweifel/git-auto-commit-action@v4
7672
```
73+
#### Committing at your own timing instead of right after the tags were updated:
74+
```yaml
75+
jobs:
76+
yor-job:
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Checkout repo
80+
uses: actions/checkout@v2
81+
with:
82+
fetch-depth: 0
83+
- name: Run yor action
84+
uses: bridgecrewio/yor-action@main
85+
with:
86+
commit_changes: NO # Any value which is not YES (which is the default value) will lead to no commit
87+
```

action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
log_level:
2727
description: 'log level'
2828
required: false
29+
commit_changes:
30+
description: 'Choose whether the action will commit changes. Changes will be commited if this is exactly "YES"'
31+
default: YES
32+
required: false
2933

3034
branding:
3135
icon: 'shield'

entrypoint.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,26 @@ echo "running yor on directory: $INPUT_DIRECTORY"
1616
/go/yor/yor tag -d "$INPUT_DIRECTORY" "$TAG_FLAG" "$TAG_GROUPS" "$SKIP_TAG_FLAG" "$SKIP_DIR_FLAG" "$EXT_TAGS_FLAG" "$OUTPUT_FLAG"
1717
rm -rf .yor_plugins
1818
YOR_EXIT_CODE=$?
19-
exit $YOR_EXIT_CODE
19+
20+
_git_is_dirty() {
21+
[ -n "$(git status -s --untracked-files=no)" ]
22+
}
23+
24+
if [[ $YOR_EXIT_CODE -eq 0 && $INPUT_COMMIT_CHANGES == "YES" ]]
25+
then
26+
if _git_is_dirty
27+
then
28+
echo "Yor made changes, committing"
29+
git add .
30+
git -c user.name=actions@github.com -c user.email="GitHub Actions" \
31+
commit -m "Update tags (by Yor)" \
32+
--author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" ;
33+
echo "Changes committed, pushing..."
34+
git push origin
35+
fi
36+
else
37+
echo "::debug::exiting, yor failed or commit is skipped"
38+
echo "::debug::yor exit code: $YOR_EXIT_CODE"
39+
echo "::debug::commit_changes: $INPUT_COMMIT_CHANGES"
40+
exit $YOR_EXIT_CODE
41+
fi

0 commit comments

Comments
 (0)