Giter Club home page Giter Club logo

eol-blocker's Introduction

EOL Blocker

This GitHub action blocks pull requests that contain improper line-endings. GitHub and git have mechanisms to deal with keeping line-endings consistent to ensure compatibility with multiple operating systems. You can read more about this in the GitHub help pages, but to summarize: GitHub typically stores all text files with Unix-style line endings on their servers. The Windows versions of git clients can handle converting them to Windows-style on checkout, and back to Unix-style on check-in, and some repositories set this on their repo to enforce it. This mostly avoids any issues. However, there is at least one way that this "auto-conversion" can be bypassed: the "Upload files" button on GitHub.com.

If a user adds files to the repo via this button from a Windows machine, then the file on the server will contain Windows-style line endings. This can cause havoc with repositories that have multiple active contributors. As those files get synced to their local clones, the git client detects them as full-file diffs that cannot be discarded. Multiple contributors committing these changes can lead to merge conflicts that become difficult to resolve.

The solution

To avoid these "bad" line endings from spreading to all contributors' clones, it's best to keep these from entering your default branch (or any other persistent branches that your contributors use). EOL Blocker aims to detect any pull requests that contains these type of files, and allows you to block merges until the files are fixed.

Setup

  1. Create a label in your repository named crlf detected. The action will flag pull requests with bad line endings with this tag. If the tag isn't present, the action will fail.

  2. To install this action, create a .yml file in .github\workflows, with the following syntax. See Inputs below for info on the inputs. (See main.yml in this repository for an example).

    on:
      pull_request:
        branches: [ main ]
    
    jobs:
      check_pull_request_job:
        runs-on: ubuntu-latest
        name: Check files for CRLF
        steps:
        - name: Validate files
          with:
            repoToken: ${{ secrets.GITHUB_TOKEN }}
            excludeFiles: '**/**.png;filename.txt'
          id: validate
          uses: microsoftgraph/[email protected]
  3. If you wish to block merges that are flagged by this action, set the Check files for CRLF check as a required status check.

Inputs

Input Required? Description
repoToken Yes A token that allows the action read/write access to pull requests in your repository. This SHOULD be set to the default GitHub Actions token (${{ secrets.GITHUB_TOKEN }}, but MAY be set to a personal access token stored in a repository secret.
excludeFiles No A semicolon-delimited list of glob patterns to match files against. Any matching files will be excluded from validation. If omitted, the default pattern **/**.{png,jpg,jpeg,gif,bmp} is used.

Code of conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

eol-blocker's People

Contributors

jasonjoh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.