- Overview
- Getting Started
- Do the same in continuous integration
- Run the script without docker
- Contributions
- Changelog
- License
This project provides two docker images (ubuntu and alpine) with two scripts to check the encoding file and the end-of-line of the file in a project. Both images can be seeing in the docker directory
These images can be used in a continuous integration system like circle-ci, gitlab-ci or travis-ci.
Finally all images are available on docker hub
The tool who does the job (named checkEncoding), tooks as a first parameter the encoding target to check. As the tool uses uchardet, we can have all supported encoding by uchardet.
As the second parameter, the tool takes all files that you want to check. It can take a regex too.
For example, you want to check if the files of your current project (let's say a Java project build with maven) is encoding in utf-8, you could use the tool like this:
docker run --rm -v ${PWD}:/var/workspace/project nexucis/ci-checkfiles /bin/bash -c "cd /var/workspace/project && checkEncoding utf-8 *.md *.java *.xml"
For the moment, the tool (named checkEOL) checks only if the files have an UNIX end-of-line.
The tool takes only one thing : the kind of document that you want to check.
If we use the same example used in the "Check encoding" section, we could use the tool like this:
docker run --rm -v ${PWD}:/var/workspace/project nexucis/ci-checkfiles /bin/bash -c "cd /var/workspace/project && checkEOL *.md *.java *.xml"
This image is designed to work in a continuous integration system. So you could use it to check your project in a easy way.
The example below shows a simple circle-ci configuration files .circleci/config.yml who shows how to use the two tools describe in a previous section
version: 2
jobs:
analyze_eol:
docker:
- image: nexucis/ci-checkfiles
working_directory: ~/repo
steps:
- checkout
- run: checkEOL *.cmd *.php *.md *.xml
analyze_encoding_utf8:
docker:
- image: nexucis/ci-checkfiles
working_directory: ~/repo
steps:
- checkout
- run: checkEncoding utf-8 *.cmd *.php *.md *.xml
workflows:
version: 2
build_and_analyze:
jobs:
- analyze_eol
- analyze_encoding_utf8
If you want to learn more about circle-ci please read the official documentation
Same example but with Gitlab-ci .
stages:
- analyze
analyze_eol:
stage: analyze
image: nexucis/ci-checkfiles
script:
- checkEOL *.md *.java *.xml *.json *.ts *.js
analyze_encoding_utf8:
stage: analyze
image: nexucis/ci-checkfiles
script:
- checkEncoding utf-8 *.md *.java *.xml *.json *.ts *.js
If you want to use it with tracis, you can do something like this :
sudo: required
language: java
services:
- docker
script:
- docker run --rm -v ${PWD}:/var/workspace/project nexucis/ci-checkfiles /bin/bash -c "cd /var/workspace/project && checkEOL *.md *.java *.xml"
- docker run --rm -v ${PWD}:/var/workspace/project nexucis/ci-checkfiles /bin/bash -c "cd /var/workspace/project && checkEncoding utf-8 *.md *.java *.xml"
The example above is based on the official documentation when we want to use docker with travis-ci
Docker bothering you ? You think that is overkill to use docker to run just two tiny script ? Here is the way to use it without docker.
- a bash in version 4 to run this script
bash --version
- uchardet installed
sudo apt-get update && sudo apt-get install uchardet libuchardet-dev
uchardet can be installed on Fedora, Gentoo and mac. Please see the official documentation to learn about it
- Install the script in a
bin
directory :
curl -s -XGET https://raw.githubusercontent.com/Nexucis/ci-checkFiles/master/encoding/encoding_if.sh > /usr/bin/encoding_if
curl -s -XGET https://raw.githubusercontent.com/Nexucis/ci-checkFiles/master/encoding/checkEncoding.sh > /usr/bin/checkEncoding
chmod +x /usr/bin/checkEncoding /usr/bin/encoding_if
- Use it and enjoy :
cd /var/workspace/project && checkEncoding ascii *.java
- dos2unix with a version >= 7.1
Tips :
dos2unix with this version is available on ubuntu 17.10
gitbash (at least last version, maybe older too) has dos2unix in 7.4.0
- Install the script in a
bin
directory :
curl -s -XGET https://raw.githubusercontent.com/Nexucis/ci-checkFiles/master/eol/eol_if.sh > /usr/bin/eol_if
curl -s -XGET https://raw.githubusercontent.com/Nexucis/ci-checkFiles/master/eol/checkEOL.sh > /usr/bin/checkEOL
chmod +x /usr/bin/eol_if /usr/bin/checkEOL
- Use it and enjoy :
cd /var/workspace/project && checkEOL *.java
If you want to improve this image, feel free to use the Issue section or to send a pull request. Both of them will be appreciated.