Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech 4449 appraisal phase 1 #19

Merged
merged 11 commits into from
May 15, 2020
10 changes: 10 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
version: 1
update_configs:
- package_manager: "ruby:bundler"
directory: "/"
update_schedule: "live"
version_requirement_updates: "off"
commit_message:
prefix: "No-Jira"
include_scope: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline here I think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like my script isn't adding the newline to the end 👎 i've gone ahead and added it

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ build-iPhoneSimulator/

# rubocop
.rubocop-https---raw-githubusercontent-com-Invoca-style-guide-master-ruby--rubocop-yml

# appraisal
gemfiles/*.lock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting--I'd missed this subtlety. The appraisals generate a fresh Gemfile.lock each time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, this is a best practice set by the appraisals gem to make sure that the appraisal is always tested against the most recent version of the lock. it leans very heavily on semantic versioning and locking.

85 changes: 85 additions & 0 deletions .jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/groovy
@Library('jenkins-pipeline@v0.4.5')
import com.invoca.docker.*;
pipeline {
agent {
kubernetes {
defaultContainer "ruby"
yamlFile ".jenkins/ruby_build_pod.yml"
}
}

environment { GITHUB_TOKEN = credentials('github_token') }

stages {
stage('Setup') {
steps {
script {
updateGitHubStatus('clean-build', 'pending', 'Unit tests.')
sh 'bundle install'
sh 'bundle exec appraisal install'
}
}
}
stage('Appraisals') {
parallel {
stage('Current') {
steps {
sh 'bundle exec rspec --format RspecJunitFormatter --out spec/reports/current/rspec.xml'
}

post {
always { junit 'spec/reports/current/*.xml' }
}
}

stage('Rails 4') {
steps {
sh 'bundle exec appraisal rails-4 rspec --format RspecJunitFormatter --out spec/reports/rails4/rspec.xml'
}

post {
always { junit 'spec/reports/rails4/*.xml' }
}
}

stage('Rails 5') {
steps {
sh 'bundle exec appraisal rails-5 rspec --format RspecJunitFormatter --out spec/reports/rails5/rspec.xml'
}

post {
always { junit 'spec/reports/rails5/*.xml' }
}
}

stage('Rails 6') {
steps {
sh 'bundle exec appraisal rails-6 rspec --format RspecJunitFormatter --out spec/reports/rails6/rspec.xml'
}

post {
always { junit 'spec/reports/rails6/*.xml' }
}
}
}

post {
success { updateGitHubStatus('clean-build', 'success', 'Unit tests.') }
failure { updateGitHubStatus('clean-build', 'failure', 'Unit tests.') }
}
}
}
}

void updateGitHubStatus(String context, String status, String description) {
gitHubStatus([
repoSlug: 'Invoca/contextual_logger',
sha: env.GIT_COMMIT,
description: description,
context: context,
targetURL: env.RUN_DISPLAY_URL,
token: env.GITHUB_TOKEN,
status: status
])
}
18 changes: 18 additions & 0 deletions .jenkins/ruby_build_pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins/contextual-logger: 'true'
namespace: jenkins
name: contextual_logger
spec:
containers:
- name: ruby
image: ruby:2.6.5
tty: true
resources:
requests:
memory: "100Mi"
command:
- cat
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.6.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the hyphen file best practice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.ruby_version isn't picked up by rbenv only .ruby-version is. so the file name change was necessary for the configuration to take affect.

1 change: 0 additions & 1 deletion .ruby_version

This file was deleted.

13 changes: 13 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

appraise 'rails-4' do
gem 'activesupport', '~> 4.2'
end

appraise 'rails-5' do
gem 'activesupport', '~> 5.2'
end

appraise 'rails-6' do
gem 'activesupport', '~> 6.0'
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 So clean!

13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.0] - Unreleased
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I have 0.7.0 also in a branch. We may be able to release those together.

### Added
- Added support for rails 5 and 6.
- Added appraisal tests for all supported rails version: 4/5/6

### Changed
- Updated various test to be compatible with rails version 4/5/6
- Updated the CI pipeline to test against all three supported versions of rails

### Fixed
- Fixed undefined method `delegate` bug in ActiveSupport version 4

## [0.6.1] - 2020-04-03
### Fixed
- Gemspec to point to correct source code uri
Expand Down Expand Up @@ -35,6 +47,7 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
- Extracted `ContextualLogger.normalize_log_level` into a public class method so we can call it elsewhere where we allow log_level to be
configured to text values like 'debug'.

[0.7.0]: https://github.com/Invoca/contextual_logger/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/Invoca/contextual_logger/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/Invoca/contextual_logger/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/Invoca/contextual_logger/compare/v0.5.0...v0.5.1
Expand Down
25 changes: 11 additions & 14 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ gemspec

gem 'coveralls', require: false

group :development do
gem 'activesupport'
gem 'bump', '~> 0.6.1'
gem 'pry'
gem 'rake'
gem 'rubocop', '0.54.0'
gem 'rubocop-git'
gem 'ruby-prof'
gem 'ruby-prof-flamegraph'
end
gem 'activesupport'
gem 'appraisal'
gem 'bump', '~> 0.6.1'
gem 'pry'
gem 'rake'
gem 'rubocop', '0.54.0'
gem 'rubocop-git'
gem 'ruby-prof'
gem 'ruby-prof-flamegraph'

group :test do
gem 'rspec'
gem 'rspec_junit_formatter'
end
gem 'rspec'
gem 'rspec_junit_formatter'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for simplifying here!

7 changes: 6 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
contextual_logger (0.6.1)
contextual_logger (0.7.0)
activesupport
json

Expand All @@ -13,6 +13,10 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
appraisal (2.2.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.0)
bump (0.6.1)
coderay (1.1.2)
Expand Down Expand Up @@ -86,6 +90,7 @@ PLATFORMS

DEPENDENCIES
activesupport
appraisal
bump (~> 0.6.1)
contextual_logger!
coveralls
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# ContextualLogger [![Build Status](https://travis-ci.org/Invoca/contextual_logger.svg?branch=master)](https://travis-ci.org/Invoca/contextual_logger) [![Coverage Status](https://coveralls.io/repos/github/Invoca/contextual_logger/badge.svg?branch=master)](https://coveralls.io/github/Invoca/contextual_logger?branch=master) [![Gem Version](https://badge.fury.io/rb/contextual_logger.svg)](https://badge.fury.io/rb/contextual_logger)
This gem adds the ability to your ruby logger, to accept conditional context, and utilize it when formatting your log entry.

## Dependencies
* Ruby >= 2.6
* ActiveSupport >= 4.2, < 7

## Installation
To install this gem directly on your machine from rubygems, run the following:
```ruby
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_RETRY: "1"
18 changes: 18 additions & 0 deletions gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "coveralls", require: false
gem "activesupport", "~> 4.2"
gem "appraisal"
gem "bump", "~> 0.6.1"
gem "pry"
gem "rake"
gem "rubocop", "0.54.0"
gem "rubocop-git"
gem "ruby-prof"
gem "ruby-prof-flamegraph"
gem "rspec"
gem "rspec_junit_formatter"

gemspec path: "../"
18 changes: 18 additions & 0 deletions gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "coveralls", require: false
gem "activesupport", "~> 5.2"
gem "appraisal"
gem "bump", "~> 0.6.1"
gem "pry"
gem "rake"
gem "rubocop", "0.54.0"
gem "rubocop-git"
gem "ruby-prof"
gem "ruby-prof-flamegraph"
gem "rspec"
gem "rspec_junit_formatter"

gemspec path: "../"
18 changes: 18 additions & 0 deletions gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "coveralls", require: false
gem "activesupport", "~> 6.0"
gem "appraisal"
gem "bump", "~> 0.6.1"
gem "pry"
gem "rake"
gem "rubocop", "0.54.0"
gem "rubocop-git"
gem "ruby-prof"
gem "ruby-prof-flamegraph"
gem "rspec"
gem "rspec_junit_formatter"

gemspec path: "../"
1 change: 1 addition & 0 deletions lib/contextual_logger.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'active_support'
require 'active_support/core_ext/module/delegation'
require 'json'
require_relative './contextual_logger/redactor'
require_relative './contextual_logger/context/handler'
Expand Down
2 changes: 1 addition & 1 deletion lib/contextual_logger/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ContextualLogger
VERSION = '0.6.1'
VERSION = '0.7.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
describe 'ContextualLogger::Overrides::ActiveSupport::TaggedLogging::Formatter' do
before do
Time.now_override = Time.now
@logger = ContextualLogger.new(Logger.new('/dev/null'))
@logger = Logger.new('/dev/null')
@logger.formatter = ->(_, _, _, msg_with_context) { "#{msg_with_context.to_json}\n" }
@logger = ActiveSupport::TaggedLogging.new(@logger)
@logger = ContextualLogger.new(@logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuck, I hadn't noticed how this overwrites @logger! I will fix that on my branch.

end

it 'should log log_tags as additional context' do
Expand Down