Skip to content

Instantly share code, notes, and snippets.

@jessiel-hacke
Last active May 1, 2023 19:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessiel-hacke/83bf7cc2b7719ff5752fb4ef2abbc1ef to your computer and use it in GitHub Desktop.
Save jessiel-hacke/83bf7cc2b7719ff5752fb4ef2abbc1ef to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
# GIT_DIR isn't set for all hook events. Read this as GIT_DIR ||=
export GIT_DIR="${GIT_DIR-$(dirname "$(dirname "${BASH_SOURCE[0]}")")}"
if [[ -p /dev/fd/0 ]]; then # Check if STDIN is a pipe (i.e. we're getting input from Git)
INPUT=$(</dev/stdin)
fi
while read -r hook; do
if [[ -z "${INPUT+x}" ]]; then
"${hook}" "$@"
else
"${hook}" "$@" <<< "${INPUT}"
fi
done < <(/usr/bin/find -L "${GIT_DIR}/hooks/pre-commit.d" -maxdepth 1 -mindepth 1 -type f -perm +111 | sort)
#!/usr/bin/env ruby
# This script requires the following gems to be installed
# gem install whirly
# gem install paint
require 'pty'
require 'whirly'
GRAPHQL_CHANGES = %x(git diff --cached --name-only --diff-filter=ACM | grep -E "(graphql|mutation|queries)")
JS_CHANGES = %x(git diff --cached --name-only --diff-filter=ACM | grep "[.ts|.tsx]$")
RUBY_CHANGES = %x(git diff --cached --name-only --diff-filter=ACM | grep ".rb$")
@failed = false
@error_messages = []
def run_command(command, title)
Whirly.configure spinner: "dots", color: true, stop: "🎉"
Whirly.start status: "Running #{title}"
message = %x(#{command} 2>&1)
if $?.to_i != 0
Whirly.status = "#{title} failed"
Whirly.stop "❌"
@error_messages << message
@failed= true
end
Whirly.status = "#{title} Completed"
Whirly.stop "🎉"
end
puts GRAPHQL_CHANGES
if !RUBY_CHANGES.empty?
run_command('bundle exec rubocop', 'Rubocop')
run_command('bin/tapioca dsl', 'Sobert DSL Types Generator')
run_command('bin/tapioca gem', 'Sobert GEM Types Generator')
run_command('bin/typecheck', 'Sorbet Typecheck')
if !GRAPHQL_CHANGES.empty?
run_command('bundle exec rails graphql:schema:dump', 'GraphQL Schema Dump')
run_command('yarn graphql:generate', 'GraphQL Types Generator')
end
end
if !JS_CHANGES.empty?
run_command('yarn lint', 'ESLint')
run_command('yarn tc', 'TypeScript Typecheck')
if !GRAPHQL_CHANGES.empty?
run_command('yarn graphql:generate', 'GraphQL Types Generator')
end
end
if @failed
fail_message = Paint['FAILED: One or more checks have failed. Please fix the errors below', :red]
puts "\n#{fail_message}\n\n"
abort @error_messages.join('\n')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment