#development #git #github

In one of my repositories, I'm using GitHub actions to compare a fresh build with the one checked in into the repository. This is done like this:

1- name: Compare the expected and actual dist/ directories
2  run: |
3    if [ "$(git diff --ignore-space-at-eol --ignore-cr-at-eol dist/ | wc -l)" -gt "0" ]; then
4      echo "Detected uncommitted changes after build.  See status below:"
5      git diff
6      exit 1
7    fi    
8  id: diff

Since this morning, I was getting the following error:

1warning: in the working copy of 'dist/index.js', CRLF will be replaced by LF the next time Git touches it
2Detected uncommitted changes after build.  See status below:
3warning: in the working copy of 'dist/index.js', CRLF will be replaced by LF the next time Git touches it
4diff --git a/dist/index.js b/dist/index.js
5index 8018be6..31f317c 100644
6Binary files a/dist/index.js and b/dist/index.js differ
7Error: Process completed with exit code 1.

To fix it, it took two steps.

First, I updated the .gitattributes file and changed the following line:

* text=auto

was changed into:

* text=auto eol=lf

Then, I updated the step in the action to perform a renormalize of the line endings before doing the diff:

1- name: Compare the expected and actual dist/ directories
2  run: |
3    git add --renormalize .
4    if [ "$(git diff --ignore-space-at-eol --ignore-cr-at-eol dist/ | wc -l)" -gt "0" ]; then
5      echo "Detected uncommitted changes after build.  See status below:"
6      git diff
7      exit 1
8    fi    
9  id: diff