Skip to content

Commit 5420bac

Browse files
authored
Add publish pipeline (#155)
Automate gem publish
1 parent a003dad commit 5420bac

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

.circleci/config.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
version: 2.0
2+
init: &init
3+
run:
4+
name: init
5+
command: |
6+
echo '. .circleci/shared.bash' >> "$BASH_ENV"
7+
28
jobs:
39
test:
410
environment:
@@ -19,8 +25,33 @@ jobs:
1925
- coverage
2026
- run: ./cc-test-reporter after-build --exit-code $? || echo "Send coverage skipped..."
2127

28+
publish:
29+
machine: true
30+
steps:
31+
- checkout
32+
- *init
33+
- run:
34+
name: Install Hub dependency
35+
command: install_hub
36+
- run:
37+
name: Login on RubyGems
38+
command: login_to_rubygems
39+
- run:
40+
name: Publish new version
41+
command: |
42+
if [ `git diff --quiet HEAD~ VERSION; echo $?` -eq 1 ]; then
43+
publish_new_version
44+
fi
45+
2246
workflows:
2347
version: 2
2448
test:
2549
jobs:
2650
- test
51+
- publish:
52+
requires:
53+
- test
54+
filters:
55+
branches:
56+
only:
57+
- master

.circleci/shared.bash

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -exuo pipefail
4+
5+
VERSION=$(cat VERSION)
6+
7+
function install_hub() {
8+
sudo apt update && sudo apt install -y git wget
9+
url="$(wget -qO- https://api.github.com/repos/github/hub/releases/latest | tr '"' '\n' | grep '.*/download/.*/hub-linux-amd64-.*.tgz')"
10+
wget -qO- "$url" | sudo tar -xzvf- -C /usr/bin --strip-components=2 --wildcards "*/bin/hub"
11+
}
12+
13+
function login_to_rubygems() {
14+
mkdir -p "$HOME/.gem"
15+
touch "$HOME/.gem/credentials"
16+
chmod 0600 "$HOME/.gem/credentials"
17+
printf -- "---\n:rubygems_api_key: %s\n" "$GEM_HOST_API_KEY" > "$HOME/.gem/credentials"
18+
}
19+
20+
function tag_version() {
21+
GITHUB_TOKEN="${GITHUB_TOKEN}" hub release create -m "v${VERSION}" "v${VERSION}"
22+
}
23+
24+
25+
function publish_new_version() {
26+
set +x
27+
# Build and push gem
28+
gem build ./*.gemspec
29+
gem push ./*.gem
30+
31+
# Create gh tag
32+
tag_version
33+
34+
set -x
35+
}

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.11.4

codeclimate-services.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require "cc/services/version"
55

66
Gem::Specification.new do |spec|
77
spec.name = "codeclimate-services"
8-
spec.version = CC::Services::VERSION
8+
spec.version = CC::Services.version
99
spec.authors = ["Bryan Helmkamp"]
1010
spec.email = ["bryan@brynary.com"]
1111
spec.summary = "Service classes for Code Climate"

lib/cc/services/version.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module CC
22
module Services
3-
VERSION = "1.11.3".freeze
3+
def version
4+
path = File.expand_path("../../../../VERSION", __FILE__)
5+
@version ||= File.read(path).strip
6+
end
7+
module_function :version
48
end
59
end

0 commit comments

Comments
 (0)