From b3794be0683b29c4422bebec6de83af9ccf359ed Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:54:51 -0400 Subject: [PATCH 01/11] Configure Git + Make Git operations optional --- action.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/action.yml b/action.yml index f5478d5..d7587b9 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,12 @@ inputs: extensions: description: 'List of extensions (including the dot) seperated by a comma.' required: true + do-checkout: + description: 'Set to true in order to let the action perform the checkout for you (default = false).' + default: false + do-push: + description: 'Set to true in order to let the action perform the checkout for you (default = false).' + default: false bot-name: description: 'Name of the bot that will perform the commit.' default: 'github-actions[bot]' @@ -16,7 +22,13 @@ inputs: runs: using: "composite" steps: + - name: Configure Git + if: ${{ inputs.do-checkout }} + run: | + git config --global core.autocrlf false + git config --global core.eol lf - name: Checkout + if: ${{ inputs.do-checkout() }} uses: actions/checkout@v4 - name: Set up Python 3.10 uses: actions/setup-python@v5 @@ -32,6 +44,7 @@ runs: python '${{ github.action_path }}/enforce-crlf.py' "${{ inputs.extensions }}" shell: bash - name: Push content + if: ${{ inputs.do-push }} uses: stefanzweifel/git-auto-commit-action@v5 with: # Optional. Commit message for the created commit. From 354d2f6e6ec4b274fb458590bf02aadf29c6f668 Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:57:27 -0400 Subject: [PATCH 02/11] fix inputs check --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index d7587b9..66c56b5 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,7 @@ runs: git config --global core.autocrlf false git config --global core.eol lf - name: Checkout - if: ${{ inputs.do-checkout() }} + if: ${{ inputs.do-checkout }} uses: actions/checkout@v4 - name: Set up Python 3.10 uses: actions/setup-python@v5 From 4e270909b241d763348a3b36d5db57d228a1e496 Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:58:42 -0400 Subject: [PATCH 03/11] Add shell --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 66c56b5..b9488e6 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,7 @@ runs: run: | git config --global core.autocrlf false git config --global core.eol lf + shell: bash - name: Checkout if: ${{ inputs.do-checkout }} uses: actions/checkout@v4 From 02eeacd426260ba26947ad808b91f05ad2d85d0e Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:12:51 -0400 Subject: [PATCH 04/11] Add check for EOL configs --- action.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b9488e6..e6e353b 100644 --- a/action.yml +++ b/action.yml @@ -23,11 +23,17 @@ runs: using: "composite" steps: - name: Configure Git - if: ${{ inputs.do-checkout }} run: | git config --global core.autocrlf false git config --global core.eol lf shell: bash + - name: Check EOL configs + run: | + IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" + for ext in "${ext_array[@]}"; do + git check-attr eol *"${ext}" + done + shell: bash - name: Checkout if: ${{ inputs.do-checkout }} uses: actions/checkout@v4 From f213d874b6dd7d8c189da1a497f381790ddc259b Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:13:57 -0400 Subject: [PATCH 05/11] Reorder --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index e6e353b..ba95f89 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,9 @@ runs: git config --global core.autocrlf false git config --global core.eol lf shell: bash + - name: Checkout + if: ${{ inputs.do-checkout }} + uses: actions/checkout@v4 - name: Check EOL configs run: | IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" @@ -34,9 +37,6 @@ runs: git check-attr eol *"${ext}" done shell: bash - - name: Checkout - if: ${{ inputs.do-checkout }} - uses: actions/checkout@v4 - name: Set up Python 3.10 uses: actions/setup-python@v5 with: From 3147ce8c85c4feca3b8262686d6ce6fda4cb7daf Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:25:27 -0400 Subject: [PATCH 06/11] Use text attribute --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ba95f89..3874381 100644 --- a/action.yml +++ b/action.yml @@ -34,7 +34,7 @@ runs: run: | IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" for ext in "${ext_array[@]}"; do - git check-attr eol *"${ext}" + git check-attr text *"${ext}" done shell: bash - name: Set up Python 3.10 From d3e540aebc24adb01277709a62f7ab50d132d54c Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:43:41 -0400 Subject: [PATCH 07/11] Error out if some files have text propertie --- action.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 3874381..bf01342 100644 --- a/action.yml +++ b/action.yml @@ -32,10 +32,14 @@ runs: uses: actions/checkout@v4 - name: Check EOL configs run: | - IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" - for ext in "${ext_array[@]}"; do - git check-attr text *"${ext}" - done + IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" + for ext in "${ext_array[@]}"; do + result=$(git check-attr eol *"${ext}") + if [[ $result == *"text: auto" || $result == *"text: text" ]]; then + echo "There is an issue with ${ext}" + exit 1 + fi + done shell: bash - name: Set up Python 3.10 uses: actions/setup-python@v5 From c7ffb8f7a72c84cb6ff97dbd49077ef77dab36a0 Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:45:44 -0400 Subject: [PATCH 08/11] Indentation --- action.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index bf01342..0f0d7a8 100644 --- a/action.yml +++ b/action.yml @@ -32,14 +32,14 @@ runs: uses: actions/checkout@v4 - name: Check EOL configs run: | - IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" - for ext in "${ext_array[@]}"; do - result=$(git check-attr eol *"${ext}") - if [[ $result == *"text: auto" || $result == *"text: text" ]]; then - echo "There is an issue with ${ext}" - exit 1 - fi - done + IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" + for ext in "${ext_array[@]}"; do + result=$(git check-attr eol *"${ext}") + if [[ $result == *"text: auto" || $result == *"text: text" ]]; then + echo "There is an issue with ${ext}" + exit 1 + fi + done shell: bash - name: Set up Python 3.10 uses: actions/setup-python@v5 From 9301b5c664c707ee7739fda50fce58511bb307d1 Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:48:09 -0400 Subject: [PATCH 09/11] Also echo --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0f0d7a8..3dc1119 100644 --- a/action.yml +++ b/action.yml @@ -34,7 +34,8 @@ runs: run: | IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" for ext in "${ext_array[@]}"; do - result=$(git check-attr eol *"${ext}") + result=$(git check-attr text *"${ext}") + echo "$result" if [[ $result == *"text: auto" || $result == *"text: text" ]]; then echo "There is an issue with ${ext}" exit 1 From a29f272c7cb9a6c7ba4eac750375574943571aab Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:08:01 -0400 Subject: [PATCH 10/11] Improve error message --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 3dc1119..b8a766a 100644 --- a/action.yml +++ b/action.yml @@ -37,7 +37,8 @@ runs: result=$(git check-attr text *"${ext}") echo "$result" if [[ $result == *"text: auto" || $result == *"text: text" ]]; then - echo "There is an issue with ${ext}" + echo "There is an issue with the ${ext} extension. The `text` attribute is set or it has a value of `auto` for that extension." + echo "This means that you won't be able to commit changes with CRLF. You need to make sure that `text` is unspecified or unset (-text)" exit 1 fi done From 6f1bfdba65516608530d154d4991232aa3740e83 Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:25:47 -0400 Subject: [PATCH 11/11] Update README --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78c71be..d85cf9c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A simple GitHub Action to enforce CRLF on selected file types in your repo. Example worflow: ```yml -name: Enforce-CRLF +name: Force CRLF for files inside the index on: push: @@ -18,7 +18,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Enforce CRLF action - uses: DecimalTurn/Enforce-CRLF@v1 + uses: DecimalTurn/Enforce-CRLF@main with: extensions: .bas, .frm, .cls + do-checkout: true + do-push: true ``` + +Note that in the above example, we are setting `do-checkout` and `do-push` in order to let Enforce-CRLF perform those steps for us. If however, you want Enforce-CRLF to be part of a more complex workflow where you've already performed the `git checkout` and/or will perform the `git push` at the end, you can always set those values to false. + +```yml + do-checkout: false + do-push: false +``` \ No newline at end of file