Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Add publish pipeline #155

Merged
merged 5 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
version: 2.0
init: &init
run:
name: init
command: |
echo '. .circleci/shared.bash' >> "$BASH_ENV"

jobs:
test:
environment:
Expand All @@ -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
35 changes: 35 additions & 0 deletions .circleci/shared.bash
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.11.4
2 changes: 1 addition & 1 deletion codeclimate-services.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["[email protected]"]
spec.summary = "Service classes for Code Climate"
Expand Down
6 changes: 5 additions & 1 deletion lib/cc/services/version.rb
Original file line number Diff line number Diff line change
@@ -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