Skip to content

Commit

Permalink
Technical/Update CI/CD flow (#82)
Browse files Browse the repository at this point in the history
* Added new bunch of project linters
* Added auto deploy to RubyGems
* Added auto creating release notes on GitHub
* Added lefthook config, removed overcommit
* Updated gemspecs
* Updated codeclimate/circleci configs
* Updated gem development dependencies
* Updated gem version, changelog
  • Loading branch information
bestwebua authored Nov 30, 2022
1 parent fb30f4a commit 45e26e2
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 101 deletions.
90 changes: 75 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

version: 2.1

defaults: &defaults
Expand All @@ -6,26 +8,42 @@ defaults: &defaults
- image: cimg/ruby:<< parameters.ruby-version >>

orbs:
ruby: circleci/ruby@1.8.0
ruby: circleci/ruby@2.0.0

references:
restore_bundle_cache: &restore_bundle_cache
restore_cache:
keys:
- ruby-dns-mock-{{ checksum "dns_mock.gemspec" }}
paths:
- ~/vendor/bundle

bundle_install: &bundle_install
run:
name: Installing gems
command: |
bundle config set --local path 'vendor/bundle'
bundle config set --local path '~/vendor/bundle'
bundle install
save_bundle_cache: &save_bundle_cache
save_cache:
key: ruby-dns-mock-{{ checksum "dns_mock.gemspec" }}
paths:
- vendor/bundle
- ~/vendor/bundle

install_yamllint: &install_yamllint
run:
name: Installing Yamllint
command: |
sudo apt-get update -y
sudo apt-get install -y yamllint
install_lefthook: &install_lefthook
run:
name: Installing Lefthook
command: |
curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.deb.sh' | sudo -E bash
sudo apt-get install -y lefthook
install_codeclimate_reporter: &install_codeclimate_reporter
run:
Expand All @@ -37,14 +55,12 @@ references:
use_latest_gemspec: &use_latest_gemspec
run:
name: Using latest gemspec
command: |
cp .circleci/gemspec_latest dns_mock.gemspec
command: cp .circleci/gemspecs/latest dns_mock.gemspec

use_compatible_gemspec: &use_compatible_gemspec
run:
name: Using compatible gemspec
command: |
cp .circleci/gemspec_compatible dns_mock.gemspec
command: cp .circleci/gemspecs/compatible dns_mock.gemspec

jobs:
linters-ruby:
Expand All @@ -61,12 +77,23 @@ jobs:
- <<: *restore_bundle_cache
- <<: *bundle_install
- <<: *save_bundle_cache
- <<: *install_yamllint
- <<: *install_lefthook

- run:
name: Running code style linters
command: lefthook run code-style-linters

- run:
name: Running Overcommit
name: Running code performance linters
command: |
bundle exec overcommit -s
SKIP=AuthorEmail,AuthorName bundle exec overcommit -r
cp .circleci/linter_configs/.fasterer.yml .fasterer.yml
lefthook run code-performance-linters
rm .fasterer.yml
- run:
name: Running code vulnerability linters
command: lefthook run code-vulnerability-linters

tests-ruby:
parameters:
Expand Down Expand Up @@ -109,21 +136,43 @@ jobs:
parameters:
ruby-version:
type: string
docker:
- image: cimg/ruby:<< parameters.ruby-version >>

<<: *defaults

steps:
- checkout

- <<: *use_compatible_gemspec

- ruby/install-deps:
bundler-version: "2.3.22"
bundler-version: "2.3.26"
with-cache: false
path: './vendor/custom_bundle'
path: '~/vendor/custom_bundle'

- run:
name: Running compatibility tests
command: bundle exec rspec

releasing-gem-from-ruby:
parameters:
ruby-version:
type: string

<<: *defaults

steps:
- checkout

- add_ssh_keys:
fingerprints:
- "52:f6:00:b8:8e:08:12:41:61:65:b4:4c:10:93:43:39"

- run:
name: Publishing new release
command: ./.circleci/scripts/release.sh

workflows:
build_and_test:
build_test_deploy:
jobs:
- linters-ruby:
matrix:
Expand All @@ -137,3 +186,14 @@ workflows:
matrix:
parameters:
ruby-version: ["2.5", "2.6", "2.7", "3.0"]
- releasing-gem-from-ruby:
requires:
- linters-ruby
- tests-ruby
- compatibility-ruby
matrix:
parameters:
ruby-version: ["2.5"]
filters:
branches:
only: master
18 changes: 4 additions & 14 deletions .circleci/gemspec_compatible → .circleci/gemspecs/compatible
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@ Gem::Specification.new do |spec|
spec.version = DnsMock::VERSION
spec.authors = ['Vladislav Trotsenko']
spec.email = ['admin@bestweb.com.ua']

spec.summary = %(dns_mock)
spec.description = %(💎 Ruby DNS mock. Mimic any DNS records for your test environment and even more.)

spec.homepage = 'https://github.com/mocktools/ruby-dns-mock'
spec.license = 'MIT'

spec.metadata = {
'homepage_uri' => 'https://github.com/mocktools/ruby-dns-mock',
'changelog_uri' => 'https://github.com/mocktools/ruby-dns-mock/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/mocktools/ruby-dns-mock',
'documentation_uri' => 'https://github.com/mocktools/ruby-dns-mock/blob/master/README.md',
'bug_tracker_uri' => 'https://github.com/mocktools/ruby-dns-mock/issues'
}

spec.required_ruby_version = '>= 2.5.0'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
Expand All @@ -31,8 +21,8 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'

spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'rspec', '~> 3.11'
spec.add_development_dependency 'rspec-dns', '~> 0.1.8'
spec.add_development_dependency 'ffaker'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rspec-dns'
end
24 changes: 7 additions & 17 deletions .circleci/gemspec_latest → .circleci/gemspecs/latest
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@ Gem::Specification.new do |spec|
spec.version = DnsMock::VERSION
spec.authors = ['Vladislav Trotsenko']
spec.email = ['admin@bestweb.com.ua']

spec.summary = %(dns_mock)
spec.description = %(💎 Ruby DNS mock. Mimic any DNS records for your test environment and even more.)

spec.homepage = 'https://github.com/mocktools/ruby-dns-mock'
spec.license = 'MIT'

spec.metadata = {
'homepage_uri' => 'https://github.com/mocktools/ruby-dns-mock',
'changelog_uri' => 'https://github.com/mocktools/ruby-dns-mock/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/mocktools/ruby-dns-mock',
'documentation_uri' => 'https://github.com/mocktools/ruby-dns-mock/blob/master/README.md',
'bug_tracker_uri' => 'https://github.com/mocktools/ruby-dns-mock/issues'
}

spec.required_ruby_version = '>= 2.5.0'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
Expand All @@ -34,15 +24,15 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler-audit', '~> 0.9.1'
spec.add_development_dependency 'fasterer', '~> 0.10.0'
spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'net-ftp', '~> 0.1.3'
spec.add_development_dependency 'overcommit', '~> 0.59.1'
spec.add_development_dependency 'mdl', '~> 0.12.0'
spec.add_development_dependency 'net-ftp', '~> 0.2.0'
spec.add_development_dependency 'pry-byebug', '~> 3.10', '>= 3.10.1'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.1'
spec.add_development_dependency 'rspec', '~> 3.11'
spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.2'
spec.add_development_dependency 'rspec', '~> 3.12'
spec.add_development_dependency 'rspec-dns', '~> 0.1.8'
spec.add_development_dependency 'rubocop', '~> 1.36'
spec.add_development_dependency 'rubocop-performance', '~> 1.15'
spec.add_development_dependency 'rubocop-rspec', '~> 2.13', '>= 2.13.2'
spec.add_development_dependency 'rubocop', '~> 1.39'
spec.add_development_dependency 'rubocop-performance', '~> 1.15', '>= 1.15.1'
spec.add_development_dependency 'rubocop-rspec', '~> 2.15'
spec.add_development_dependency 'simplecov', '~> 0.21.2'
end
4 changes: 4 additions & 0 deletions .circleci/linter_configs/.bundler-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

ignore:
- EXA-MPLE-XXXX
5 changes: 5 additions & 0 deletions .circleci/linter_configs/.fasterer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

exclude_paths:
- '.circleci/**/*.rb'
- 'spec/dns_mock/record/builder/mx_spec.rb'
8 changes: 8 additions & 0 deletions .circleci/linter_configs/.mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

all
rule 'MD013', line_length: 500
rule 'MD029', style: :ordered
exclude_rule 'MD007'
exclude_rule 'MD010'
exclude_rule 'MD024'
23 changes: 13 additions & 10 deletions .rubocop.yml → .circleci/linter_configs/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
---

require:
- rubocop-rspec
- rubocop-performance

AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.5
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.5
SuggestExtensions: false
NewCops: enable

# Metrics ---------------------------------------------------------------------
Expand Down Expand Up @@ -66,13 +69,13 @@ Layout/ClassStructure:
- prepend
- extend
ExpectedOrder:
- module_inclusion
- constants
- public_class_methods
- initializer
- public_methods
- protected_methods
- private_methods
- module_inclusion
- constants
- public_class_methods
- initializer
- public_methods
- protected_methods
- private_methods

Layout/EmptyLineAfterGuardClause:
Enabled: false
Expand Down
5 changes: 5 additions & 0 deletions .circleci/linter_configs/.yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

rules:
line-length:
max: 200
58 changes: 58 additions & 0 deletions .circleci/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# !/bin/sh
set -e

RELEASES_URL="https://github.com/cli/cli/releases"
FILE_NAME="gh"
BUILD_ARCHITECTURE="linux_amd64.deb"
DELIMETER="_"
PACKAGE_FILE="$FILE_NAME$DELIMETER$BUILD_ARCHITECTURE"

gh_cli_latest_release() {
curl -sL -o /dev/null -w %{url_effective} "$RELEASES_URL/latest" | rev | cut -f1 -d'/'| rev
}

download_gh_cli() {
test -z "$VERSION" && VERSION="$(gh_cli_latest_release)"
test -z "$VERSION" && {
echo "Unable to get GitHub CLI release." >&2
exit 1
}
curl -s -L -o "$PACKAGE_FILE" "$RELEASES_URL/download/$VERSION/$FILE_NAME$DELIMETER${VERSION:1}$DELIMETER$BUILD_ARCHITECTURE"
}

install_gh_cli() {
sudo dpkg -i "$PACKAGE_FILE"
rm "$PACKAGE_FILE"
}

get_release_candidate_version() {
echo $(ruby -r rubygems -e "puts Gem::Specification::load('$(ls *.gemspec)').version")
}

release_candidate_tag="v$(get_release_candidate_version)"

is_an_existing_github_release() {
git fetch origin "refs/tags/$release_candidate_tag" >/dev/null 2>&1
}

release_to_rubygems() {
echo "Setting RubyGems publisher credentials..."
./.circleci/scripts/set_publisher_credentials.sh
echo "Publishing new gem release to RubyGems..."
git stash
git checkout develop
rake release
}

release_to_github() {
echo "Downloading and installing latest gh cli..."
download_gh_cli
install_gh_cli
echo "Publishing new release notes to GitHub..."
gh release create "$release_candidate_tag" --generate-notes
}

if is_an_existing_github_release
then echo "Tag $release_candidate_tag already exists on GitHub. Skipping releasing flow..."
else release_to_rubygems; release_to_github
fi
12 changes: 12 additions & 0 deletions .circleci/scripts/set_publisher_credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# !/bin/sh
set -e
set +x
mkdir -p ~/.gem

cat << EOF > ~/.gem/credentials
---
:rubygems_api_key: ${RUBYGEMS_API_KEY}
EOF

chmod 0600 ~/.gem/credentials
set -x
4 changes: 3 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-1-36
channel: rubocop-1-39
config:
file: .circleci/linter_configs/.rubocop.yml

reek:
enabled: true
Loading

0 comments on commit 45e26e2

Please sign in to comment.