Skip to content

Commit

Permalink
Merge pull request #94 from truemail-rb/develop
Browse files Browse the repository at this point in the history
Truemail server v0.7.0
  • Loading branch information
bestwebua authored Mar 11, 2023
2 parents a96ba48 + f621d39 commit 544de10
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 142 deletions.
101 changes: 87 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
---

version: 2.1

defaults: &defaults
working_directory: ~/truemail-server
docker:
- image: cimg/ruby:3.2.0
- image: cimg/ruby:3.2.0-node

references:
install_bundler: &install_bundler
run:
name: Installing bundler
command: gem i bundler -v $(tail -1 Gemfile.lock | tr -d ' ')
command: |
gem i bundler -v $(tail -1 Gemfile.lock | tr -d ' ')
bundle config set --local path '~/vendor/bundle'
restore_bundle_cache: &restore_bundle_cache
restore_cache:
keys:
- truemail-server-{{ checksum "Gemfile" }}
- truemail-server-{{ checksum "Gemfile.lock" }}
paths:
- ~/vendor/bundle

bundle_install: &bundle_install
run:
name: Installing gems
command: |
bundle config set --local path 'vendor/bundle'
bundle install
command: bundle install

save_bundle_cache: &save_bundle_cache
save_cache:
key: truemail-server-{{ checksum "Gemfile" }}
key: truemail-server-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- ~/vendor/bundle

install_linters: &install_linters
run:
name: Installing bunch of linters
command: |
curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.deb.sh' | sudo -E bash
sudo apt-get update -y
sudo apt-get install -y lefthook shellcheck yamllint
npm install --prefix='~/.local' --global --save-dev git+https://github.com/streetsidesoftware/cspell-cli markdownlint-cli
cp .circleci/linter_configs/.fasterer.yml .fasterer.yml
cp .circleci/linter_configs/.lefthook.yml lefthook.yml
install_codeclimate_reporter: &install_codeclimate_reporter
run:
Expand All @@ -34,7 +51,6 @@ references:
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
version: 2
jobs:
linters:
<<: *defaults
Expand All @@ -46,12 +62,27 @@ jobs:
- <<: *restore_bundle_cache
- <<: *bundle_install
- <<: *save_bundle_cache
- <<: *install_linters

- run:
name: Running Overcommit
command: |
bundle exec overcommit -s
SKIP=AuthorEmail,AuthorName bundle exec overcommit -r
name: Running code style linters
command: lefthook run code-style-linters

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

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

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

- run:
name: Running release linters
command: lefthook run release-linters

tests:
<<: *defaults
Expand Down Expand Up @@ -86,9 +117,51 @@ jobs:
command: |
./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
tag:
<<: *defaults

steps:
- checkout

- add_ssh_keys:
fingerprints:
- "4c:59:4d:fb:7a:74:00:7a:8e:e3:72:88:34:fc:6e:74"

- run:
name: Publishing new tag to GitHub
command: |
./.circleci/scripts/tag.sh
release:
<<: *defaults

steps:
- checkout

- add_ssh_keys:
fingerprints:
- "4c:59:4d:fb:7a:74:00:7a:8e:e3:72:88:34:fc:6e:74"

- run:
name: Publishing new release to GitHub
command: |
./.circleci/scripts/release.sh
workflows:
version: 2
build:
jobs:
- linters
- tests
- tag:
requires:
- linters
- tests
filters:
branches:
only: master
- release:
filters:
branches:
ignore: /.*/
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
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
31 changes: 31 additions & 0 deletions .circleci/linter_configs/.cspell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

enableGlobDot: true

patterns:
- name: GithubUser
pattern: /\[@.+\]/gmx
- name: MarkdownCode
pattern: /`{1,3}.+`{1,3}/gmx
- name: MarkdownCodeBlock
pattern: /^\s*```[\s\S]*?^\s*```/gmx

languageSettings:
- languageId: markdown
ignoreRegExpList:
- Email
- GithubUser
- MarkdownCode
- MarkdownCodeBlock

words:
- Commiting
- Gitter
- Healthcheck
- Trotsenko
- Truemail
- Vladislav
- bestwebua
- codebases
- dockerized
- nameserver's
4 changes: 4 additions & 0 deletions .circleci/linter_configs/.fasterer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

exclude_paths:
- '.circleci/**/*.rb'
39 changes: 39 additions & 0 deletions .circleci/linter_configs/.lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---

no_tty: true
skip_output:
- meta

code-style-linters:
commands:
reek:
run: bundle exec reek
rubocop:
run: bundle exec rubocop -c '.circleci/linter_configs/.rubocop.yml'
shellcheck:
glob: '*.{sh}'
run: shellcheck --norc {all_files}
yamllint:
run: yamllint -c '.circleci/linter_configs/.yamllint.yml' .

code-performance-linters:
commands:
fasterer:
run: bundle exec fasterer

code-vulnerability-linters:
commands:
bundle-audit:
run: bundle exec bundle-audit check -c '.circleci/linter_configs/.bundler-audit.yml' --update

code-documentation-linters:
commands:
cspell:
run: cspell-cli lint -c '.circleci/linter_configs/.cspell.yml' '**/*.{txt,md}'
markdownlint:
run: markdownlint -c '.circleci/linter_configs/.markdownlint.yml' '**/*.md'

release-linters:
commands:
changeloglint:
run: .circleci/scripts/changeloglint.sh
9 changes: 9 additions & 0 deletions .circleci/linter_configs/.markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

default: true

MD013:
line_length: 500

MD024:
siblings_only: true
24 changes: 13 additions & 11 deletions .rubocop.yml → .circleci/linter_configs/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---

require:
- rubocop-rspec
- rubocop-performance


AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 3.1
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 3.2
NewCops: enable

# Style -----------------------------------------------------------------------
Expand Down Expand Up @@ -65,14 +67,14 @@ Layout/ClassStructure:
- belongs_to
- has_and_belongs_to_many
ExpectedOrder:
- module_inclusion
- constants
- associations
- public_class_methods
- initializer
- public_methods
- protected_methods
- private_methods
- module_inclusion
- constants
- associations
- public_class_methods
- initializer
- public_methods
- protected_methods
- private_methods

# Lint ------------------------------------------------------------------------

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

extends: default

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

changelog=$(if [ "$1" = "" ]; then echo "CHANGELOG.md"; else echo "$1"; fi)

get_current_application_version() {
ruby -r rubygems -e "require_relative 'app/truemail_server/version'; puts TruemailServer::VERSION"
}

latest_changelog_tag() {
grep -Po "(?<=\#\# \[)[0-9]+\.[0-9]+\.[0-9]+?(?=\])" "$changelog" | head -n 1
}

current_application_version="$(get_current_application_version)"

if [ "$current_application_version" = "$(latest_changelog_tag)" ]
then
echo "SUCCESS: Current application version ($current_application_version) has been found on the top of project changelog."
else
echo "FAILURE: Following to \"Keep a Changelog\" convention current application version ($current_application_version) must be mentioned on the top of project changelog."
exit 1
fi
42 changes: 42 additions & 0 deletions .circleci/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
set -e

GH_CLI_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}' "$GH_CLI_RELEASES_URL/latest" | rev | cut -f 1 -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" "$GH_CLI_RELEASES_URL/download/$VERSION/$FILE_NAME$DELIMETER$(printf '%s' "$VERSION" | cut -c 2-100)$DELIMETER$BUILD_ARCHITECTURE"
}

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

get_release_candidate_tag() {
git tag --sort=v:refname | grep -E "v[0-9]+\.[0-9]+\.[0-9]+" | tail -n 1
}

RELEASE_CANDIDATE_TAG=$(get_release_candidate_tag)

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
}

release_to_github
30 changes: 30 additions & 0 deletions .circleci/scripts/tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
set -e

SEMVER_REGEX_PATTERN="[0-9]+\.[0-9]+\.[0-9]+"

latest_changelog_tag() {
grep -Po "(?<=\#\# \[)$SEMVER_REGEX_PATTERN?(?=\])" CHANGELOG.md | head -n 1
}

latest_git_tag() {
git tag --sort=v:refname | grep -E "v$SEMVER_REGEX_PATTERN" | tail -n 1
}

TAG_CANDIDATE="v$(latest_changelog_tag)"

if [ "$TAG_CANDIDATE" != "$(latest_git_tag)" ]
then
echo "Configuring git..."
git config --global user.email "${PUBLISHER_EMAIL}"
git config --global user.name "${PUBLISHER_NAME}"
echo "Pushing new semver tag to GitHub..."
git tag "$TAG_CANDIDATE"
git push --tags
echo "Updating develop branch with new semver tag..."
git checkout develop
git merge "$TAG_CANDIDATE" --ff --no-edit
git push origin develop
else
echo "Latest changelog tag ($TAG_CANDIDATE) already released on GitHub. Tagging is not required."
fi
Loading

0 comments on commit 544de10

Please sign in to comment.