Skip to content

Commit

Permalink
feat: run release without having any particular ruby installed locally
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 28, 2020
1 parent aa03d58 commit c52a3b1
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 16 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
test.sh
*.md
.gitkeep
script
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pact_broker/pact_broker.sqlite
pact_broker.sqlite
pact_broker/log
pact_broker/tmp
pact_broker/tmp
tmp
8 changes: 7 additions & 1 deletion Dockerfile-package-base
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ ENV HOME=/app
WORKDIR $HOME

RUN gem install bundler -v 2.0.2

COPY script/docker/fake-git /usr/local/sbin/git
COPY Rakefile $HOME/
COPY Gemfile Gemfile.lock $HOME/
RUN bundle install --no-cache
# Only loaded for running the specs
COPY pact_broker $HOME/pact_broker
COPY spec $HOME/spec
RUN bundle install
File renamed without changes.
2 changes: 1 addition & 1 deletion script/publish.sh → script/dev/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ else
BASE_URL="$1"
fi

BODY=$(ruby -e "require 'json'; j = JSON.parse(File.read('script/foo-bar.json')); j['interactions'][0]['providerState'] = 'it is ' + Time.now.to_s; puts j.to_json")
BODY=$(ruby -e "require 'json'; j = JSON.parse(File.read('script/dev/foo-bar.json')); j['interactions'][0]['providerState'] = 'it is ' + Time.now.to_s; puts j.to_json")
echo ${BODY} >> tmp.json
curl -v -XPUT -u foo:bar \-H "Content-Type: application/json" \
-d@tmp.json \
Expand Down
8 changes: 2 additions & 6 deletions script/docker-functions
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ function docker_build_bundle_base() {
docker build . -f Dockerfile-bundle-base -t dius_pact_broker_bundle_base
}

function get_pact_broker_version() {
docker run --rm -v ${PWD}/pact_broker/Gemfile.lock:/tmp/Gemfile.lock dius_pact_broker_bundle_base ruby -e "puts File.read('/tmp/Gemfile.lock').match(/pact_broker \((.*)\)/)[1]"
}

function bundle_update_on_docker() {
rm -rf tmp/Gemfile.lock
docker run --rm -v ${PWD}/tmp:/tmp/shared dius_pact_broker_bundle_base:latest sh -c "bundle update && cp Gemfile.lock /tmp/shared"
Expand All @@ -18,6 +14,6 @@ function docker_build_package_base() {
docker build . -f Dockerfile-package-base -t dius_pact_broker_package_base
}

function generate_changelog() {
docker run --rm -v ${PWD}:/app dius_pact_broker_package_base bundle exec rake generate_changelog
function run_on_package_base() {
docker run --rm -it dius_pact_broker_package_base sh -c "$@"
}
9 changes: 9 additions & 0 deletions script/docker/fake-git
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh

# This file is used by the conventional changelog gem instead of the real git executable
# inside the docker container, as using git in a docker container turns out to be ridiculously hard.
# It echos a pre-created list of git commits, created in
# script/prepare-git-log-extract-for-conventional-changelog.sh
# Don't judge me. I've tried a LOT of things.

cat /tmp/git-log
5 changes: 5 additions & 0 deletions script/functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

gem_version_from_gemfile_lock() {
grep "pact_broker (" pact_broker/Gemfile.lock | awk -F '[()]' '{print $2}'
}
4 changes: 2 additions & 2 deletions script/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

export TAG=$(script/next-docker-tag.sh)
bundle exec rake generate_changelog
export TAG=$(script/release/next-docker-tag.sh)
script/release/generate-changelog.sh
git add CHANGELOG.md && git commit -m "chore(changelog): update for ${TAG}"
echo "Tagging version ${TAG}"
git tag -a "${TAG}" -m "Releasing version ${TAG}" && git push origin "${TAG}"
18 changes: 18 additions & 0 deletions script/release/generate-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh

set -e

: "${TAG:?Please set the TAG environment variable}"

source script/docker-functions

docker_build_package_base

$(dirname "$0")/prepare-git-log-extract-for-conventional-changelog.sh

docker run --rm -it \
-e TAG=${TAG} \
-v ${PWD}/tmp/git-log:/tmp/git-log \
-v ${PWD}/CHANGELOG.md:/app/CHANGELOG.md \
dius_pact_broker_package_base \
sh -c "bundle exec rake generate_changelog"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set -e
source script/functions
gem_version=$(gem_version_from_gemfile_lock)
DOCKER_IMAGE="dius/pact-broker"
# TODO pass this in
gem_version=$(docker run --rm -v ${PWD}/pact_broker/Gemfile.lock:/tmp/Gemfile.lock ruby:2.6.4-alpine ruby -e "puts File.read('/tmp/Gemfile.lock').match(/pact_broker \((.*)\)/)[1]")
existing_tags=$(wget -q https://registry.hub.docker.com/v1/repositories/${DOCKER_IMAGE}/tags -O - | jq -r .[].name)
existing_release_numbers_for_current_gem_version=$(echo "$existing_tags" | grep "${gem_version}-" | sed 's/'${gem_version}'-//g')
last_release_number=$(printf "0\n${existing_release_numbers_for_current_gem_version}" | sort -g | tail -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env sh
# Extracts the relevant commits from the git log for this release

set -e

rm -rf tmp; mkdir -p tmp

export DELIMITER="/////"

last_tag=$(grep "a name=" CHANGELOG.md | head -n 1 | cut -d \" -f2)

# Use the same command that conventional-changelog uses to extract the relevant
# lines from the git log
# See https://github.com/dcrec1/conventional-changelog-ruby/blob/628565d00caed1f93461a3cd189fb40452066e71/lib/conventional_changelog/git.rb#L17-L20

git log --pretty=format:"%h${DELIMITER}%ad${DELIMITER}%s%x09" \
--date=short \
--grep="^(feat|fix)(\\(.*\\))?:" \
-E \
${last_tag}..HEAD > tmp/git-log

echo "Extracted the following commits since ${last_tag}:"
cat tmp/git-log
echo ""
6 changes: 6 additions & 0 deletions script/spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

source script/docker-functions

docker_build_package_base
run_on_package_base "bundle exec rake spec"
2 changes: 1 addition & 1 deletion script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fi
[ -z "${PACT_BROKER_WEBHOOK_SCHEME_WHITELIST}" ] && PACT_BROKER_WEBHOOK_SCHEME_WHITELIST="http https"
[ -z "${PACT_BROKER_WEBHOOK_HOST_WHITELIST}" ] && PACT_BROKER_WEBHOOK_HOST_WHITELIST="/.*\\.foo\\.com$/ bar.com 10.2.3.41/24"

bundle exec rspec spec
script/spec.sh

echo "Will build the pact broker"
docker build -t=dius/pact_broker .
Expand Down
4 changes: 3 additions & 1 deletion script/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
set -e

source script/docker-functions
source script/functions

docker_build_bundle_base
bundle_update_on_docker

Expand All @@ -12,5 +14,5 @@ unset PACT_BROKER_DATABASE_PASSWORD
PACT_BROKER_DATABASE_NAME=pact_broker.sqlite PACT_BROKER_DATABASE_ADAPTER=sqlite script/test.sh
PACT_BROKER_DATABASE_NAME=pact_broker.sqlite PACT_BROKER_DATABASE_ADAPTER=sqlite script/test_basic_auth.sh
git add pact_broker
git commit -m "feat(gems): update pact_broker gem to version $(cd pact_broker && bundle exec ruby -e "require 'pact_broker/version'; puts PactBroker::VERSION")"
git commit -m "feat(gems): update pact_broker gem to version $(gem_version_from_gemfile_lock)"
git push

0 comments on commit c52a3b1

Please sign in to comment.