Skip to content

Commit

Permalink
add github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
bdurand committed Nov 12, 2023
1 parent 9ef4c04 commit b0a5cf4
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 32 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dependabot update strategy
version: 2
updates:
- package-ecosystem: bundler
directory: "/"
schedule:
interval: weekly
allow:
# Automatically keep all runtime dependencies updated
- dependency-name: "*"
dependency-type: "production"
versioning-strategy: lockfile-only
47 changes: 47 additions & 0 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Continuous Integration

on:
push:
branches:
- master
- actions-*
tags:
- v*
pull_request:
branches-ignore:
- actions-*

env:
BUNDLE_CLEAN: "true"
BUNDLE_PATH: vendor/bundle
BUNDLE_JOBS: 3
BUNDLE_RETRY: 3

jobs:
build:
name: ${{ matrix.ruby }} build
runs-on: ubuntu-latest
strategy:
matrix:
include:
- ruby: "ruby"
standardrb: true
- ruby: "3.0"
- ruby: "2.7"
- ruby: "2.6"
- ruby: "2.5"
- ruby: "2.4"
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby}}
- name: Install gems
run: |
bundle install
- name: Run Tests
run: bundle exec rake
- name: standardrb
if: matrix.standardrb
run: bundle exec standardrb
29 changes: 29 additions & 0 deletions .github/workflows/regression_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Regression Test
on:
workflow_dispatch:
schedule:
- cron: "0 15 * * 1"
env:
BUNDLE_CLEAN: "true"
BUNDLE_PATH: vendor/bundle
BUNDLE_JOBS: 3
BUNDLE_RETRY: 3
jobs:
specs:
name: Run specs
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
- name: Install bundler
run: |
bundle update
- name: Run specs
run: |
bundle exec rake spec
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
pkg
tmp
rdoc
*.rbc
.tm_properties
.bundle
/gemfiles/*.lock
.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
.DS_Store
Gemfile.lock
.ruby-version
10 changes: 10 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# I really just have issues with the automatic "semantic blocks"

ruby_version: 2.4

format: progress

ignore:
- 'spec/**/*':
- Lint/UselessAssignment
- Lint/Void
14 changes: 7 additions & 7 deletions lib/lumberjack_syslog_device.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'syslog'
require 'lumberjack'
require "syslog"
require "lumberjack"

module Lumberjack
# This Lumberjack device logs output to syslog. There can only be one connection to syslog
Expand All @@ -18,8 +18,8 @@ class SyslogDevice < Device
Severity::UNKNOWN => Syslog::LOG_ALERT
}

PERCENT = '%'
ESCAPED_PERCENT = '%%'
PERCENT = "%"
ESCAPED_PERCENT = "%%"

@@lock = Mutex.new

Expand Down Expand Up @@ -82,15 +82,15 @@ def write(entry)
def close
flush
@lock.synchronize do
@syslog.close if @syslog && @syslog.opened?
@syslog.close if @syslog&.opened?
end
end

private

# Open syslog with ident set to progname. If it is already open with a different
# ident, close it and reopen it.
def open_syslog(progname) #:nodoc:
def open_syslog(progname) # :nodoc:
syslog_impl = syslog_implementation
if syslog_impl.opened?
if (progname.nil? || syslog_impl.ident == progname) && @syslog_facility == syslog_impl.facility && @syslog_options == syslog_impl.options
Expand All @@ -105,7 +105,7 @@ def open_syslog(progname) #:nodoc:
end

# Provided for testing purposes
def syslog_implementation #:nodoc:
def syslog_implementation # :nodoc:
Syslog
end

Expand Down
18 changes: 9 additions & 9 deletions lumberjack_syslog_device.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Gem::Specification.new do |spec|
spec.name = 'lumberjack_syslog_device'
spec.name = "lumberjack_syslog_device"
spec.version = File.read(File.expand_path("../VERSION", __FILE__)).strip
spec.authors = ['Brian Durand']
spec.email = ['[email protected]']
spec.authors = ["Brian Durand"]
spec.email = ["[email protected]"]

spec.summary = "A logging device for the lumberjack gem that writes log entries to syslog."
spec.homepage = "https://github.com/bdurand/lumberjack_syslog_device"
spec.license = "MIT"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
ignore_files = %w(
ignore_files = %w[
.gitignore
.travis.yml
Appraisals
Expand All @@ -19,14 +19,14 @@ Gem::Specification.new do |spec|
Rakefile
gemfiles/
spec/
)
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject{ |f| ignore_files.any?{ |path| f.start_with?(path) } }
]
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| ignore_files.any? { |path| f.start_with?(path) } }
end

spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.required_ruby_version = '>=2.4'
spec.required_ruby_version = ">=2.4"

spec.add_dependency "lumberjack", ">=1.1"

Expand Down
13 changes: 6 additions & 7 deletions spec/lumberjack_syslog_device_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'
require "spec_helper"

describe Lumberjack::SyslogDevice do

let(:syslog) { MockSyslog.new }
let(:time) { Time.parse("2011-02-01T18:32:31Z") }
let(:entry) { Lumberjack::LogEntry.new(time, Lumberjack::Severity::WARN, "message 1", "lumberjack_syslog_device_spec", 12345, "foo" => "bar") }
Expand All @@ -15,14 +14,14 @@
end

it "should be able to specify syslog options" do
device = Lumberjack::SyslogDevice.new(:options => Syslog::LOG_CONS)
device = Lumberjack::SyslogDevice.new(options: Syslog::LOG_CONS)
allow(device).to receive(:syslog_implementation).and_return(syslog)
device.write(entry)
expect(syslog.options).to eq Syslog::LOG_CONS
end

it "should be able to specify a syslog facility" do
device = Lumberjack::SyslogDevice.new(:facility => Syslog::LOG_FTP)
device = Lumberjack::SyslogDevice.new(facility: Syslog::LOG_FTP)
allow(device).to receive(:syslog_implementation).and_return(syslog)
device.write(entry)
expect(syslog.facility).to eq Syslog::LOG_FTP
Expand All @@ -42,7 +41,7 @@
end

it "should close the syslog connection if :close_connection is true" do
device = Lumberjack::SyslogDevice.new(:close_connection => true)
device = Lumberjack::SyslogDevice.new(close_connection: true)
device.write(entry)
expect(Syslog).not_to be_opened
end
Expand Down Expand Up @@ -73,14 +72,14 @@
end

it "should be able to specify a string template" do
device = Lumberjack::SyslogDevice.new(:template => ":foo - :message")
device = Lumberjack::SyslogDevice.new(template: ":foo - :message")
allow(device).to receive(:syslog_implementation).and_return(syslog)
device.write(entry)
expect(syslog.output).to eq [[Syslog::LOG_WARNING, "bar - message 1"]]
end

it "should be able to specify a proc template" do
device = Lumberjack::SyslogDevice.new(:template => lambda{|e| e.message.upcase})
device = Lumberjack::SyslogDevice.new(template: lambda { |e| e.message.upcase })
allow(device).to receive(:syslog_implementation).and_return(syslog)
device.write(entry)
expect(syslog.output).to eq [[Syslog::LOG_WARNING, "MESSAGE 1"]]
Expand Down
7 changes: 2 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require_relative "../lib/lumberjack_syslog_device.rb"
require_relative "../lib/lumberjack_syslog_device"

# Mock object for testing Syslog since it's not available on many systems.
class MockSyslog

attr_reader :ident, :options, :facility, :mask, :output

def initialize
Expand All @@ -22,9 +21,7 @@ def opened?
@opened
end

def mask=(value)
@mask = value
end
attr_writer :mask

def log(severity, message)
@output << [severity, message]
Expand Down

0 comments on commit b0a5cf4

Please sign in to comment.