"Auto-commit if spotlessApply has changes" workflow job failed unexpectedly
- Dominant language
- Kotlin
- Stars
- 1.1k
- Forks
- 419
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 28
Description
The **"Auto-commit if spotlessApply has changes"** workflow job can fail with a misleading error message. While the log may suggest a non-existent branch, the root cause is often an uncommitted change from a previous step ([example failure](https://github.com/android/snippets/actions/runs/16627536236/job/47057365190)).
### Root Cause
The failure is a symptom of a cascading issue:
1. A preceding job (e.g., **"Run spotlessApply for Wear"**) modifies a file to fix a style violation but still exits with a success code.
2. Because source files were modified, the conditional **"Auto-commit..."** job is triggered.
3. The `Auto-commit` job then fails due to the unexpected repository state.
This is confusing because the UI marks all previous jobs as successful, making it seem like the `Auto-commit` job is the only problem.
### Workaround
The workaround is to run the `spotlessApply` tasks locally to find and commit the file modifications.
1. Manually execute each job of [the workflow](https://github.com/android/snippets/blob/main/.github/workflows/apply_spotless.yml) until you find one that modifies a file. For example:
```sh
./gradlew :wear:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
```
2. Commit the change that the command made ([example](https://github.com/android/snippets/pull/572/commits/2d72e3375e9ad683ec6f8d560af829259233b419)).
3. Push the commit. The workflow should now complete successfully, as the `Auto-commit` step will have nothing to do.
Contributor guide
Assessment
This issue has not been assessed yet.