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: 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..11ef977 100755 --- a/cli.ts +++ b/cli.ts @@ -92,7 +92,19 @@ if (core.getBooleanInput("preprocess")) { } await $`git add -Av`; -await $`git commit --allow-empty -m ${core.getInput("commit_message")}`; +if (core.getBooleanInput("disable_empty_commits")) { + 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")}`; +} if (core.getBooleanInput("dry_run")) { await $`git show`;