From 26438f8f5b75273d69767f7e3799d4d5bb16da31 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Thu, 12 Oct 2023 11:29:01 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Update=20checksums=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/rubygems/guides/pull/325 --- bin/checksums | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/checksums b/bin/checksums index 77decc0..1e40c88 100755 --- a/bin/checksums +++ b/bin/checksums @@ -1,9 +1,14 @@ #!/usr/bin/env ruby # frozen_string_literal: true +# Script from https://github.com/rubygems/guides/pull/325 require "digest/sha2" -VERSION_REGEX = /\d+\.\d+\.\d+([-.].+)*/.freeze +# Final clause of Regex `(?=\.gem)` is a positive lookahead assertion +# See: https://learnbyexample.github.io/Ruby_Regexp/lookarounds.html#positive-lookarounds +# Used to pattern match against a gem package name, which always ends with .gem. +# The positive lookahead ensures it is present, and prevents it from being captured. +VERSION_REGEX = /((\d+\.\d+\.\d+)([-.][0-9A-Za-z-]+)*)(?=\.gem)/.freeze gem_path_parts = ARGV.first&.split("/") @@ -36,7 +41,7 @@ checksum256 = Digest::SHA256.new.hexdigest(File.read(gem_pkg)) checksum256_path = "checksums/#{gem_name}.sha256" File.write(checksum256_path, checksum256) -version = File.basename(checksum256_path[VERSION_REGEX], ".gem") +version = gem_name[VERSION_REGEX] git_cmd = <<~GIT_MSG git add checksums/* && \ @@ -48,7 +53,9 @@ puts <<~RESULTS [VERSION: #{version}] [CHECKSUM SHA256 PATH: #{checksum256_path}] [CHECKSUM SHA512 PATH: #{checksum512_path}] + ... Running ... + #{git_cmd} RESULTS