Skip to content

Commit

Permalink
🔨 Update checksums script
Browse files Browse the repository at this point in the history
  • Loading branch information
pboling committed Oct 12, 2023
1 parent 3cde569 commit 26438f8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bin/checksums
Original file line number Diff line number Diff line change
@@ -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("/")

Expand Down Expand Up @@ -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/* && \
Expand All @@ -48,7 +53,9 @@ puts <<~RESULTS
[VERSION: #{version}]
[CHECKSUM SHA256 PATH: #{checksum256_path}]
[CHECKSUM SHA512 PATH: #{checksum512_path}]
... Running ...
#{git_cmd}
RESULTS

Expand Down

0 comments on commit 26438f8

Please sign in to comment.