Skip to content

Add "disable-empty-commits" option #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jun 16, 2025

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.

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.
@jrfnl jrfnl force-pushed the feature/add-disable-empty-commits-option branch from 5340735 to cb0c245 Compare June 16, 2025 08:27
@jrfnl
Copy link
Contributor Author

jrfnl commented Jun 17, 2025

@Andrew-Chen-Wang Could you please approve the workflow run again ?

@jrfnl
Copy link
Contributor Author

jrfnl commented Jun 17, 2025

Thanks @Andrew-Chen-Wang - looking at the current build failure - that looks to be a permission issue, which I suspect is related to my PR coming from a fork ?

@Andrew-Chen-Wang
Copy link
Owner

No worries on the failed CI; I'm just looking at the CI logs itself. Can you write a unit test that has the disable empty commit option enabled? That way we'll see whether a commit is made or not (the CI should say "Up-to-date" or whatever git says whenever there are no changes)

@jrfnl
Copy link
Contributor Author

jrfnl commented Jun 17, 2025

Can you write a unit test that has the disable empty commit option enabled?

Done - and both cases (should commit and should not commit) should be covered via the tests I've just added.

cli.ts Outdated
@@ -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")}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line is incorrect - the await will never receive anything when no commit is made due to no changes.

As I'm not a JS dev, I'm not sure what to do about this. Guidance welcome.

Copy link
Owner

@Andrew-Chen-Wang Andrew-Chen-Wang Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling this is what the original contributor, jcbhmr, ran into.

Give this a try:

Suggested change
await $`git commit -m ${core.getInput("commit_message")}`;
try {
await $`git commit -m "Test"`;
} 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
}
}

from chatgpt: https://chatgpt.com/share/6851dccc-4940-8010-a69a-9b22db64d4a1

something about being more defensive:

const { stdout } = await $`git status --porcelain`;
if (!stdout.trim()) {
  console.log("nothing to commit, working tree clean");
} else {
  await $`git commit -m "Test"`;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your original suggestion. I've applied that now 🤞🏻

As for ChatGPT - I'm pretty allergic to the garbage that puts out and the "more defensive" suggestion is nonsense in the context of this action always being run in GitHub Actions, where the git language will be English.

@jrfnl
Copy link
Contributor Author

jrfnl commented Jun 24, 2025

@Andrew-Chen-Wang Could you please allow CI to run again so we can see if the update I made last week made a difference ?

@Andrew-Chen-Wang
Copy link
Owner

sorry, thanks for pinging! Just ran it. Taking a look now

Copy link
Owner

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you!

@Andrew-Chen-Wang Andrew-Chen-Wang merged commit 7ee32e8 into Andrew-Chen-Wang:master Jun 27, 2025
0 of 13 checks passed
@Andrew-Chen-Wang
Copy link
Owner

Hi I've released v5.0.0 @jrfnl please take a look thank you

@jrfnl
Copy link
Contributor Author

jrfnl commented Jun 27, 2025

@Andrew-Chen-Wang Uh-oh... I kind of didn't think this was ready for merge yet.... and testing v5 now, confirms that as the action fails with exit code 1 and an "uncaught exception" when there is nothing to commit.

Aside from that, the preprocess option is also trouble-some as it escapes way too much , breaking every link in the wiki. The default value for that option should probably be false, not true.

I'll try and see if I can come up with a fix for the error related to this PR, but as I said before, I'm not a Node/JS dev, so haven't got a clue what I'm doing.

@jrfnl jrfnl mentioned this pull request Jun 29, 2025
@jrfnl jrfnl deleted the feature/add-disable-empty-commits-option branch June 29, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants