Skip to content

Commit

Permalink
Migrate to GitHub actions
Browse files Browse the repository at this point in the history
- Add test and publish workflows
- Format codebase using StandardRB
- Refactor CLI interface
  • Loading branch information
krmbzds committed Mar 16, 2022
1 parent aa3a095 commit 7668bb1
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 111 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish

on:
release:
types: [published]

jobs:
build:
name: Publish Packages
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Publish to RubyGems
uses: dawidd6/action-publish-gem@v1
with:
api_key: ${{secrets.RUBYGEMS_AUTH_TOKEN}}

53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test

on:
pull_request:

push:
branches: [ develop, master ]

env:
GIT_COMMIT_SHA: ${{ github.sha }}
GIT_BRANCH: ${{ github.ref }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

jobs:

lint:
runs-on: ubuntu-latest
name: lint ${{ matrix.ruby }}
strategy:
fail-fast: false
matrix:
ruby: [ '2.6.9', '2.7.5', '3.0.3', '3.1.1' ]

steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: StandardRB
continue-on-error: ${{ matrix.experimental }}
run: bundle exec standardrb --parallel --format progress

test:
needs: [ lint ]
runs-on: ubuntu-latest
name: test ${{ matrix.ruby }}
strategy:
fail-fast: false
matrix:
ruby: [ '2.6.9', '2.7.5', '3.0.3', '3.1.1' ]

steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Test
continue-on-error: ${{ matrix.experimental }}
run: bundle exec rake
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.1.1
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

13 changes: 4 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in turkish_id.gemspec
gemspec
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

group :test do
gem 'bundler'
gem 'rake'
gem 'rspec'
gem 'simplecov'
end
# Specify your gem's dependencies in viabtc.gemspec
gemspec
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Kerem Bozdas
Copyright (c) 2015-2022 Kerem Bozdas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Turkish ID 🔖

[![Build Status](https://travis-ci.org/krmbzds/turkish_id.svg?branch=master)](https://travis-ci.org/krmbzds/turkish_id) [![Gem](https://img.shields.io/gem/v/turkish_id.svg)](https://github.com/krmbzds/turkish_id) [![Dependencies](https://img.shields.io/badge/dependencies-none-brightgreen.svg)](https://rubygems.org/gems/turkish_id) [![Gem](https://img.shields.io/gem/dt/turkish_id.svg)](https://rubygems.org/gems/turkish_id) [![Code Climate](https://codeclimate.com/github/krmbzds/turkish_id/badges/gpa.svg)](https://codeclimate.com/github/krmbzds/turkish_id) [![Test Coverage](https://codeclimate.com/github/krmbzds/turkish_id/badges/coverage.svg)](https://codeclimate.com/github/krmbzds/turkish_id/coverage)
[![Status](https://img.shields.io/github/workflow/status/krmbzds/turkish_id/Test/master)](https://github.com/krmbzds/turkish_id/actions/workflows/test.yml)
[![Coverage](https://img.shields.io/coveralls/github/krmbzds/turkish_id)](https://coveralls.io/github/krmbzds/turkish_id)
[![Downloads](https://img.shields.io/gem/dt/turkish_id.svg)](https://rubygems.org/gems/turkish_id)
[![Dependencies](https://img.shields.io/badge/dependencies-none-brightgreen.svg)](https://rubygems.org/gems/turkish_id)
[![Maintainability](https://img.shields.io/codeclimate/maintainability/krmbzds/turkish_id)](https://codeclimate.com/github/krmbzds/turkish_id)
[![Version](https://img.shields.io/gem/v/turkish_id.svg)](https://github.com/krmbzds/turkish_id)
[![Docs](https://img.shields.io/badge/rubydoc-info-blue.svg)](https://www.rubydoc.info/gems/turkish_id)

This gem provides methods to validate Turkish Identification Numbers.

Expand Down Expand Up @@ -39,7 +45,10 @@ identity_number.valid? #=> true
Or use the command line executable:

```sh
$ turkish_id 10000000078 #=> Your identification number is valid.
$ turkish_id 10000000078 #=> true
$ echo $? #=> 0
$ turkish_id 10000000079 #=> false
$ echo $? #=> 1
```

### Generating Relatives
Expand Down Expand Up @@ -98,9 +107,10 @@ Remember that a valid identification number does not imply the existence of an I

This gem is used in production and tested against the following Ruby versions:

-`2.7.1` (stable)
-`2.6.6` (stable)
-`2.5.8` (security maintenance)
-`3.1.1` (stable)
-`3.0.3` (stable)
-`2.7.5` (stable)
-`2.6.9` (security maintenance)

## Development

Expand All @@ -126,7 +136,7 @@ Yes.

## License

Copyright © 2019 [Kerem Bozdas][Personal Webpage]
Copyright © 2015-2022 [Kerem Bozdas][Personal Webpage]

This gem is available under the terms of the [MIT License][License].

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)
task default: :spec
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'turkish_id'
require "bundler/setup"
require "turkish_id"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require 'irb'
require "irb"
IRB.start
Empty file modified bin/setup
100644 → 100755
Empty file.
27 changes: 8 additions & 19 deletions bin/turkish_id
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)

require 'turkish_id'
require "turkish_id"

@help = '
Usage
Expand All @@ -16,21 +16,10 @@ require 'turkish_id'
'

def parse_input
ARGV[0] ? validate_id(ARGV[0]) : print_help
if ARGV[0]
result = TurkishId.new(ARGV[0]).valid?
$stdout.puts result
exit result ? 0 : 1
else
$stdout.puts @help
end

def validate_id(id_number)
identity_number = TurkishId.new(id_number)
print_result(identity_number.valid?)
end

def print_result(result)
STDOUT.puts "Your identification number is #{result ? 'valid' : 'invalid'}."
end

def print_help
STDOUT.puts @help
end

parse_input
8 changes: 4 additions & 4 deletions lib/turkish_id.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'turkish_id/version'
require "turkish_id/version"

class TurkishId
attr_reader :id_number, :checksum, :elder_relative, :younger_relative
Expand Down Expand Up @@ -32,7 +32,7 @@ def calculate_checksum(id_array)

# Return checksum
[d10, d11]
rescue StandardError
rescue
[]
end

Expand All @@ -42,7 +42,7 @@ def append_checksum(id)
end

def next_relative(id_array, direction)
tree = { up: 1, down: -1 }
tree = {up: 1, down: -1}
get_core(id_array) + 29_999 * tree[direction]
end

Expand All @@ -60,7 +60,7 @@ def generate_relatives(id_array, direction)

def get_id_array(id)
split_num(Integer(id))
rescue StandardError
rescue
[]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/turkish_id/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class TurkishId
VERSION = '1.3.0'
VERSION = "1.3.0"
end
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'simplecov'
SimpleCov.start
require "coveralls"
Coveralls.wear!

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'turkish_id'
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "turkish_id"
Loading

0 comments on commit 7668bb1

Please sign in to comment.