From 8a66ba1f286d90def1bdc729ed30234b2b2a833c Mon Sep 17 00:00:00 2001 From: Josh Pencheon Date: Tue, 12 Jan 2021 12:59:26 +0000 Subject: [PATCH 1/2] # refactor gem build hooks - continue checking code_safety.yml - avoid re-building/releasing an existing tag (to make Continous Deployment easier) --- lib/ndr_dev_support/tasks.rb | 1 + lib/tasks/audit_code.rake | 3 --- lib/tasks/release.rake | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 lib/tasks/release.rake diff --git a/lib/ndr_dev_support/tasks.rb b/lib/ndr_dev_support/tasks.rb index abb2466..36704ec 100644 --- a/lib/ndr_dev_support/tasks.rb +++ b/lib/ndr_dev_support/tasks.rb @@ -14,4 +14,5 @@ load 'tasks/ci/simplecov.rake' load 'tasks/ci/slack.rake' load 'tasks/ci/stats.rake' +load 'tasks/release.rake' load 'tasks/rubocop.rake' diff --git a/lib/tasks/audit_code.rake b/lib/tasks/audit_code.rake index 2d6b25d..1722257 100644 --- a/lib/tasks/audit_code.rake +++ b/lib/tasks/audit_code.rake @@ -510,6 +510,3 @@ Usage: end end end - -# Prevent building of un-reviewed gems: -task build: :'audit:ensure_safe' diff --git a/lib/tasks/release.rake b/lib/tasks/release.rake new file mode 100644 index 0000000..1ebc10b --- /dev/null +++ b/lib/tasks/release.rake @@ -0,0 +1,36 @@ +namespace :ndr_dev_support do + namespace :gem do + desc 'Quits if the current version has already been tagged.' + task :exit_if_already_released do + gemspec_path = Dir['{,*}.gemspec'].first + raise 'No gemspec found!' unless gemspec_path + + gemspec = Bundler.load_gemspec(gemspec_path) + release_tag = "v#{gemspec.version}" + + existing_tags = `git tag` + raise 'Error getting git tags!' if $?.exitstatus > 0 + + if existing_tags.split("\n").include?(release_tag) + abort "The tag for the release (#{release_tag}) already exists; stopping build process." + end + end + end +end + +# `audit:ensure_safe` is our legacy code review process, a precursor to a PR-based +# workflow with branch-protection. We continue to use this for the time being. +# This prevents bundler from building gems if there are outstanding code reviews to be done. +# +# When doing a build/release, don't bother if the version has already been tagged. +# This allows a CD pipeline to conditionally build/release when run against every commit, +# without needing to rely on existing tags (which are harder to protect). +desc <<~DESC + NdrDevSupport prevents building/releasing if either: + * legacy code review fails + * the release has already been tagged (for CD) +DESC +task build: [ + 'audit:ensure_safe', + 'ndr_dev_support:gem:exit_if_already_released' +] From fdb808955a1cd8b27c3c55d8772242952d2b7a73 Mon Sep 17 00:00:00 2001 From: Josh Pencheon Date: Tue, 12 Jan 2021 14:47:40 +0000 Subject: [PATCH 2/2] # building gems: exit with zero status if the git tag already exists --- lib/tasks/release.rake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tasks/release.rake b/lib/tasks/release.rake index 1ebc10b..ed98ffa 100644 --- a/lib/tasks/release.rake +++ b/lib/tasks/release.rake @@ -12,7 +12,8 @@ namespace :ndr_dev_support do raise 'Error getting git tags!' if $?.exitstatus > 0 if existing_tags.split("\n").include?(release_tag) - abort "The tag for the release (#{release_tag}) already exists; stopping build process." + puts "The tag for the release (#{release_tag}) already exists; nothing to do!" + exit 0 end end end