Skip to content

entrypoint.php does not return a non-zero exit code on failure (e.g. auth error) #58

@yoriiis

Description

@yoriiis

Describe the bug

The current entrypoint.php script does not return a non-zero exit code when a failure occurs internally (such as a Git authentication error, failed chdir, or missing .git directory). This leads to CI jobs (e.g., GitHub Actions, GitLab CI) reporting success even when the monorepo split clearly failed.

Steps to reproduce

  1. Run the splitter with an invalid Git token (e.g., incorrect or missing token in environment variable).
  2. Observe that git clone fails and errors like Authentication failed or No such file or directory appear.
  3. Despite the failure, the script finishes and returns a 0 exit code.
  4. The CI job incorrectly reports success.

Example output

Here is a real-world log extract (GitLab CI), using an intentionally invalid token to simulate an auth error:

$ php /splitter/entrypoint.php
[NOTE] Resolving configuration...
[NOTE] Cloning "https://gitlab.com/company/project-path.git" repository to "/tmp/monorepo_split/clone_directory" directory
[NOTE] Running: git clone -- https://oauth2:[MASKED]@gitlab.com/company/project-path.git /tmp/monorepo_split/clone_directory
Cloning into '/tmp/monorepo_split/clone_directory'...
remote: HTTP Basic: Access denied. If a password was provided for Git authentication, the password was incorrect or you're required to use a token instead of a password. If a token was provided, it was either incorrect, expired, or improperly scoped. See https://gitlab.com/help/topics/git/troubleshooting_git.md#error-on-git-fetch-http-basic-access-denied
fatal: Authentication failed for 'https://gitlab.com/company/project-path.git/'
Warning: chdir(): No such file or directory (errno 2) in /splitter/entrypoint.php on line 39
[NOTE] Trying to checkout main branch
Switched to a new branch 'main'
[NOTE] Cleaning destination repository of old files
cp: can't stat '/tmp/monorepo_split/clone_directory/.git': No such file or directory
Command failed
Cleaning up project directory and file based variables
00:02
Job succeeded

Despite multiple errors (Authentication failed, chdir(): No such file, cp: can't stat), the script finishes with a success status, causing the CI job to incorrectly report success.

Expected behavior

The script should:

  • Return a non-zero exit code when an internal command fails.
  • Fail fast when a git clone, file operation, or directory change fails.

Why it matters

This breaks reliability in CI/CD workflows. Downstream tasks may proceed under the false assumption that the split operation succeeded, potentially propagating incorrect states or triggering deployments.

Related

Proposed solution

Reintroduce exit code handling with exit(1) (or appropriate non-zero codes) when:

  • git clone or other shell commands fail (e.g., using proc_open or checking return values)
  • Exceptions are thrown or fatal conditions are encountered
  • Any operation that makes the split incomplete or invalid

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions