|
74 | 74 |
|
75 | 75 | TAILWINDCSS_RAILS_GEMSPEC = Bundler.load_gemspec("tailwindcss-rails.gemspec")
|
76 | 76 |
|
| 77 | +# prepend the download task before the Gem::PackageTask tasks |
| 78 | +task :package => :download |
| 79 | + |
77 | 80 | gem_path = Gem::PackageTask.new(TAILWINDCSS_RAILS_GEMSPEC).define
|
78 | 81 | desc "Build the ruby gem"
|
79 | 82 | task "gem:ruby" => [gem_path]
|
@@ -110,7 +113,33 @@ Tailwindcss::Upstream::NATIVE_PLATFORMS.each do |platform, filename|
|
110 | 113 | end
|
111 | 114 | end
|
112 | 115 |
|
| 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 | + |
113 | 142 | desc "Download all tailwindcss binaries"
|
114 |
| -task "download" => exepaths |
| 143 | +task "download" => :check |
115 | 144 |
|
116 | 145 | CLOBBER.add(exepaths.map { |p| File.dirname(p) })
|
0 commit comments