Skip to content

Commit 08e5442

Browse files
authored
Merge pull request #306 from rails/flavorjones-check-sha256sums
dev: validate sha256 checksums from upstream when packaging
2 parents d52b49e + 66d8114 commit 08e5442

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

rakelib/package.rake

+30-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ end
7474

7575
TAILWINDCSS_RAILS_GEMSPEC = Bundler.load_gemspec("tailwindcss-rails.gemspec")
7676

77+
# prepend the download task before the Gem::PackageTask tasks
78+
task :package => :download
79+
7780
gem_path = Gem::PackageTask.new(TAILWINDCSS_RAILS_GEMSPEC).define
7881
desc "Build the ruby gem"
7982
task "gem:ruby" => [gem_path]
@@ -110,7 +113,33 @@ Tailwindcss::Upstream::NATIVE_PLATFORMS.each do |platform, filename|
110113
end
111114
end
112115

116+
desc "Validate checksums for tailwindcss binaries"
117+
task "check" => exepaths do
118+
sha_filename = "sha256sums.txt"
119+
sha_url = tailwindcss_download_url(sha_filename)
120+
gemspec = TAILWINDCSS_RAILS_GEMSPEC
121+
122+
checksums = URI.open(sha_url).each_line.map do |line|
123+
checksum, file = line.split
124+
[File.basename(file), checksum]
125+
end.to_h
126+
127+
Tailwindcss::Upstream::NATIVE_PLATFORMS.each do |platform, filename|
128+
exedir = File.join(gemspec.bindir, platform) # "exe/x86_64-linux"
129+
exepath = File.join(exedir, "tailwindcss") # "exe/x86_64-linux/tailwindcss"
130+
131+
local_sha256 = Digest::SHA256.file(exepath).hexdigest
132+
remote_sha256 = checksums.fetch(filename)
133+
134+
if local_sha256 == remote_sha256
135+
puts "Checksum OK for #{exepath} (#{local_sha256})"
136+
else
137+
abort "Checksum mismatch for #{exepath} (#{local_sha256} != #{remote_sha256})"
138+
end
139+
end
140+
end
141+
113142
desc "Download all tailwindcss binaries"
114-
task "download" => exepaths
143+
task "download" => :check
115144

116145
CLOBBER.add(exepaths.map { |p| File.dirname(p) })

0 commit comments

Comments
 (0)