فهرست منبع

testing bash linter

Daniel Gibbs 10 سال پیش
والد
کامیت
02789fcb28
13فایلهای تغییر یافته به همراه197 افزوده شده و 2 حذف شده
  1. 5 2
      .travis.yml
  2. 8 0
      build/.shippable.yml
  3. 8 0
      build/.travis.yml
  4. 22 0
      build/LICENSE
  5. 75 0
      build/README.md
  6. 45 0
      build/build.sh
  7. 10 0
      build/install.sh
  8. 8 0
      build/shippable.yml.example
  9. 2 0
      build/tests/bash.sh
  10. 2 0
      build/tests/ksh.sh
  11. 2 0
      build/tests/sh.sh
  12. 2 0
      build/tests/zsh.sh
  13. 8 0
      build/travis.yml.example

+ 5 - 2
.travis.yml

@@ -20,7 +20,10 @@ addons:
     - telnet 
     - expect
 
-script:
+install:
+  	- ./build/install.sh
 
+script:
+  	- ./build/build.sh
     - bash tests/tests_jc2server.sh
-    - bash tests/tests_ts3server.sh
+    - bash tests/tests_ts3server.sh

+ 8 - 0
build/.shippable.yml

@@ -0,0 +1,8 @@
+language: ruby
+install:
+  - ./install.sh
+script:
+  - ./build.sh
+notifications:
+  email: false
+sudo: required

+ 8 - 0
build/.travis.yml

@@ -0,0 +1,8 @@
+language: bash
+install:
+  - ./install.sh
+script:
+  - ./build.sh
+notifications:
+  email: false
+sudo: required

+ 22 - 0
build/LICENSE

@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Carlos Alexandro Becker
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+

+ 75 - 0
build/README.md

@@ -0,0 +1,75 @@
+shell-ci-build [![Build Status](https://travis-ci.org/caarlos0/shell-ci-build.svg?branch=master)](https://travis-ci.org/caarlos0/shell-ci-build)
+==================
+
+A submodule to lint your shell projects with shellcheck in travis.ci builds.
+
+## Build
+
+- The `install.sh` script will install shellckeck.
+- The `build.sh` will lint all executable files with shellcheck, avoiding
+Ruby, compdef and the like files. It will also ignore all files inside `.git`
+directory and files of your `gitmodules`, if any.
+
+## Usage
+
+```sh
+git submodule add https://github.com/caarlos0/shell-ci-build.git build
+cp build/travis.yml.example .travis.yml
+```
+
+We also support Shippable:
+
+```
+cp build/shippable.yml.example .shippable.yml
+```
+
+Or tweak your `.travis.yml` to be like this:
+
+```yml
+language: bash
+install:
+  - ./build/install.sh
+script:
+  - ./build/build.sh
+```
+
+## Customizing
+
+You might want to lint other files, to do that, you need your own
+`build.sh` and a slight change in `.travis.yml` file.
+
+Example (from  my [dotfiles](https://github.com/caarlos0/dotfiles)):
+
+```sh
+#!/usr/bin/env bash
+set -eo pipefail
+source ./build/build.sh
+check "./zsh/zshrc.symlink"
+```
+
+```yml
+language: bash
+install:
+  - ./build/install.sh
+script:
+  - ./build.sh
+notifications:
+  email: false
+```
+
+This will make travis ran the `build.sh` from this project first,
+then, lint your custom files.
+
+You can also override the `find_cmd` function, which returns a string
+containing the `find` command to `eval`. Check the source or open an
+issue if you have any problems.
+
+## Updating
+
+Update your projects is easy. Just run this:
+
+```sh
+git submodule update --remote --merge && \
+  git commit -am 'updated shell-ci-build version' && \
+  git push
+```

+ 45 - 0
build/build.sh

@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+set -eo pipefail
+[[ "${DEBUG:-}" ]] && set -x
+
+success() {
+  printf "\r\033[2K  [ \033[00;32mOK\033[0m ] Linting %s...\n" "$1"
+}
+
+fail() {
+  printf "\r\033[2K  [\033[0;31mFAIL\033[0m] Linting %s...\n" "$1"
+  exit 1
+}
+
+check() {
+  local script="$1"
+  shellcheck "$script" || fail "$script"
+  success "$script"
+}
+
+find_prunes() {
+  local prunes="! -path './.git/*'"
+  if [ -f .gitmodules ]; then
+    while read module; do
+      prunes="$prunes ! -path './$module/*'"
+    done < <(grep path .gitmodules | awk '{print $3}')
+  fi
+  echo "$prunes"
+}
+
+find_cmd() {
+  echo "find . -type f -and \( -perm +111 -or -name '*.sh' \) $(find_prunes)"
+}
+
+check_all_executables() {
+  echo "Linting all executables and .sh files, ignoring files inside git modules..."
+  eval "$(find_cmd)" | while read script; do
+    head=$(head -n1 "$script")
+    [[ "$head" =~ .*ruby.* ]] && continue
+    [[ "$head" =~ .*zsh.* ]] && continue
+    [[ "$head" =~ ^#compdef.* ]] && continue
+    check "$script"
+  done
+}
+
+check_all_executables

+ 10 - 0
build/install.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+set -eo pipefail
+
+main() {
+  local filename="shellcheck_0.3.7-1_amd64.deb"
+  wget "http://ftp.debian.org/debian/pool/main/s/shellcheck/$filename"
+  sudo dpkg -i "$filename"
+}
+
+main

+ 8 - 0
build/shippable.yml.example

@@ -0,0 +1,8 @@
+language: ruby
+install:
+  - ./build/install.sh
+script:
+  - ./build/build.sh
+notifications:
+  email: false
+sudo: required

+ 2 - 0
build/tests/bash.sh

@@ -0,0 +1,2 @@
+#!/bin/bash
+echo "hi"

+ 2 - 0
build/tests/ksh.sh

@@ -0,0 +1,2 @@
+#!/bin/ksh
+echo "hi"

+ 2 - 0
build/tests/sh.sh

@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "hi"

+ 2 - 0
build/tests/zsh.sh

@@ -0,0 +1,2 @@
+#!/bin/zsh
+echo "hi"

+ 8 - 0
build/travis.yml.example

@@ -0,0 +1,8 @@
+language: bash
+install:
+  - ./build/install.sh
+script:
+  - ./build/build.sh
+notifications:
+  email: false
+sudo: required