From 15774288bf073702c29aa61266209a98a0de812e Mon Sep 17 00:00:00 2001 From: Vadim Kononov Date: Wed, 12 Jul 2023 09:58:24 -0500 Subject: [PATCH] Improve Github workflows and add a "lint" badge to README. Github workflows will now only run on pull requests and on master. Pushes to other branches will no longer trigger the running of Github actions. --- .github/workflows/lint.yml | 8 ++++++-- .github/workflows/test.yml | 6 +++++- README.md | 3 ++- bin/lint | 30 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100755 bin/lint diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f175bc6..976e078 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,6 +1,10 @@ name: Lint -on: [ push, pull_request ] +on: + push: + branches: + - main + pull_request: jobs: test: @@ -17,4 +21,4 @@ jobs: - name: Install dependencies run: bundle install - name: Run Rubocop - run: bundle exec rubocop \ No newline at end of file + run: bin/lint --no-fix \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0189cb8..2da34df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,10 @@ name: Test -on: [ push, pull_request ] +on: + push: + branches: + - main + pull_request: jobs: test: diff --git a/README.md b/README.md index efcb6fd..3ce6817 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ # FillablePDF [![Gem Version](https://badge.fury.io/rb/fillable-pdf.svg)](https://rubygems.org/gems/fillable-pdf) -[![Test Status](https://github.com/vkononov/fillable-pdf/actions/workflows/test.yml/badge.svg)](https://github.com/vkononov/fillable-pdf/actions) +[![Lint Status](https://github.com/vkononov/fillable-pdf/actions/workflows/lint.yml/badge.svg)](https://github.com/vkononov/fillable-pdf/actions/workflows/lint.yml) +[![Test Status](https://github.com/vkononov/fillable-pdf/actions/workflows/test.yml/badge.svg)](https://github.com/vkononov/fillable-pdf/actions/workflows/test.yml) FillablePDF is an extremely simple and lightweight utility that bridges iText and Ruby in order to fill out fillable PDF forms or extract field values from previously filled out PDF forms. diff --git a/bin/lint b/bin/lint new file mode 100755 index 0000000..c9a1df9 --- /dev/null +++ b/bin/lint @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +RESET_COLOR='\033[0m' +HIGHLIGHT_COLOR='\033[0;35m' +SUCCESS_COLOR='\033[0;32m' +ERROR_COLOR='\033[0;31m' + +clear + +# linter configuration paths +RUBOCOP_CONFIG=.rubocop.yml + +# Checking for existence of configuration files... +test -e ${RUBOCOP_CONFIG} || { echo -e "${ERROR_COLOR}"ERROR: ${RUBOCOP_CONFIG} not found."${RESET_COLOR}"; exit 1; } + +# Running linters +echo -e "${HIGHLIGHT_COLOR}"Linting Ruby on Rails using RuboCop..."${RESET_COLOR}" +if [[ "$1" == "--no-fix" ]]; then + bundle exec rubocop || { valid=false; } +else + bundle exec rubocop --autocorrect-all || { valid=false; } +fi + +# Printing summary +if [[ "$valid" == false ]]; then + echo -e "${ERROR_COLOR}"ERROR: Lint errors have been found in your code."${RESET_COLOR}" + exit 1 +else + echo -e "${SUCCESS_COLOR}"SUCCESS: All lints have completed without errors."${RESET_COLOR}" +fi