bake-modernize 0.13.3 → 0.14.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: 43ccc35944a73c49b82c67b6dfe17a0010f7653da8f3cf1c861915a4be1a5017
4
- data.tar.gz: 885e420146d6319d69949d12da0ef15d6af06001e42b3cbfa8dcd5bdb038ee1e
3
+ metadata.gz: 23c20cae9dae81e435771d980f8c7944a78e818809cca3161ac428d94fd690f6
4
+ data.tar.gz: 1bb494fe765f62e0da2ad5b4a690e519499acc01db7e19ec66949d574cb83a7b
5
5
  SHA512:
6
- metadata.gz: 5835b74331b32293a53b771ebc0c92caa9e823b8fe90156aebaca98d10c876f060d3f60f82904256a0d11e2662c4cdfa791dffde13b845cced6e4ca3adbfc721
7
- data.tar.gz: 432d156c7e168cf87a0038e7f2cb4e0d28a668414438d5a4ab1a14109294048a5e9e44ee31e90a7b9f5c8746bdfd7986ff6ab6d2e4f9ed02e1545cb667d0ce14
6
+ metadata.gz: f287b0e61d32d6d3f9b60e6b93a796a3de8529581617691b6bfc784a5a6f30e9c7405b994736d5c0cbed774a89371431fd2b2202ec044b92705a06e981ed390c
7
+ data.tar.gz: e36f6ef0a58d24e8196726d732fdb2b4d09643ea299636ff66279b326e2eccd07c47ab1387c903edb03442dc540b93118b8ca811123040a6d030014e4490ee4e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Released under the MIT License.
4
+ # Copyright, 2022, by Samuel Williams.
5
+
3
6
  def frozen_string_literal
4
7
  update(root: Dir.pwd)
5
8
  end
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022, by Samuel Williams.
5
5
 
6
- require 'console'
6
+ require 'bake/modernize'
7
7
 
8
8
  LICENSE = <<~LICENSE
9
9
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -31,16 +31,15 @@ def license
31
31
  end
32
32
 
33
33
  def update(root:)
34
- authors, paths = self.authors(root)
34
+ authorship = Bake::Modernize::License::Authorship.new
35
+ authorship.extract(root)
35
36
 
36
37
  buffer = StringIO.new
37
38
  buffer.puts "# MIT License"
38
39
  buffer.puts
39
40
 
40
- authors.map do |author, dates|
41
- years = dates.map(&:year).uniq
42
-
43
- buffer.puts "Copyright, #{years.join('-')}, by #{author}. "
41
+ authorship.copyrights.each do |copyright|
42
+ buffer.puts "#{copyright.statement} "
44
43
  end
45
44
 
46
45
  buffer.puts
@@ -50,19 +49,21 @@ def update(root:)
50
49
  file.write(buffer.string)
51
50
  end
52
51
 
53
- paths.each do |path, authors|
52
+ authorship.paths.each do |path, modifications|
54
53
  next unless File.exist?(path)
55
54
 
56
55
  case path
57
56
  when /\.rb$/
58
- self.update_source_file_authors(path, authors)
57
+ self.update_source_file_authors(authorship, path, modifications)
59
58
  end
60
59
  end
61
60
  end
62
61
 
63
62
  private
64
63
 
65
- def update_source_file_authors(path, authors)
64
+ def update_source_file_authors(authorship, path, modifications)
65
+ copyrights = authorship.copyrights_for_modifications(modifications)
66
+
66
67
  input = File.readlines(path)
67
68
  output = []
68
69
 
@@ -84,16 +85,14 @@ def update_source_file_authors(path, authors)
84
85
  end
85
86
 
86
87
  # Remove any empty lines:
87
- while input.first.chomp.empty?
88
+ while input.first&.chomp&.empty?
88
89
  input.shift
89
90
  end
90
91
 
91
92
  output << "# Released under the MIT License.\n"
92
93
 
93
- authors.each do |author, dates|
94
- years = dates.map(&:year).uniq
95
-
96
- output << "# Copyright, #{years.join('-')}, by #{author}.\n"
94
+ copyrights.each do |copyright|
95
+ output << "# #{copyright.statement}\n"
97
96
  end
98
97
 
99
98
  output << "\n"
@@ -104,67 +103,3 @@ def update_source_file_authors(path, authors)
104
103
  file.puts(output)
105
104
  end
106
105
  end
107
-
108
- def authors(root)
109
- paths = {}
110
- authors = {}
111
-
112
- total = `git rev-list --count HEAD`.to_i
113
-
114
- input, output = IO.pipe
115
- pid = Process.spawn("git", "log", "--name-only", "--pretty=format:%ad\t%an", out: output, chdir: root)
116
-
117
- output.close
118
-
119
- progress = Console.logger.progress(self, total)
120
-
121
- while header = (input.readline.chomp rescue nil)
122
- break if header.empty?
123
- progress.increment
124
-
125
- date, author = header.split("\t", 2)
126
- date = Date.parse(date)
127
-
128
- while path = (input.readline.chomp rescue nil)
129
- break if path.empty?
130
-
131
- paths[path] ||= {}
132
- paths[path][author] ||= []
133
- paths[path][author] << date
134
-
135
- authors[author] ||= []
136
- authors[author] << date
137
- end
138
- end
139
-
140
- input.close
141
- Process.wait2(pid)
142
-
143
- paths.each do |path, authors|
144
- authors.transform_values! do |dates|
145
- dates.minmax
146
- end
147
- end
148
-
149
- paths.transform_values! do |authors|
150
- authors.transform_values! do |dates|
151
- dates.minmax
152
- end
153
-
154
- authors.sort_by do |author, dates|
155
- dates
156
- end
157
- end
158
-
159
- authors.transform_values! do |dates|
160
- dates.minmax
161
- end
162
-
163
- authors = authors.to_a
164
-
165
- authors.sort_by! do |author, dates|
166
- dates
167
- end
168
-
169
- return authors, paths
170
- end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2022, by Samuel Williams.
5
+
6
+ require 'rugged'
7
+
8
+ module Bake
9
+ module Modernize
10
+ module License
11
+ class Mailmap
12
+ def self.for(root)
13
+ full_path = File.join(root, '.mailmap')
14
+
15
+ if File.exist?(full_path)
16
+ mailmap = self.new
17
+ mailmap.extract(full_path)
18
+ return mailmap
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ @names = {}
24
+ end
25
+
26
+ attr :names
27
+
28
+ def extract(path)
29
+ File.open(path, 'r') do |file|
30
+ file.each_line do |line|
31
+ # Skip comments
32
+ next if line =~ /^#/
33
+ # Skip empty lines
34
+ next if line =~ /^\s*$/
35
+ # Parse line
36
+ # Format: Full Name <email@address>
37
+ line.match(/^(.*) <(.*)>$/) do |match|
38
+ @names[match[2]] = match[1]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ class Authorship
46
+ Modification = Struct.new(:author, :time, :path) do
47
+ def full_name
48
+ author[:name]
49
+ end
50
+ end
51
+
52
+ Copyright = Struct.new(:dates, :author) do
53
+ def <=> other
54
+ self.to_a <=> other.to_a
55
+ end
56
+
57
+ def statement
58
+ years = self.dates.map(&:year).uniq
59
+ return "Copyright, #{years.join('-')}, by #{author}."
60
+ end
61
+ end
62
+
63
+ def initialize
64
+ @paths = {}
65
+ end
66
+
67
+ attr :paths
68
+
69
+ def extract(root = Dir.pwd)
70
+ mailmap = Mailmap.for(root)
71
+
72
+ walk(Rugged::Repository.discover(root), mailmap: mailmap)
73
+
74
+ return self
75
+ end
76
+
77
+ def copyrights
78
+ copyrights_for_modifications(@paths.values.flatten)
79
+ end
80
+
81
+ def copyrights_for_path(path)
82
+ copyrights_for_modifications(@paths[path])
83
+ end
84
+
85
+ def copyrights_for_modifications(modifications)
86
+ authors = modifications.group_by{|modification| modification.full_name}
87
+
88
+ authors.map do |name, modifications|
89
+ Copyright.new(modifications.map(&:time).minmax, name)
90
+ end.sort
91
+ end
92
+
93
+ private
94
+
95
+ DEFAULT_SORT = Rugged::SORT_DATE | Rugged::SORT_TOPO | Rugged::SORT_REVERSE
96
+
97
+ def walk(repository, mailmap: nil, show: "HEAD")
98
+ Rugged::Walker.walk(repository, show: show, sort: DEFAULT_SORT) do |commit|
99
+ diff = commit.diff
100
+ diff.find_similar!
101
+
102
+ diff.each_delta do |delta|
103
+ old_path = delta.old_file[:path]
104
+ new_path = delta.new_file[:path]
105
+
106
+ @paths[new_path] ||= []
107
+
108
+ if old_path != new_path
109
+ # The file was moved, move copyright information too:
110
+ @paths[new_path].concat(@paths[old_path])
111
+ end
112
+
113
+ author = commit.author
114
+
115
+ if mailmap
116
+ if name = mailmap.names[author[:email]]
117
+ author[:name] = name
118
+ end
119
+ end
120
+
121
+ @paths[new_path] << Modification.new(author, commit.time, new_path)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Bake
7
7
  module Modernize
8
- VERSION = "0.13.3"
8
+ VERSION = "0.14.0"
9
9
  end
10
10
  end
@@ -3,7 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2020-2022, by Samuel Williams.
5
5
 
6
- require "bake/modernize/version"
6
+ require_relative 'modernize/license'
7
+ require_relative 'modernize/version'
7
8
  require 'build/files/glob'
8
9
  require 'fileutils'
9
10
 
@@ -1,22 +1,30 @@
1
1
  name: Documentation
2
2
 
3
- permissions:
4
- contents: write
5
-
6
3
  on:
7
4
  push:
8
5
  branches:
9
6
  - main
10
7
 
8
+ # Allows you to run this workflow manually from the Actions tab:
9
+ workflow_dispatch:
10
+
11
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages:
11
12
  permissions:
12
- contents: write
13
+ contents: read
14
+ pages: write
15
+ id-token: write
16
+
17
+ # Allow one concurrent deployment:
18
+ concurrency:
19
+ group: "pages"
20
+ cancel-in-progress: true
13
21
 
14
22
  env:
15
23
  CONSOLE_OUTPUT: XTerm
16
24
  BUNDLE_WITH: maintenance
17
25
 
18
26
  jobs:
19
- deploy:
27
+ generate:
20
28
  runs-on: ubuntu-latest
21
29
 
22
30
  steps:
@@ -30,12 +38,24 @@ jobs:
30
38
  - name: Installing packages
31
39
  run: sudo apt-get install wget
32
40
 
33
- - name: Prepare GitHub Pages
34
- run: bundle exec bake github:pages:prepare --directory docs
35
-
36
41
  - name: Generate documentation
37
42
  timeout-minutes: 5
38
43
  run: bundle exec bake utopia:project:static --force no
39
44
 
40
- - name: Deploy GitHub Pages
41
- run: bundle exec bake github:pages:commit --directory docs
45
+ - name: Upload documentation artifact
46
+ uses: actions/upload-pages-artifact@v1
47
+ with:
48
+ path: docs
49
+
50
+ deploy:
51
+ runs-on: ubuntu-latest
52
+
53
+ environment:
54
+ name: github-pages
55
+ url: ${{steps.deployment.outputs.page_url}}
56
+
57
+ needs: generate
58
+ steps:
59
+ - name: Deploy to GitHub Pages
60
+ id: deployment
61
+ uses: actions/deploy-pages@v1
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bake-modernize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -38,7 +38,7 @@ cert_chain:
38
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
40
  -----END CERTIFICATE-----
41
- date: 2022-08-25 00:00:00.000000000 Z
41
+ date: 2022-09-02 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: async-http
@@ -141,6 +141,7 @@ files:
141
141
  - bake/modernize/readme.rb
142
142
  - bake/modernize/signing.rb
143
143
  - lib/bake/modernize.rb
144
+ - lib/bake/modernize/license.rb
144
145
  - lib/bake/modernize/version.rb
145
146
  - license.md
146
147
  - readme.md
metadata.gz.sig CHANGED
Binary file