Circle CI - custom workflow

Arun Kumar
2 min readMay 23, 2021

We are rails workshop and doing continuous integration on CircleCI.

Business requirements

Our app is serving customers from different countries. Internationalization is key in our app. Rails provides very good support for i18n and takes care of most.

However we have loop whole in our workflow where devs tend to push I18n files with incomplete information, i.e. setting up messages for EN version and left incomplete for other countries. We tried to tighten the process to ensure I18n files are always updated with all language versions.

Since devs are not good at messaging part, during the development we setup yaml file with draft version in English, and keeping other language empty (Chinese, Japanese parts blank to be filled). like

home:
title:
en: MyApp Dashboard
ch: # not set
sw: # not set

There are cases we miss the messages and customers caught in production 🤯

Setting up custom workflows..

Since CI provides 1-to-many jobs under workflow, we have configured custom workflow to catch above.

When dev makes a commit and push to Github; it automatically triggers build (Straightforward). In CI workflow we do following.

  • Run test suite (rspec or minitest)
  • Run rubocop (coding standards)
  • Run translations checks..

For each build → it triggers above jobs in parallel. As you can see we have “Translations Checks” Job.. The way it configured in circle.yml configuration as be

workflows:
commit:
jobs:
- environment-setup
- coding-standards:
requires:
- environment-setup
- test-suit:
requires:
- environment-setup
- translations:
requires:
- environment-setup
---------------------------------------
executors:
rails-app:
docker:
- image: circleci/ruby:2.5.x
environment:
RAILS_ENV: test
- image: circleci/mysql
working_directory: *working_directory
---------------------------------------
jobs:
environment-setup:
executor: rails-app
steps:
- run: sudo apt-get update
.....
coding-standards:
executor: rails-app
steps:
- prepare_workspace
- run:
name: Coding standards
command: bundle exec rubocop
translations:
executor: rails-app
steps:
- prepare_workspace
- run:
name: Translations
command: bundle exec rake myapp:translations
test-suit:
executor: rails-app
parallelism: 10
steps:
- prepare_workspace
- run: sudo apt-get update
- run:
name: Setup database.yml
command: |
---------------------------------------

configure rake task for translations

namespace :myapp do
task :translations do
puts "> Loading i18n files..."
require_relative 'lib/myapp_i18n_check'
MyAppI18nCheck.new.run
end
end

configure i18n checker

class MyAppI18nCheck
def initialize
@files = []
end
def run
scan_i18n_files
validate_and_exit
end
def scan_i18n_files
Dir.glob('config/locales/*.yml').sort.each do |folder|
folder.files.each do |file|
# if a target path has been passed in, only process that one
file = File.read(path)
if file.missing_translation?
@files << path
end
end
end
end
def validate_and_exit
if @files.blank?
exit 0 # successful exit
else
@files.each. { |file|
puts "File: #{file}"
}
exit 1 # error exit
end
end
end

Now we have integrated I18n incorrect files as part of CI. 🔗And in github we enabled “translations” check as “required”. This worked well for us 💯..

Above is example of how we integrated custom job with circle ci and github checks.. It may not be same for your applications, but you can do other custom checks based on your needs..

Hope above helpful..

--

--

Arun Kumar
0 Followers

I am rails developer, also leading development team to build application to serve customers from multiple regions.