From 9b3f5a1e953f5a2394594d443abb762ce0392ab7 Mon Sep 17 00:00:00 2001 From: Stef Schenkelaars Date: Wed, 28 Jul 2021 13:26:56 +0200 Subject: [PATCH] Setup standardrb with reviewdog --- .github/workflows/publish.yml | 2 +- .github/workflows/reviewdog.yml | 29 ++++++++++++++++ .reviewdog.yml | 4 +++ Gemfile | 5 +++ Gemfile.lock | 49 +++++++++++++++++++++++++++ appsignal-sourcemap.gemspec | 26 +++++++------- lib/appsignal-sourcemap.rb | 2 +- lib/appsignal/sourcemap/hook.rb | 8 ++--- lib/appsignal/sourcemap/supervisor.rb | 14 ++++---- lib/appsignal/sourcemap/uploader.rb | 18 +++++----- lib/appsignal/sourcemap/version.rb | 2 +- 11 files changed, 124 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/reviewdog.yml create mode 100644 .reviewdog.yml create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fe8d0f6..afc4802 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,7 +23,7 @@ jobs: printf -- "---\n:github: Bearer ${{ secrets.GITHUB_TOKEN }}\n" > $HOME/.gem/credentials - name: Replace version by tag value - run: sed -i "s/'[0-9]\.[0-9]\..*'/'${GITHUB_REF##*/}'/" lib/appsignal/sourcemap/version.rb + run: sed -i "s/\"[0-9]\.[0-9]\..*\"/\"${GITHUB_REF##*/}\"/" lib/appsignal/sourcemap/version.rb - name: Build and Publish gem to GitHub Package Registry run: | diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..52731d4 --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,29 @@ +name: reviewdog +on: push +jobs: + rubocop: + strategy: + fail-fast: false + matrix: + ruby: + - 2.7 + - 3.0 + + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: Setup reviewdog + uses: reviewdog/action-setup@v1 + + - name: Run linters with Reviewdog + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: reviewdog -fail-on-error -tee -reporter=github-check diff --git a/.reviewdog.yml b/.reviewdog.yml new file mode 100644 index 0000000..c1ea446 --- /dev/null +++ b/.reviewdog.yml @@ -0,0 +1,4 @@ +--- +runner: + standardrb: + cmd: bundle exec standardrb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..be173b2 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..cfa2824 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,49 @@ +PATH + remote: . + specs: + appsignal-sourcemap (1.0.0.develop) + appsignal (~> 3.0) + +GEM + remote: https://rubygems.org/ + specs: + appsignal (3.0.11) + rack + ast (2.4.2) + parallel (1.20.1) + parser (3.0.2.0) + ast (~> 2.4.1) + rack (2.2.3) + rainbow (3.0.0) + regexp_parser (2.1.1) + rexml (3.2.5) + rubocop (1.18.4) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.8.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.8.0) + parser (>= 3.0.1.1) + rubocop-performance (1.11.4) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + ruby-progressbar (1.11.0) + standard (1.1.6) + rubocop (= 1.18.4) + rubocop-performance (= 1.11.4) + unicode-display_width (2.0.0) + +PLATFORMS + x86_64-darwin-20 + x86_64-linux + +DEPENDENCIES + appsignal-sourcemap! + standard + +BUNDLED WITH + 2.2.24 diff --git a/appsignal-sourcemap.gemspec b/appsignal-sourcemap.gemspec index 909c3f2..583412f 100644 --- a/appsignal-sourcemap.gemspec +++ b/appsignal-sourcemap.gemspec @@ -1,24 +1,26 @@ # frozen_string_literal: true -$LOAD_PATH.push File.expand_path('lib', __dir__) +$LOAD_PATH.push File.expand_path("lib", __dir__) # Maintain your gem's version: -require 'appsignal/sourcemap/version' +require "appsignal/sourcemap/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |spec| - spec.name = 'appsignal-sourcemap' - spec.version = Appsignal::Sourcemap::VERSION - spec.authors = ['Stef Schenkelaars'] - spec.email = ['stef.schenkelaars@gmail.com'] - spec.homepage = 'https://github.com/drieam/appsignal-sourcemap' - spec.summary = 'Upload private sourcemaps to appsignal' + spec.name = "appsignal-sourcemap" + spec.version = Appsignal::Sourcemap::VERSION + spec.authors = ["Stef Schenkelaars"] + spec.email = ["stef.schenkelaars@gmail.com"] + spec.homepage = "https://github.com/drieam/appsignal-sourcemap" + spec.summary = "Upload private sourcemaps to appsignal" - spec.metadata['allowed_push_host'] = 'https://rubygems.pkg.github.com/Drieam' + spec.metadata["allowed_push_host"] = "https://rubygems.pkg.github.com/Drieam" - spec.required_ruby_version = '>= 2.7' + spec.required_ruby_version = ">= 2.7" - spec.files = Dir['lib/**/*', 'README.md'] + spec.files = Dir["lib/**/*", "README.md"] - spec.add_dependency 'appsignal', '~> 3.0' + spec.add_dependency "appsignal", "~> 3.0" + + spec.add_development_dependency "standard" end diff --git a/lib/appsignal-sourcemap.rb b/lib/appsignal-sourcemap.rb index b630ab2..d96f0db 100644 --- a/lib/appsignal-sourcemap.rb +++ b/lib/appsignal-sourcemap.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -require 'appsignal/sourcemap/hook' +require "appsignal/sourcemap/hook" diff --git a/lib/appsignal/sourcemap/hook.rb b/lib/appsignal/sourcemap/hook.rb index a0dcb02..7401b9f 100644 --- a/lib/appsignal/sourcemap/hook.rb +++ b/lib/appsignal/sourcemap/hook.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'appsignal/hooks' +require "appsignal/hooks" module Appsignal module Sourcemap @@ -10,15 +10,15 @@ class SourcemapHook < Appsignal::Hooks::Hook def dependencies_present? defined?(::Rails) && defined?(::Rake::Task) && - Rake::Task.task_defined?('assets:precompile') && + Rake::Task.task_defined?("assets:precompile") && Appsignal.config && Appsignal.config[:upload_sourcemaps] end def install - require 'appsignal/sourcemap/supervisor' + require "appsignal/sourcemap/supervisor" - Rake::Task['assets:precompile'].enhance do + Rake::Task["assets:precompile"].enhance do Appsignal::Sourcemap::Supervisor.start end end diff --git a/lib/appsignal/sourcemap/supervisor.rb b/lib/appsignal/sourcemap/supervisor.rb index 1c8c1cb..49549ae 100644 --- a/lib/appsignal/sourcemap/supervisor.rb +++ b/lib/appsignal/sourcemap/supervisor.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'appsignal/sourcemap/uploader' +require "appsignal/sourcemap/uploader" module Appsignal module Sourcemap @@ -12,7 +12,7 @@ def self.start def start return if invalid_preconditions - Appsignal.logger.info('Starting sourcemaps upload') + Appsignal.logger.info("Starting sourcemaps upload") source_map_paths.map do |source_map_path| Thread.new do @@ -20,20 +20,20 @@ def start end end.each(&:join) - Appsignal.logger.info('Finished sourcemaps upload') + Appsignal.logger.info("Finished sourcemaps upload") end private def invalid_preconditions unless Appsignal.config.valid? - return Appsignal.logger.error('Skipping sourcemaps upload since Appsignal config is invalid') + return Appsignal.logger.error("Skipping sourcemaps upload since Appsignal config is invalid") end if asset_host.blank? - return Appsignal.logger.error('Skipping sourcemaps upload since Rails asset_host is not set') + return Appsignal.logger.error("Skipping sourcemaps upload since Rails asset_host is not set") end if source_map_paths.empty? - return Appsignal.logger.info('Skipping sourcemaps upload since no javascript maps are found') + return Appsignal.logger.info("Skipping sourcemaps upload since no javascript maps are found") end false @@ -44,7 +44,7 @@ def asset_host end def source_map_paths - Dir.glob('**/*.map', base: Rails.public_path) + Dir.glob("**/*.map", base: Rails.public_path) end end end diff --git a/lib/appsignal/sourcemap/uploader.rb b/lib/appsignal/sourcemap/uploader.rb index 6a6520d..113aeb8 100644 --- a/lib/appsignal/sourcemap/uploader.rb +++ b/lib/appsignal/sourcemap/uploader.rb @@ -3,7 +3,7 @@ module Appsignal module Sourcemap class Uploader - UPLOAD_URI = URI('https://appsignal.com/api/sourcemaps') + UPLOAD_URI = URI("https://appsignal.com/api/sourcemaps") def self.upload(sourcemap_path) new(sourcemap_path).upload @@ -42,18 +42,18 @@ def sourcemap_full_path def request Net::HTTP::Post.new(UPLOAD_URI).tap do |request| - request.set_form request_form_data, 'multipart/form-data' + request.set_form request_form_data, "multipart/form-data" end end def request_form_data [ - ['push_api_key', Appsignal.config[:push_api_key]], - ['app_name', Appsignal.config[:name]], - ['revision', Appsignal.config[:revision]], - ['environment', Appsignal.config.env], - ['name[]', source_url], - ['file', sourcemap_content] + ["push_api_key", Appsignal.config[:push_api_key]], + ["app_name", Appsignal.config[:name]], + ["revision", Appsignal.config[:revision]], + ["environment", Appsignal.config.env], + ["name[]", source_url], + ["file", sourcemap_content] ] end @@ -66,7 +66,7 @@ def source_url end def js_path - @sourcemap_path.delete_suffix('.map') + @sourcemap_path.delete_suffix(".map") end def asset_host diff --git a/lib/appsignal/sourcemap/version.rb b/lib/appsignal/sourcemap/version.rb index c5a8c6e..67aac89 100644 --- a/lib/appsignal/sourcemap/version.rb +++ b/lib/appsignal/sourcemap/version.rb @@ -2,6 +2,6 @@ module Appsignal module Sourcemap - VERSION = '1.0.0.develop' + VERSION = "1.0.0.develop" end end