From cb0c245e074820dc25a0e4de7d4aa8108a6ab3f3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 16 Jun 2025 09:08:48 +0200 Subject: [PATCH 1/3] Add "disable-empty-commits" option As discussed in 80. Note: I'm very much not a TS/JS dev, so I hope I've gotten it right ;-) Also wasn't sure how to add tests for this, but hopefully you don't mind guiding me on that ? Feel free to push to my branch. --- README.md | 5 +++++ action.yml | 9 +++++++++ cli.ts | 6 +++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad9a32a..63546f8 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,11 @@ is specific to GitHub wikis. links. This helps ensure that the Markdown works in source control as well as the wiki. The default is true. +- **`disable-empty-commits`:** By default, any triggering of this action will + result in a commit to the Wiki, even if that commit is empty. + If this option is true, a workflow run which would result in no changes + to the Wiki files, will no longer create an empty commit. The default is false. + #### `strategy:` input There are some specific usecases where using `strategy: init` might be better diff --git a/action.yml b/action.yml index b2d0514..008d780 100644 --- a/action.yml +++ b/action.yml @@ -71,6 +71,14 @@ inputs: default is true. required: true default: true + disable-empty-commits: + description: >- + By default, any triggering of this action will result in a commit to the + Wiki, even if that commit is empty. If this option is true, a workflow + run which would result in no changes to the Wiki files, will no longer + create an empty commit. The default is false. + required: false + default: false outputs: wiki_url: description: >- @@ -94,3 +102,4 @@ runs: INPUT_IGNORE: ${{ inputs.ignore }} INPUT_DRY_RUN: ${{ inputs.dry-run }} INPUT_PREPROCESS: ${{ inputs.preprocess }} + INPUT_DISABLE_EMPTY_COMMITS: ${{ inputs.disable-empty-commits }} diff --git a/cli.ts b/cli.ts index f20bc26..1e68c61 100755 --- a/cli.ts +++ b/cli.ts @@ -92,7 +92,11 @@ if (core.getBooleanInput("preprocess")) { } await $`git add -Av`; -await $`git commit --allow-empty -m ${core.getInput("commit_message")}`; +if (core.getBooleanInput("disable_empty_commits")) { + await $`git commit -m ${core.getInput("commit_message")}`; +} else { + await $`git commit --allow-empty -m ${core.getInput("commit_message")}`; +} if (core.getBooleanInput("dry_run")) { await $`git show`; From 99a9e25b3433e63a2a58f6afd6ddd755f4987896 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 17 Jun 2025 17:13:32 +0200 Subject: [PATCH 2/3] GH Actions/test: add test jobs with `disable-empty-commits: true` --- .github/workflows/test-action.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 346eb7c..5f114d3 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -47,6 +47,34 @@ jobs: with: strategy: init dry-run: true + test-action-clone-dry-run-no-empty: + # Expects no commit (unless the wiki test files are changed). + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: ./ + with: + strategy: clone + dry-run: true + disable-empty-commits: true + test-action-init-dry-run-no-empty: + # Expects a commit either way as the init strategy creates an orphan branch. + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: ./ + with: + strategy: init + dry-run: true + disable-empty-commits: true test-action-real: concurrency: ${{ github.workflow }}-real permissions: From 0ad0992c26c0d75e2f0619a59b98de904eb4c138 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 18 Jun 2025 01:44:37 +0200 Subject: [PATCH 3/3] Apply review suggestion - wrap commit in try-catch --- cli.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli.ts b/cli.ts index 1e68c61..11ef977 100755 --- a/cli.ts +++ b/cli.ts @@ -93,7 +93,15 @@ if (core.getBooleanInput("preprocess")) { await $`git add -Av`; if (core.getBooleanInput("disable_empty_commits")) { - await $`git commit -m ${core.getInput("commit_message")}`; + try { + await $`git commit -m ${core.getInput("commit_message")}`; + } catch (e) { + if (e.exitCode === 1 && e.stderr.includes("nothing to commit")) { + console.log("nothing to commit, working tree clean"); + } else { + throw e; // Unexpected error + } + } } else { await $`git commit --allow-empty -m ${core.getInput("commit_message")}`; }