Skip to content

Commit 7ee32e8

Browse files
authored
Add "disable-empty-commits" option (#81)
Fixes #80. --------- Co-authored-by: jrfnl <[email protected]>
1 parent b7e552d commit 7ee32e8

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

.github/workflows/test-action.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ jobs:
4747
with:
4848
strategy: init
4949
dry-run: true
50+
test-action-clone-dry-run-no-empty:
51+
# Expects no commit (unless the wiki test files are changed).
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
os: [ubuntu-latest, windows-latest, macos-latest]
56+
runs-on: ${{ matrix.os }}
57+
steps:
58+
- uses: actions/checkout@v3
59+
- uses: ./
60+
with:
61+
strategy: clone
62+
dry-run: true
63+
disable-empty-commits: true
64+
test-action-init-dry-run-no-empty:
65+
# Expects a commit either way as the init strategy creates an orphan branch.
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
os: [ubuntu-latest, windows-latest, macos-latest]
70+
runs-on: ${{ matrix.os }}
71+
steps:
72+
- uses: actions/checkout@v3
73+
- uses: ./
74+
with:
75+
strategy: init
76+
dry-run: true
77+
disable-empty-commits: true
5078
test-action-real:
5179
concurrency: ${{ github.workflow }}-real
5280
permissions:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ is specific to GitHub wikis.
116116
links. This helps ensure that the Markdown works in source control as well as
117117
the wiki. The default is true.
118118

119+
- **`disable-empty-commits`:** By default, any triggering of this action will
120+
result in a commit to the Wiki, even if that commit is empty.
121+
If this option is true, a workflow run which would result in no changes
122+
to the Wiki files, will no longer create an empty commit. The default is false.
123+
119124
#### `strategy:` input
120125

121126
There are some specific usecases where using `strategy: init` might be better

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ inputs:
7171
default is true.
7272
required: true
7373
default: true
74+
disable-empty-commits:
75+
description: >-
76+
By default, any triggering of this action will result in a commit to the
77+
Wiki, even if that commit is empty. If this option is true, a workflow
78+
run which would result in no changes to the Wiki files, will no longer
79+
create an empty commit. The default is false.
80+
required: false
81+
default: false
7482
outputs:
7583
wiki_url:
7684
description: >-
@@ -94,3 +102,4 @@ runs:
94102
INPUT_IGNORE: ${{ inputs.ignore }}
95103
INPUT_DRY_RUN: ${{ inputs.dry-run }}
96104
INPUT_PREPROCESS: ${{ inputs.preprocess }}
105+
INPUT_DISABLE_EMPTY_COMMITS: ${{ inputs.disable-empty-commits }}

cli.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,19 @@ if (core.getBooleanInput("preprocess")) {
9292
}
9393

9494
await $`git add -Av`;
95-
await $`git commit --allow-empty -m ${core.getInput("commit_message")}`;
95+
if (core.getBooleanInput("disable_empty_commits")) {
96+
try {
97+
await $`git commit -m ${core.getInput("commit_message")}`;
98+
} catch (e) {
99+
if (e.exitCode === 1 && e.stderr.includes("nothing to commit")) {
100+
console.log("nothing to commit, working tree clean");
101+
} else {
102+
throw e; // Unexpected error
103+
}
104+
}
105+
} else {
106+
await $`git commit --allow-empty -m ${core.getInput("commit_message")}`;
107+
}
96108

97109
if (core.getBooleanInput("dry_run")) {
98110
await $`git show`;

0 commit comments

Comments
 (0)