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 diff --git a/action.yml b/action.yml index f5478d5..b8a766a 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,8 +22,27 @@ inputs: runs: using: "composite" steps: + - name: Configure Git + 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 + - name: Check EOL configs + run: | + IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}" + for ext in "${ext_array[@]}"; do + result=$(git check-attr text *"${ext}") + echo "$result" + if [[ $result == *"text: auto" || $result == *"text: text" ]]; then + 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 + shell: bash - name: Set up Python 3.10 uses: actions/setup-python@v5 with: @@ -32,6 +57,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.