Decision Automate checking for uncommitted files

accepted

Uncommitted files resulting from builds can cause issues during deployments.

Decision

Add automation to verify there are no uncommitted files tracked in git.

Implementations

This test can be implemented several ways.

Drainpipe

If your project already uses Drainpipe, this test is already included in the task test:static and task test:functional jobs. It is also included in the preconfigured Github Actions job. If needed, the test can be run independently: task test:untracked.

Task runner

If not using Drainpipe, but are using an automated task runner, such as Github Actions or Bitbucket Pipelines, add the test there.

If using Github Actions, consider verify-changed-files.

If using another task runner, either adapt the verify-changed-files project, or utilize the pre-commit script, below.

Git pre-commit hook

If the project does not have access to Drainpipe or a task runner, or does not want the overhead of their inclusion, use a git pre-commit hook.

The following shell script is sufficient to test.

#!/bin/sh

if [ -z "$(git status --porcelain)" ]; then
  echo "Working directory clean"
else
  echo "Uncommitted changes present"
  exit 1
fi

Consequences

  • Deployments will not have errors related to uncommitted files
  • Devops will need to setup uncommitted file checks for each project