Skip to content

Commit

Permalink
Setup standardrb with reviewdog
Browse files Browse the repository at this point in the history
  • Loading branch information
StefSchenkelaars committed Jul 28, 2021
1 parent 11817cc commit 9b3f5a1
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
runner:
standardrb:
cmd: bundle exec standardrb
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec
49 changes: 49 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
26 changes: 14 additions & 12 deletions appsignal-sourcemap.gemspec
Original file line number Diff line number Diff line change
@@ -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 = ['[email protected]']
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 = ["[email protected]"]
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
2 changes: 1 addition & 1 deletion lib/appsignal-sourcemap.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require 'appsignal/sourcemap/hook'
require "appsignal/sourcemap/hook"
8 changes: 4 additions & 4 deletions lib/appsignal/sourcemap/hook.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'appsignal/hooks'
require "appsignal/hooks"

module Appsignal
module Sourcemap
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/appsignal/sourcemap/supervisor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'appsignal/sourcemap/uploader'
require "appsignal/sourcemap/uploader"

module Appsignal
module Sourcemap
Expand All @@ -12,28 +12,28 @@ 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
Uploader.upload(source_map_path)
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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions lib/appsignal/sourcemap/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/appsignal/sourcemap/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Appsignal
module Sourcemap
VERSION = '1.0.0.develop'
VERSION = "1.0.0.develop"
end
end

0 comments on commit 9b3f5a1

Please sign in to comment.