revision 1.6.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d15b43ba3833b4581b97b89a7c5ba40890373b5cc85f1186f5917e9ad5d5fb21
4
- data.tar.gz: badf688375adaab009a16f4e03a250cb77725fcc3d140d3b47a38d7e8436a575
3
+ metadata.gz: e319fb6dc51ae708782296c793f658547dd4a1e1f1df19e4fb2d3787213a22b8
4
+ data.tar.gz: 9645d927126073825302fe097c719c6294af2a9ee97f4a72058040039f2beb00
5
5
  SHA512:
6
- metadata.gz: 33dea1ba91f478dc674d9c5b3f23f875b9ca192f9a3efa2a27f2e0e33b39a119ffb367353dd17e7b3ecb4ce17df64747b0edef415ea66eb9a1fe8604fae73378
7
- data.tar.gz: 7c386e43dd4f3979462f0e0d4c1ca6ae29409f042d5239f5b1434ba7bb8ef4836d5ca70b0786bf86e0b83a4102191f60f4f23df883341c67a0fcd2b851f4d5d7
6
+ metadata.gz: 57bffb27f36a0a282c9555157402309069dceaabb403a2be7ae3bcacf4c17319b7a3646414087575e89bd1928876266282be9ca9aa89cf697e58d7d80b121dc8
7
+ data.tar.gz: '094cd008804acc63b1f9732df488f59b5bed2e703928073c7b331c089854f00277317404eb127871ff01a67d58547153c311a9c7c5bb7520c51b9a4f0e1c6bcc'
data/.envrc ADDED
@@ -0,0 +1,2 @@
1
+ use flake
2
+ layout ruby
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ README.html
15
15
  *.zip
16
16
  test-output
17
17
  *.md5
18
+ .direnv
data/README.org CHANGED
@@ -198,9 +198,9 @@ The lines beginning with '#' are explanatory comments
198
198
  - :src: pkg/revision-<VER>.gem
199
199
  :dest: revision-<VER>.gem
200
200
  # ':dest:' defaults to the string specified for ':src:' if not specified explicitly
201
- # md5sums are generated by default for each artefact -- the ':md5:' option allows this to be disabled per-artefact
201
+ # sha512 checksums are generated by default for each artefact -- the ':chk:' option allows this to be disabled per-artefact
202
202
  - :src: README.org
203
- :md5: false
203
+ :chk: false
204
204
  #+END_SRC
205
205
 
206
206
  **** TODO (or at least consider) add support for overridable defaults
data/flake.lock ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "nodes": {
3
+ "nixpkgs": {
4
+ "locked": {
5
+ "lastModified": 1699343069,
6
+ "narHash": "sha256-s7BBhyLA6MI6FuJgs4F/SgpntHBzz40/qV0xLPW6A1Q=",
7
+ "owner": "NixOS",
8
+ "repo": "nixpkgs",
9
+ "rev": "ec750fd01963ab6b20ee1f0cb488754e8036d89d",
10
+ "type": "github"
11
+ },
12
+ "original": {
13
+ "owner": "NixOS",
14
+ "ref": "nixpkgs-unstable",
15
+ "repo": "nixpkgs",
16
+ "type": "github"
17
+ }
18
+ },
19
+ "root": {
20
+ "inputs": {
21
+ "nixpkgs": "nixpkgs"
22
+ }
23
+ }
24
+ },
25
+ "root": "root",
26
+ "version": 7
27
+ }
data/flake.nix ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ description = "A Nix-flake-based Ruby development environment";
3
+
4
+ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5
+
6
+ outputs = { self, nixpkgs }:
7
+ let
8
+ supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
9
+ forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
10
+ pkgs = import nixpkgs { inherit system; };
11
+ });
12
+ in
13
+ {
14
+ devShells = forEachSupportedSystem ({ pkgs }: {
15
+ default = pkgs.mkShell {
16
+ packages = with pkgs; [ ruby_3_2 ];
17
+ };
18
+ });
19
+ };
20
+ }
@@ -1,34 +1,38 @@
1
1
  require 'digest'
2
2
 
3
- class Revision::MD5
3
+ class Revision::Checksum
4
4
 
5
5
  READ_CHUNK_KB = 1024
6
6
  FILENAME_EXTENSION = "md5"
7
7
 
8
+ MD5 = {name: "md5", generator: Digest::MD5}
9
+ SHA512 = {name: "sha512", generator: Digest::SHA512}
10
+
8
11
  attr_reader :root, :filename
9
12
 
10
- def self.from_file(filepath, filename: nil)
13
+ def self.from_file(filepath, filename: nil, type: SHA512)
11
14
  raise "File #{filepath} not found" unless File.exist?(filepath)
12
15
  filename ||= File.basename(filepath)
13
16
  root = File.dirname(filepath)
14
17
  stream = File.open(filepath, 'rb')
15
- new(stream, filename, root: root)
18
+ new(stream, filename, root: root, type: type)
16
19
  end
17
20
 
18
- def initialize(ioreader, filename, root: nil)
21
+ def initialize(ioreader, filename, root: nil, type: SHA512)
19
22
  root ||= Dir.getwd
20
23
  @reader = ioreader
21
24
  @root = root
22
25
  @filename = filename
26
+ @impl = type
23
27
  end
24
28
 
25
29
  def calc
26
- md5 = Digest::MD5.new
30
+ checksum = @impl[:generator].new
27
31
  bytes_per_chunk = READ_CHUNK_KB*1024
28
32
  while chunk = @reader.read(bytes_per_chunk)
29
- md5 << chunk
33
+ checksum << chunk
30
34
  end
31
- md5.hexdigest
35
+ checksum.hexdigest
32
36
  end
33
37
 
34
38
  def to_s
@@ -37,12 +41,12 @@ class Revision::MD5
37
41
  EOT
38
42
  end
39
43
 
40
- def md5filename
41
- "#{@filename}.#{FILENAME_EXTENSION}"
44
+ def chkfilename
45
+ "#{@filename}.#{@impl[:name]}"
42
46
  end
43
47
 
44
48
  def write(filepath: nil)
45
- filepath ||= File.join(@root, md5filename)
49
+ filepath ||= File.join(@root, chkfilename)
46
50
  filename = File.basename(filepath)
47
51
  File.open(filepath, "w") { |f| f.write "#{calc} #{filename}" }
48
52
  filepath
data/lib/revision/cli.rb CHANGED
@@ -4,7 +4,7 @@ require_relative 'releasable'
4
4
  require_relative 'info'
5
5
  require_relative 'errors'
6
6
  require_relative 'version'
7
- require_relative 'md5'
7
+ require_relative 'checksum'
8
8
 
9
9
  module Revision
10
10
  class CLI < Thor
@@ -111,13 +111,28 @@ module Revision
111
111
  def md5
112
112
  r = select_one
113
113
  files = options[:file].nil? ?
114
- r.artefacts.select { |a| a[:md5]==true }.map { |a| a[:src] } :
114
+ r.artefacts.select { |a| a[:chk]==true }.map { |a| a[:src] } :
115
115
  [options[:file]]
116
116
  raise "No files specified" unless files.length
117
- puts "Calculating md5sum for files #{files}"
117
+ puts "Calculating checksum for files #{files}"
118
118
  for f in files
119
- md5sum = Revision::MD5.from_file(f)
120
- puts "#{md5sum}"
119
+ checksum = Revision::Checksum.from_file(f, type: Revision::Checksum::MD5)
120
+ puts "#{checksum}"
121
+ end
122
+ end
123
+
124
+ desc 'chk', 'Compute sha512 checksums for current build artefacts'
125
+ method_option :file, :aliases => "-f", :type => :string, :default => nil ,:desc => "File to checksum (defaults to build artefacts defined in yaml)"
126
+ def chk
127
+ r = select_one
128
+ files = options[:file].nil? ?
129
+ r.artefacts.select { |a| a[:chk]==true }.map { |a| a[:src] } :
130
+ [options[:file]]
131
+ raise "No files specified" unless files.length
132
+ puts "Calculating checksum for files #{files}"
133
+ for f in files
134
+ checksum = Revision::Checksum.from_file(f, type: Revision::Checksum::SHA512)
135
+ puts "#{checksum}"
121
136
  end
122
137
  end
123
138
 
@@ -69,7 +69,7 @@ module Revision
69
69
  @build_def = config[:build] ? config[:build] : { environment: { variables: {}}, steps: config[:build_steps]}
70
70
  @artefacts = config[:artefacts] || []
71
71
  @artefacts.each { |a| a[:dest] ||= File.basename(a[:src]) } unless @artefacts.nil? || @artefacts.empty?
72
- # @artefacts.each { |a| a[:md5] = true if a[:md5].nil? } unless @artefacts.nil? || @artefacts.empty?
72
+ # @artefacts.each { |a| a[:chk] = true if a[:chk].nil? } unless @artefacts.nil? || @artefacts.empty?
73
73
  @config = config
74
74
  end
75
75
 
@@ -194,13 +194,15 @@ module Revision
194
194
 
195
195
  def normalise_artefact(a)
196
196
  src_norm = interp_rev(a[:src])
197
+ # the :chk key replaced a legacy :md5 key -- support old syntax
198
+ chk_unified = a[:chk].nil? ? a[:md5] : a[:chk]
197
199
  a_norm = {
198
200
  src: src_norm,
199
201
  dest: a[:dest].nil? ? File.basename(src_norm) : interp_rev(a[:dest]),
200
- md5: a[:md5].nil? ? true : a[:md5]
202
+ chk: chk_unified.nil? ? true : chk_unified
201
203
  }
202
204
  if Gem.win_platform? && !a_norm[:src].end_with?('.exe') && File.exist?(File.join(@root, a_norm[:src] + '.exe'))
203
- puts "... windows platform -- appending '.exe' ('#{a_norm[:src]}' -> '#{a_norm[src]}.exe')"
205
+ puts "... windows platform -- appending '.exe' ('#{a_norm[:src]}' -> '#{a_norm[:src]}.exe')"
204
206
  a_norm[:src] += '.exe'
205
207
  a_norm[:dest] += '.exe' unless a_norm[:dest].end_with?('.exe')
206
208
  end
@@ -222,27 +224,27 @@ module Revision
222
224
  zip_entries.each.with_index(1) do |a, idx|
223
225
  puts "... (#{idx}/#{zip_entries.length}) #{a[:dest]} :: <= #{a[:src]}"
224
226
  zipfile.add(a[:dest], a[:src])
225
- if a[:md5]
226
- md5name = "#{a[:dest]}.md5"
227
- puts "... (#{idx}/#{zip_entries.length}) #{a[:dest]} :: embedding md5sum (#{md5name})"
228
- zipfile.get_output_stream(md5name) { |os| os.write("#{MD5.from_file(a[:src])}")}
227
+ if a[:chk]
228
+ chkfile = Checksum.from_file(a[:src])
229
+ puts "... (#{idx}/#{zip_entries.length}) #{a[:dest]} :: embedding checksum (#{chkfile.chkfilename})"
230
+ zipfile.get_output_stream(chkfile.chkfilename) { |os| os.write("#{chkfile}")}
229
231
  else
230
- puts "... (#{idx}/#{zip_entries.length}) #{a[:dest]} :: no md5sum required"
232
+ puts "... (#{idx}/#{zip_entries.length}) #{a[:dest]} :: no checksum required"
231
233
  end
232
234
  end
233
235
  puts "... embedding revision history as #{changelog_name} "
234
236
  zipfile.get_output_stream(changelog_name) { |os| output_changelog(os)}
235
237
  end
236
- archive_md5 = MD5.from_file(archive_name)
237
- puts "... generating archive md5sum as #{archive_md5.md5filename} "
238
- archive_md5.write
238
+ archive_checksum = Checksum.from_file(archive_name)
239
+ puts "... generating archive checksum as #{archive_checksum.chkfilename} "
240
+ archive_checksum.write
239
241
 
240
242
  if @config.dig(:archive)
241
243
  archive_root = File.expand_path(@config[:archive])
242
244
  puts "... moving #{archive_name} to #{archive_root}"
243
245
  FileUtils.mkdir_p(archive_root)
244
246
  FileUtils.mv(archive_name, archive_root)
245
- FileUtils.mv(archive_md5.md5filename, archive_root)
247
+ FileUtils.mv(archive_checksum.chkfilename, archive_root)
246
248
  end
247
249
  end
248
250
 
@@ -283,7 +285,7 @@ module Revision
283
285
  end
284
286
  puts "... deploying '#{src}' -> '#{dest}'"
285
287
  FileUtils.cp_r(src,dest)
286
- puts "... writing md5sum for '#{dest}' to '#{MD5.from_file(dest).write}'" if a[:md5]
288
+ puts "... writing checksum for '#{dest}' to '#{Checksum.from_file(dest).write}'" if a[:chk]
287
289
  end
288
290
  File.open(File.join(destination,changelog_name),'w') { |f| output_changelog(f)}
289
291
 
@@ -1,12 +1,18 @@
1
1
  # Defines the revision ID for the revision gem
2
2
  module Revision
3
- VERSION = "1.6.0".freeze
3
+ VERSION = "2.0.0".freeze
4
4
  end
5
5
 
6
6
  # <BEGIN CHANGELOG>
7
7
  #
8
+ # Version 2.0.0 (10 Nov 2023)
9
+ # - new(checksum): Now using SHA512 rather than MD5 checksums
10
+ #
11
+ # Version 1.6.1 (31 Aug 2022)
12
+ # - Fixed logging error preventing windows exe creation
13
+ #
8
14
  # Version 1.6.0 (01 Dec 2021)
9
- # - New feature: Automated MD5sum generation during 'archive' and 'deploy' tasks
15
+ # - New feature: Automated checksum generation during 'archive' and 'deploy' tasks
10
16
  #
11
17
  # Version 1.5.3 (26 Oct 2021)
12
18
  # - Multiple deployment destinations bugfix -- only last destination was being used.
data/releasables.yaml CHANGED
@@ -8,13 +8,13 @@
8
8
  - mkdir -p test-output/2
9
9
  - bundle exec rake install
10
10
  #Define 3 build artefacts as test cases for 'deploy' and 'archive' tasks
11
- #Expect MD5 file to be generated by default for first entry (where not specified explicitly)
11
+ #Expect checksum file to be generated by default for first entry (where not specified explicitly)
12
12
  :artefacts:
13
13
  - :src: pkg/revision-<VER>.gem
14
14
  - :src: README.org
15
- :md5: false
15
+ :chk: false
16
16
  - :src: Rakefile
17
- :md5: true
17
+ :chk: true
18
18
  #Define two deployment destinations to verify multiple deployments work as intended
19
19
  :deploy:
20
20
  - :dest: ./test-output
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revision
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cormac Cannon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-01 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -187,6 +187,7 @@ executables:
187
187
  extensions: []
188
188
  extra_rdoc_files: []
189
189
  files:
190
+ - ".envrc"
190
191
  - ".gitignore"
191
192
  - ".rspec"
192
193
  - ".travis.yml"
@@ -197,11 +198,13 @@ files:
197
198
  - bin/console
198
199
  - bin/setup
199
200
  - exe/revision
201
+ - flake.lock
202
+ - flake.nix
200
203
  - lib/revision.rb
204
+ - lib/revision/checksum.rb
201
205
  - lib/revision/cli.rb
202
206
  - lib/revision/errors.rb
203
207
  - lib/revision/info.rb
204
- - lib/revision/md5.rb
205
208
  - lib/revision/releasable.rb
206
209
  - lib/revision/string_case.rb
207
210
  - lib/revision/version.rb
@@ -227,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
230
  - !ruby/object:Gem::Version
228
231
  version: '0'
229
232
  requirements: []
230
- rubygems_version: 3.2.13
233
+ rubygems_version: 3.4.20
231
234
  signing_key:
232
235
  specification_version: 4
233
236
  summary: Language-agnostic revision management tool