diff --git a/.circleci/config.yml b/.circleci/config.yml index 97da530..c5043b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,10 @@ version: 2.0 +init: &init + run: + name: init + command: | + echo '. .circleci/shared.bash' >> "$BASH_ENV" + jobs: test: environment: @@ -19,8 +25,33 @@ jobs: - coverage - run: ./cc-test-reporter after-build --exit-code $? || echo "Send coverage skipped..." + publish: + machine: true + steps: + - checkout + - *init + - run: + name: Install Hub dependency + command: install_hub + - run: + name: Login on RubyGems + command: login_to_rubygems + - run: + name: Publish new version + command: | + if [ `git diff --quiet HEAD~ VERSION; echo $?` -eq 1 ]; then + publish_new_version + fi + workflows: version: 2 test: jobs: - test + - publish: + requires: + - test + filters: + branches: + only: + - master diff --git a/.circleci/shared.bash b/.circleci/shared.bash new file mode 100644 index 0000000..d67af7d --- /dev/null +++ b/.circleci/shared.bash @@ -0,0 +1,35 @@ +#!/bin/bash + +set -exuo pipefail + +VERSION=$(cat VERSION) + +function install_hub() { + sudo apt update && sudo apt install -y git wget + url="$(wget -qO- https://api.github.com/repos/github/hub/releases/latest | tr '"' '\n' | grep '.*/download/.*/hub-linux-amd64-.*.tgz')" + wget -qO- "$url" | sudo tar -xzvf- -C /usr/bin --strip-components=2 --wildcards "*/bin/hub" +} + +function login_to_rubygems() { + mkdir -p "$HOME/.gem" + touch "$HOME/.gem/credentials" + chmod 0600 "$HOME/.gem/credentials" + printf -- "---\n:rubygems_api_key: %s\n" "$GEM_HOST_API_KEY" > "$HOME/.gem/credentials" +} + +function tag_version() { + GITHUB_TOKEN="${GITHUB_TOKEN}" hub release create -m "v${VERSION}" "v${VERSION}" +} + + +function publish_new_version() { + set +x + # Build and push gem + gem build ./*.gemspec + gem push ./*.gem + + # Create gh tag + tag_version + + set -x +} diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..3d0e623 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.11.4 diff --git a/codeclimate-services.gemspec b/codeclimate-services.gemspec index b2d44b4..339bda4 100644 --- a/codeclimate-services.gemspec +++ b/codeclimate-services.gemspec @@ -5,7 +5,7 @@ require "cc/services/version" Gem::Specification.new do |spec| spec.name = "codeclimate-services" - spec.version = CC::Services::VERSION + spec.version = CC::Services.version spec.authors = ["Bryan Helmkamp"] spec.email = ["bryan@brynary.com"] spec.summary = "Service classes for Code Climate" diff --git a/lib/cc/services/version.rb b/lib/cc/services/version.rb index a8551b2..6af1080 100644 --- a/lib/cc/services/version.rb +++ b/lib/cc/services/version.rb @@ -1,5 +1,9 @@ module CC module Services - VERSION = "1.11.3".freeze + def version + path = File.expand_path("../../../../VERSION", __FILE__) + @version ||= File.read(path).strip + end + module_function :version end end