diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0e31159 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +[{*.sh,*.bats,*.bash}] +# like -i=2 +indent_style = space +indent_size = 2 + +shell_variant = auto # like -ln=auto +binary_next_line = true # like -bn +switch_case_indent = true # like -ci +space_redirects = true # like -sr +#keep_padding = true # like -kp +#function_next_line = true # like -fn diff --git a/.github/workflows/gitwatch.yml b/.github/workflows/gitwatch.yml new file mode 100644 index 0000000..e6d60bc --- /dev/null +++ b/.github/workflows/gitwatch.yml @@ -0,0 +1,78 @@ +name: Gitwatch QA + +on: + push: + pull_request: + branches: [master] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + #----------------------------------------------------------------------------- + super-lint: + name: Lint Code Base + + # Don't run action if commit message has #noaction in it. + if: "! contains(github.event.head_commit.message, '#noaction')" + + # I don't think running lint on multiple os' will do any good. + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Run Super-Linter + uses: github/super-linter@v3 + env: + DEFAULT_BRANCH: master + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + #----------------------------------------------------------------------------- + bats: + name: BATS Tests + + # Don't run action if commit message has #noaction in it. + if: "! contains(github.event.head_commit.message, '#noaction')" + + strategy: + matrix: + os: [ubuntu-latest, macOS-latest] + + # The type of runner that the job will run on + runs-on: ${{ matrix.os }} + + timeout-minutes: 5 + + steps: + - name: Setup BATS + # Even though this says 1.2.0,it's actually using 1.2.1 + uses: mig4/setup-bats@v1.2.0 + + - name: Install gitwatch dependencies + shell: bash + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + sudo apt-get -y install inotify-tools + + elif [ "$RUNNER_OS" == "macOS" ]; then + brew install fswatch + brew install coreutils # in order to get readlink + + else + echo "Unsupported OS: $RUNNER_OS" + exit 1 + fi + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run tests + shell: bash + run: | + git config --global user.email "test@email.com" + git config --global user.name "test user" + bashcov bats -rt tests diff --git a/tests/startup-shutdown.bash b/tests/startup-shutdown.bash index c22e3b6..6c5e186 100644 --- a/tests/startup-shutdown.bash +++ b/tests/startup-shutdown.bash @@ -1,26 +1,32 @@ setup() { - # Time to wait for gitwatch to respond - WAITTIME=4 - # Set up directory structure and initialize remote - testdir=$(mktemp -d) - cd $testdir - mkdir remote - cd remote - git init -q --bare - cd .. - mkdir local - cd local - git clone -q ../remote + # Time to wait for gitwatch to respond + # shellcheck disable=SC2034 + WAITTIME=4 + # Set up directory structure and initialize remote + testdir=$(mktemp -d) + # shellcheck disable=SC2164 + cd "$testdir" + mkdir remote + # shellcheck disable=SC2164 + cd remote + git init -q --bare + # shellcheck disable=SC2103 + cd .. + # shellcheck disable=SC2164 + mkdir local + # shellcheck disable=SC2164 + cd local + git clone -q ../remote } - teardown() { - # Remove testing directories - cd /tmp + # Remove testing directories + # shellcheck disable=SC2164 + cd /tmp -# rm -rf $testdir + # rm -rf $testdir - # Make sure gitwatch script gets killed if script stopped background - # Must kill the entire tree of processes generated - pkill -15 -P $GITWATCH_PID + # Make sure gitwatch script gets killed if script stopped background + # Must kill the entire tree of processes generated + pkill -15 -P "$GITWATCH_PID" } diff --git a/tests/sync.bats b/tests/sync.bats index 76cb241..cdbe0d1 100644 --- a/tests/sync.bats +++ b/tests/sync.bats @@ -33,7 +33,7 @@ load startup-shutdown currentcommit=$(git rev-parse master) remotecommit=$(git rev-parse origin/master) [ "$currentcommit" = "$remotecommit" ] - + # Try making subdirectory with file lastcommit=$(git rev-parse master) mkdir subdir @@ -45,7 +45,7 @@ load startup-shutdown # Verify that new commit has happened currentcommit=$(git rev-parse master) [ "$lastcommit" != "$currentcommit" ] - + # Verify that push happened currentcommit=$(git rev-parse master) remotecommit=$(git rev-parse origin/master) @@ -59,7 +59,7 @@ load startup-shutdown # Verify that new commit has happened currentcommit=$(git rev-parse master) [ "$lastcommit" != "$currentcommit" ] - + # Verify that push happened currentcommit=$(git rev-parse master) remotecommit=$(git rev-parse origin/master)