Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add allow-empty option to enable empty commits when no file changes…
… detected
  • Loading branch information
vincent-joignie-dd committed Sep 16, 2025
commit 50745aca92f27d9f5c60dce5bbcef7e4cd1e7264
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ out
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.idea/
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ jobs:
tag: v1.0.3
```

```yaml
jobs:
<job-id>:
permissions:
contents: write # grant secrets.GITHUB_TOKEN permission to push file changes

- name: Create empty commit
uses: ryancyq/github-signed-commit@v1
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commit-message: Trigger rebuild
allow-empty: true
```

Note: The `GH_TOKEN` environment variable is **required** for GitHub API request authentication.

## Inputs
Expand All @@ -67,6 +82,7 @@ Note: The `GH_TOKEN` environment variable is **required** for GitHub API request
| `branch-push-force` | **NO** | `--force` flag when running `git push <branch-name>`. |
| `tag` | **NO** | Push tag for the new/current commit. |
| `tag-only-if-file-changes` | **NO** | Push tag for new commit only when file changes present. **DEFAULT:** true |
| `allow-empty` | **NO** | Allow creating commits even when no file changes are detected. **DEFAULT:** false |

## Outputs
| Output | Description |
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ inputs:
Push tag for new commit only when file changes present.
required: false
default: true
allow-empty:
description: |
Allow creating commits even when no file changes are detected.
required: false
default: false

outputs:
commit-sha:
Expand Down
31 changes: 29 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30511,10 +30511,37 @@ function run() {
core.info(`detected ${fileCount.toString()} file changes`);
core.debug(`detect file changes: ${JSON.stringify(fileChanges)}`);
if (fileCount <= 0) {
const allowEmpty = core.getBooleanInput('allow-empty');
const skipTagCommit = core.getBooleanInput('tag-only-if-file-changes');
if (skipTagCommit)
if (!allowEmpty && skipTagCommit)
throw new errors_1.NoFileChanges();
core.notice(new errors_1.NoFileChanges().message);
if (allowEmpty) {
core.notice('No file changes detected, but proceeding with empty commit due to allow-empty option');
// Create empty commit
const commitMessage = core.getInput('commit-message', {
required: true,
});
core.debug(`commit message: ${commitMessage}`);
const createResponse = yield core.group('committing empty commit', () => __awaiter(this, void 0, void 0, function* () {
const startTime = Date.now();
const commitData = yield (0, graphql_1.createCommitOnBranch)(currentCommit, commitMessage, {
repositoryNameWithOwner: repository.nameWithOwner,
branchName: selectedBranch,
}, { additions: [], deletions: [] } // Empty file changes
);
const endTime = Date.now();
core.debug(`time taken: ${(endTime - startTime).toString()} ms`);
return commitData;
}));
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
createdCommit = createResponse.commit;
const commitSha = createdCommit.oid;
core.info(`committed empty commit with ${commitSha}`);
core.setOutput('commit-sha', commitSha);
}
else {
core.notice(new errors_1.NoFileChanges().message);
}
}
else {
const commitMessage = core.getInput('commit-message', {
Expand Down
39 changes: 37 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,44 @@ export async function run(): Promise<void> {
core.debug(`detect file changes: ${JSON.stringify(fileChanges)}`)

if (fileCount <= 0) {
const allowEmpty = core.getBooleanInput('allow-empty')
const skipTagCommit = core.getBooleanInput('tag-only-if-file-changes')
if (skipTagCommit) throw new NoFileChanges()
core.notice(new NoFileChanges().message)

if (!allowEmpty && skipTagCommit) throw new NoFileChanges()

if (allowEmpty) {
core.notice('No file changes detected, but proceeding with empty commit due to allow-empty option')
// Create empty commit
const commitMessage = core.getInput('commit-message', {
required: true,
})
core.debug(`commit message: ${commitMessage}`)
const createResponse = await core.group(
'committing empty commit',
async () => {
const startTime = Date.now()
const commitData = await createCommitOnBranch(
currentCommit,
commitMessage,
{
repositoryNameWithOwner: repository.nameWithOwner,
branchName: selectedBranch,
},
{ additions: [], deletions: [] } // Empty file changes
)
const endTime = Date.now()
core.debug(`time taken: ${(endTime - startTime).toString()} ms`)
return commitData
}
)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
createdCommit = createResponse.commit!
const commitSha = createdCommit.oid as string
core.info(`committed empty commit with ${commitSha}`)
core.setOutput('commit-sha', commitSha)
} else {
core.notice(new NoFileChanges().message)
}
} else {
const commitMessage = core.getInput('commit-message', {
required: true,
Expand Down
Loading